Skip to content

Commit

Permalink
feat(#349): enable dependencies (#540)
Browse files Browse the repository at this point in the history
* feat(#349): enable breadcrumb dependencies

* feat(#349): enable druxt-menu dependencies

* feat(#349): enable druxt-router dependencies
  • Loading branch information
Decipher authored Jul 19, 2022
1 parent 2f2a7cc commit 54c8ece
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .changeset/itchy-roses-cross.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"druxt-site": minor
---

Added watch for 'theme' prop
Added watch for 'theme' prop.
5 changes: 5 additions & 0 deletions .changeset/lazy-wasps-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"druxt-router": minor
---

Enabled dependencies when only using Nuxt druxt-router module.
5 changes: 5 additions & 0 deletions .changeset/pink-laws-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"druxt-breadcrumb": minor
---

Enabled dependencies when only using Nuxt druxt-breadcrumb module.
5 changes: 5 additions & 0 deletions .changeset/ten-vans-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"druxt-menu": minor
---

Enabled dependencies when only using Nuxt druxt-menu module.
2 changes: 1 addition & 1 deletion .changeset/three-emus-deny.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"druxt-entity": minor
---

Added watch for 'settings' prop
Added watch for 'settings' prop.
2 changes: 1 addition & 1 deletion .changeset/tidy-melons-add.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"druxt-views": minor
---

Added watch for 'arguments' prop
Added watch for 'arguments' prop.
21 changes: 17 additions & 4 deletions packages/breadcrumb/src/nuxtModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,34 @@ import { join, resolve } from 'path'
*
* @param {object} moduleOptions - Nuxt.js module options object.
*/
const DruxtBreadcrumbModule = function () {
const DruxtBreadcrumbModule = async function (moduleOptions = {}) {
// Set default options.
const options = {
baseUrl: moduleOptions.baseUrl,
...(this.options || {}).druxt || {},
breadcrumb: {
...((this.options || {}).druxt || {}).breadcrumb,
...moduleOptions,
}
}

// Add dependent module.
await this.addModule(['druxt', options])
await this.addModule(['druxt-router/nuxt', options])

// Register components directories.
this.nuxt.hook('components:dirs', dirs => {
dirs.push({ path: join(__dirname, 'components') })
dirs.push({ path: join(__dirname, 'components/blocks') })
})

// Nuxt Storybook.
const { addTemplate, options } = this
this.nuxt.hook('storybook:config', ({ stories }) => {
addTemplate({
this.addTemplate({
src: resolve(__dirname, '../templates/druxt-breadcrumb.stories.js'),
fileName: 'stories/druxt-breadcrumb.stories.js',
})
stories.push(resolve(options.buildDir, './stories/druxt-breadcrumb.stories.js'))
stories.push(resolve(this.options.buildDir, './stories/druxt-breadcrumb.stories.js'))
})
}

Expand Down
8 changes: 4 additions & 4 deletions packages/menu/src/nuxtModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import DruxtMenuStorybook from './nuxtStorybook'
*
* @param {object} moduleOptions - Module options object.
*/
const DruxtMenuNuxtModule = function (moduleOptions = {}) {
const DruxtMenuNuxtModule = async function (moduleOptions = {}) {
// Set default options.
const options = {
baseUrl: moduleOptions.baseUrl,
Expand All @@ -36,6 +36,9 @@ const DruxtMenuNuxtModule = function (moduleOptions = {}) {
}
}

// Add dependant modules.
await this.addModule(['druxt', options])

// Register components directories.
this.nuxt.hook('components:dirs', dirs => {
dirs.push({ path: join(__dirname, 'components') })
Expand All @@ -49,9 +52,6 @@ const DruxtMenuNuxtModule = function (moduleOptions = {}) {
options
})

// Enable Vuex Store.
this.options.store = true

// Add Vuex plugin.
this.addPlugin({
src: resolve(__dirname, '../templates/store.js'),
Expand Down
5 changes: 3 additions & 2 deletions packages/menu/test/nuxtModule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DruxtMenuNuxtModule } from '../src/nuxtModule'
jest.mock('../src/nuxtStorybook')

const mock = {
addModule: jest.fn(),
addPlugin: jest.fn(),
nuxt: {
hook: jest.fn((hook, fn) => {
Expand All @@ -18,7 +19,7 @@ const mock = {
}
}

test('Nuxt module', () => {
DruxtMenuNuxtModule.call(mock)
test('Nuxt module', async () => {
await DruxtMenuNuxtModule.call(mock)
expect(mock.addPlugin).toHaveBeenCalled()
})
6 changes: 3 additions & 3 deletions packages/router/src/nuxt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const DruxtRouterNuxtModule = async function (moduleOptions = {}) {
}
}

// Add dependant modules.
await this.addModule(['druxt', options])

// Register components directories.
this.nuxt.hook('components:dirs', dirs => {
dirs.push({ path: join(__dirname, '../dist/components') })
Expand Down Expand Up @@ -107,9 +110,6 @@ const DruxtRouterNuxtModule = async function (moduleOptions = {}) {
options
})

// Enable Vuex Store.
this.options.store = true

// Add Vuex plugin.
this.addPlugin({
src: resolve(__dirname, '../templates/store.js'),
Expand Down
1 change: 1 addition & 0 deletions packages/router/test/nuxt/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import DruxtRouterNuxtModule from '../../nuxt'

const mock = {
addModule: jest.fn(),
addPlugin: jest.fn(),
addTemplate: jest.fn(),
extendRoutes: jest.fn((func) => {
Expand Down

0 comments on commit 54c8ece

Please sign in to comment.