-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#693): update druxt-menu for @nuxt/kit
- Loading branch information
Showing
9 changed files
with
140 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { addPluginTemplate, defineNuxtModule, installModule } from '@nuxt/kit' | ||
import { join, resolve } from 'path' | ||
// import DruxtMenuStorybook from './storybook' | ||
|
||
/** | ||
* The Nuxt.js module function. | ||
* | ||
* - Adds Nuxt plugin. | ||
* - Adds Vuex store. | ||
* - Adds Nuxt Storybook integration. | ||
* | ||
* The module function should not be used directly, but rather installed via your Nuxt configuration file. | ||
* | ||
* Options are set on the root level `druxt` Nuxt config object. | ||
* | ||
* @example @lang js | ||
* // `nuxt.config.js` | ||
* module.exports = { | ||
* modules: [ | ||
* 'druxt-menu' | ||
* ], | ||
* druxt: { | ||
* baseUrl: 'https://demo-api.druxtjs.org' | ||
* } | ||
* } | ||
* | ||
* @param {object} moduleOptions - Module options object. | ||
*/ | ||
const DruxtMenuNuxtModule = defineNuxtModule({ | ||
meta: { | ||
name: 'druxt-menu', | ||
}, | ||
defaults: { | ||
baseUrl: '', | ||
endpoint: '/jsonapi' | ||
}, | ||
|
||
async setup(moduleOptions, nuxt) { | ||
// Set default options. | ||
const options = { | ||
baseUrl: moduleOptions.baseUrl, | ||
...nuxt.options?.druxt || {}, | ||
menu: { | ||
jsonApiMenuItems: true, | ||
...nuxt.options?.druxt?.menu, | ||
...moduleOptions, | ||
} | ||
} | ||
|
||
// Add dependant modules. | ||
await installModule('druxt/nuxt', options) | ||
|
||
// Register components directories. | ||
nuxt.hook('components:dirs', dirs => { | ||
dirs.push({ path: join(__dirname, '../dist/components') }) | ||
dirs.push({ path: join(__dirname, '../dist/components/blocks') }) | ||
}) | ||
|
||
// Add plugin. | ||
addPluginTemplate({ | ||
src: resolve(__dirname, '../templates/plugin.js'), | ||
fileName: 'druxt-menu.js', | ||
options | ||
}) | ||
|
||
// Add Vuex plugin. | ||
addPluginTemplate({ | ||
src: resolve(__dirname, '../templates/store.js'), | ||
fileName: 'store/druxt-menu.js', | ||
options | ||
}) | ||
|
||
// Nuxt Storybook. | ||
// @TODO - @nuxt/kit and @nuxt/storybook aren't compatible. | ||
// this.nuxt.hook('storybook:config', async ({ stories }) => { | ||
// await DruxtMenuStorybook.call(this, { stories }) | ||
// }) | ||
} | ||
}) | ||
|
||
export default DruxtMenuNuxtModule |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import DruxtMenuNuxtModule from '../../src/nuxt' | ||
|
||
jest.mock('../../src/nuxt/storybook') | ||
|
||
jest.mock('@nuxt/kit', () => ({ | ||
addPluginTemplate: jest.fn(), | ||
defineNuxtModule: (module) => module, | ||
installModule: jest.fn(), | ||
})) | ||
|
||
import { addPluginTemplate, installModule } from '@nuxt/kit' | ||
|
||
const nuxtMock = { | ||
hook: jest.fn((hook, fn) => { | ||
const arg = { | ||
'components:dirs': [], | ||
'storybook:config': { stories: [] } | ||
} | ||
return fn(arg[hook]) | ||
}), | ||
} | ||
|
||
test('Nuxt module', async () => { | ||
// Use module with defaults. | ||
await DruxtMenuNuxtModule.setup({}, nuxtMock) | ||
expect(addPluginTemplate).toHaveBeenCalled() | ||
|
||
// Expect JSON:API Menu Items tp be enabled. | ||
expect(installModule).toHaveBeenLastCalledWith('druxt/nuxt', { | ||
baseUrl: undefined, | ||
menu: { | ||
jsonApiMenuItems: true | ||
} | ||
}) | ||
|
||
// Use overridden options; Drupal content menu items. | ||
await DruxtMenuNuxtModule.setup({}, { ...nuxtMock, options: { druxt: { menu: { jsonApiMenuItems: false }}} }) | ||
expect(installModule).toHaveBeenLastCalledWith('druxt/nuxt', { | ||
baseUrl: undefined, | ||
menu: { | ||
jsonApiMenuItems: false | ||
} | ||
}) | ||
}) |
2 changes: 1 addition & 1 deletion
2
packages/menu/test/nuxtStorybook.test.js → packages/menu/test/nuxt/storybook.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.