-
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-site for @nuxt/kit
- Loading branch information
Showing
10 changed files
with
141 additions
and
135 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,90 @@ | ||
import { addLayout, defineNuxtModule, installModule } from '@nuxt/kit' | ||
import { existsSync } from 'fs' | ||
import { resolve } from 'path' | ||
// import DruxtSiteStorybook from '../nuxtStorybook' | ||
|
||
/** | ||
* Nuxt module function to install Druxt Site. | ||
* | ||
* - Adds the DruxtSite component. | ||
* - Adds the core modules for DruxtJS Site. | ||
* - Adds default configuration for @nuxtjs/proxy. | ||
* - Enables Vuex store. | ||
* | ||
* @param {ModuleOptions} moduleOptions - The Nuxt.js module options. | ||
*/ | ||
const DruxtSiteNuxtModule = defineNuxtModule({ | ||
meta: { | ||
name: 'druxt-site', | ||
}, | ||
defaults: { | ||
baseUrl: '', | ||
endpoint: '/jsonapi' | ||
}, | ||
|
||
async setup(moduleOptions, nuxt) { | ||
// Prevent issue "FATAL: Cannot determine nuxt version! Is current | ||
// instance passed?". | ||
nuxt._version = nuxt._version || '2.' | ||
// This is required to prevent "FATAL: nuxt.options._layers is not iterable" | ||
// error when using `installModule()`. | ||
nuxt.options._layers = nuxt.options._layers || [] | ||
|
||
// Set default options. | ||
const options = { | ||
baseUrl: moduleOptions.baseUrl, | ||
...nuxt.options?.druxt, | ||
proxy: { | ||
api: false, | ||
files: true, | ||
...nuxt.options?.druxt?.proxy, | ||
}, | ||
site: { | ||
layout: true, | ||
...nuxt.options?.druxt?.site, | ||
...moduleOptions, | ||
}, | ||
} | ||
nuxt.options.druxt = options | ||
|
||
// Register components directories. | ||
nuxt.hook('components:dirs', dirs => { | ||
dirs.push({ path: resolve(__dirname, '../dist/components') }) | ||
}) | ||
|
||
// Add Druxt modules. | ||
const druxtModules = [ | ||
'druxt/nuxt', | ||
'druxt-blocks/nuxt', | ||
'druxt-breadcrumb/nuxt', | ||
'druxt-entity/nuxt', | ||
'druxt-menu/nuxt', | ||
'druxt-router/nuxt', | ||
'druxt-schema/nuxt', | ||
'druxt-views/nuxt' | ||
] | ||
for (const module of druxtModules) { | ||
await installModule(module, {}, nuxt) | ||
} | ||
|
||
// Add default layout. | ||
if (!(await existsSync(resolve(nuxt.options.srcDir, nuxt.options.dir.layouts))) && options.site.layout) { | ||
addLayout(resolve(__dirname, '../dist/layouts/default.vue'), 'default') | ||
} | ||
|
||
// Nuxt Storybook. | ||
// @TODO - @nuxt/kit and @nuxt/storybook aren't compatible. | ||
// this.nuxt.hook('storybook:config', async ({ stories }) => { | ||
// await DruxtSiteStorybook.call(this, { options, stories }) | ||
// }) | ||
} | ||
}) | ||
|
||
export default DruxtSiteNuxtModule | ||
|
||
/** | ||
* Module options object. | ||
* | ||
* @typedef {object} ModuleOptions | ||
* @see {@link ./typedefs/moduleOptions|ModuleOptions} | ||
*/ |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,39 @@ | ||
import DruxtSiteNuxtModule from '../../src/nuxt' | ||
|
||
jest.mock('../../src/nuxt/storybook') | ||
|
||
jest.mock('@nuxt/kit', () => ({ | ||
addLayout: jest.fn(), | ||
defineNuxtModule: (module) => module, | ||
installModule: jest.fn(), | ||
})) | ||
|
||
import { installModule } from '@nuxt/kit' | ||
|
||
const nuxtMock = { | ||
hook: jest.fn((hook, fn) => { | ||
const arg = { | ||
'components:dirs': [], | ||
'storybook:config': { stories: [] } | ||
} | ||
return fn(arg[hook]) | ||
}), | ||
} | ||
|
||
jest.mock('druxt-schema') | ||
|
||
describe('DruxtJS Site module', () => { | ||
test('Nuxt module', async () => { | ||
nuxtMock.options = { | ||
dir: { layouts: 'layouts' }, | ||
druxt: {}, | ||
srcDir: __dirname, | ||
} | ||
|
||
// Call DruxtSite module. | ||
await await DruxtSiteNuxtModule.setup({}, nuxtMock) | ||
|
||
// Expect 9 modules to be added. | ||
expect(installModule).toHaveBeenCalledTimes(8) | ||
}) | ||
}) |
2 changes: 1 addition & 1 deletion
2
packages/site/test/nuxtStorybook.test.js → packages/site/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.