-
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-blocks for @nuxt/kit
- Loading branch information
Showing
11 changed files
with
128 additions
and
115 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
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,73 @@ | ||
import { defineNuxtModule, installModule } from '@nuxt/kit' | ||
import { join } from 'path' | ||
// import DruxtBlocksStorybook from './storybook' | ||
|
||
/** | ||
* The Nuxt.js module function. | ||
* | ||
* - Adds the Vue.js components to the Nuxt.js frontend. | ||
* | ||
* The module function should not be used directly, but rather installed via yout Nuxt.js configuration file. | ||
* | ||
* Options are set on the root level `druxt` Nuxt.js config object. | ||
* | ||
* @example @lang js | ||
* // `nuxt.config.js` | ||
* module.exports = { | ||
* modules: [ | ||
* 'druxt-blocks' | ||
* ], | ||
* druxt: { | ||
* baseUrl: 'https://demo-api.druxtjs.org' | ||
* } | ||
* } | ||
* | ||
* @param {object} moduleOptions - Nuxt.js module options object. | ||
*/ | ||
const DruxtBlocksNuxtModule = defineNuxtModule({ | ||
meta: { | ||
name: 'druxt-blocks' | ||
}, | ||
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 || {}, | ||
blocks: { | ||
query: {}, | ||
...nuxt.options?.druxt?.blocks, | ||
...moduleOptions, | ||
} | ||
} | ||
|
||
// Add Druxt module. | ||
await installModule('druxt/nuxt', options, nuxt) | ||
|
||
// Register components directories. | ||
nuxt.hook('components:dirs', dirs => { | ||
dirs.push({ path: join(__dirname, '../dist/components') }) | ||
dirs.push({ path: join(__dirname, '../dist/components/blocks') }) | ||
}) | ||
|
||
// Nuxt Storybook. | ||
// @TODO - @nuxt/kit and @nuxt/storybook aren't compatible. | ||
// nuxt.hook('storybook:config', async ({ stories }) => { | ||
// await DruxtBlocksStorybook.call(nuxt, { stories }) | ||
// }) | ||
} | ||
}) | ||
|
||
export default DruxtBlocksNuxtModule | ||
|
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.
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,25 @@ | ||
import DruxtBlocksNuxtModule from '../../src/nuxt' | ||
|
||
// jest.mock('../src/nuxt/storybook') | ||
|
||
jest.mock('@nuxt/kit', () => ({ | ||
defineNuxtModule: (module) => module, | ||
installModule: jest.fn(), | ||
})) | ||
|
||
const nuxtMock = { | ||
hook: jest.fn((hook, fn) => { | ||
const arg = { | ||
'components:dirs': [], | ||
// 'storybook:config': { stories: [] } | ||
} | ||
return fn(arg[hook]) | ||
}), | ||
} | ||
|
||
test('Nuxt module', async () => { | ||
nuxtMock.options = { | ||
druxt: {} | ||
} | ||
await DruxtBlocksNuxtModule.setup({}, nuxtMock) | ||
}) |
7 changes: 6 additions & 1 deletion
7
packages/blocks/test/nuxtStorybook.test.js → packages/blocks/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.