Skip to content

Commit

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

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

/**
* Vue.js mixins.
*
Expand Down
81 changes: 81 additions & 0 deletions packages/entity/src/nuxt/index.js
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', { 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
71 changes: 0 additions & 71 deletions packages/entity/src/nuxtModule.js

This file was deleted.

0 comments on commit 82d8ce9

Please sign in to comment.