-
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-entity for @nuxt/kit
- Loading branch information
Showing
10 changed files
with
123 additions
and
116 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 { defineNuxtModule, installModule } from '@nuxt/kit' | ||
import { join } from 'path' | ||
// import DruxtEntityStorybook from '../nuxtStorybook' | ||
|
||
/** | ||
* The Nuxt.js module function. | ||
* | ||
* - Adds dependant modules. | ||
* - Adds Nuxt plugin. | ||
* - 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-entity' | ||
* ], | ||
* druxt: { | ||
* baseUrl: 'https://demo-api.druxtjs.org' | ||
* } | ||
* } | ||
* | ||
* @todo Document options. | ||
* | ||
* @property {object} options.druxt - DruxtJS root level options. | ||
* @property {string} options.druxt.baseUrl - Base URL of Drupal JSON:API backend. | ||
*/ | ||
const DruxtEntityNuxtModule = defineNuxtModule({ | ||
meta: { | ||
name: 'druxt-entity', | ||
}, | ||
defaults: { | ||
baseUrl: '', | ||
endpoint: '/jsonapi' | ||
}, | ||
|
||
async setup(moduleOptions, nuxt) { | ||
// Set default options. | ||
const options = { | ||
baseUrl: moduleOptions.baseUrl, | ||
...nuxt.options?.druxt, | ||
entity: { | ||
query: {}, | ||
...nuxt.options?.druxt?.entity, | ||
...moduleOptions, | ||
components: { | ||
fields: false, | ||
...nuxt.options?.druxt?.entity?.components, | ||
...moduleOptions?.components | ||
} | ||
} | ||
} | ||
|
||
// Add dependant modules. | ||
await installModule('druxt/nuxt', options, nuxt) | ||
await installModule('druxt-schema/nuxt', { baseUrl: options.baseUrl }, nuxt) | ||
|
||
// Register components directories. | ||
nuxt.hook('components:dirs', dirs => { | ||
dirs.push({ | ||
path: join(__dirname, '../dist/components'), | ||
ignore: ['fields'] | ||
}) | ||
if (options.entity.components.fields) { | ||
dirs.push({ path: join(__dirname, '../dist/components/fields') }) | ||
} | ||
}) | ||
|
||
// Nuxt Storybook. | ||
// @TODO - @nuxt/kit and @nuxt/storybook aren't compatible. | ||
// this.nuxt.hook('storybook:config', async ({ stories }) => { | ||
// await DruxtEntityStorybook.call(this, { stories }) | ||
// }) | ||
} | ||
}) | ||
|
||
export default DruxtEntityNuxtModule |
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
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,26 @@ | ||
import DruxtEntityNuxtModule from '../../src/nuxt' | ||
|
||
// jest.mock('../src/nuxtStorybook') | ||
|
||
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: {}, | ||
modules: [], | ||
} | ||
await DruxtEntityNuxtModule.setup({}, nuxtMock) | ||
}) |
2 changes: 1 addition & 1 deletion
2
packages/entity/test/nuxtStorybook.test.js → packages/entity/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.