Skip to content

Commit

Permalink
feat(#693): initial druxt-menu update for @nuxt/kit
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Aug 8, 2024
1 parent 676652d commit 44ab6c9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 86 deletions.
5 changes: 4 additions & 1 deletion packages/menu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@
"require": "./dist/druxt-menu.ssr.js",
"import": "./dist/druxt-menu.esm.js"
},
"./components/*": "./dist/components/*"
"./components/*": "./dist/components/*",
"./nuxt": "./nuxt/index.js"
},
"main": "dist/druxt-menu.ssr.js",
"module": "dist/druxt-menu.esm.js",
"files": [
"dist",
"nuxt",
"templates"
],
"dependencies": {
"@nuxt/kit": "^3.12.2",
"deepmerge": "^4.3.1",
"drupal-jsonapi-params": "^2.2.0",
"druxt": "^0.24.0",
Expand Down
14 changes: 0 additions & 14 deletions packages/menu/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { DruxtMenuNuxtModule } from './nuxtModule'

/**
* The DruxtMenu class.
*
Expand All @@ -22,18 +20,6 @@ export { DruxtMenu } from './menu.js'
*/
export { DruxtMenuStore } from './stores/menu.js'

/**
* The Nuxt.js module function.
*
* Installs the module functionality in a Nuxt application.
*
* @type {Function}
* @exports default
* @name DruxtMenuNuxtModule
* @see {@link ./nuxtModule|DruxtMenuNuxtModule}
*/
export default DruxtMenuNuxtModule

/**
* Vue.js Mixin.
*
Expand Down
81 changes: 81 additions & 0 deletions packages/menu/src/nuxt/index.js
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 '../nuxtStorybook'

/**
* 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
71 changes: 0 additions & 71 deletions packages/menu/src/nuxtModule.js

This file was deleted.

0 comments on commit 44ab6c9

Please sign in to comment.