-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathnuxtModule.js
77 lines (69 loc) · 1.92 KB
/
nuxtModule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { existsSync } from 'fs'
import { join, resolve } from 'path'
import DruxtSiteStorybook from './nuxtStorybook'
/**
* Nuxt module function to install Druxt Site.
*
* - Adds the DruxtSite component.
* - Adds the core modules for DruxtJS Site.
* - Adds default configuration for @nuxtjs/proxy.
* - Enables Vuex store.
*
* @param {ModuleOptions} moduleOptions - The Nuxt.js module options.
*/
const DruxtSiteNuxtModule = async function (moduleOptions = {}) {
// Set default options.
const options = {
baseUrl: moduleOptions.baseUrl,
...(this.options || {}).druxt || {},
menu: {
jsonApiMenuItems: true,
...((this.options || {}).druxt || {}).menu,
},
proxy: {
api: false,
files: true,
...((this.options || {}).druxt || {}).proxy,
},
site: {
layout: true,
...((this.options || {}).druxt || {}).site,
...moduleOptions,
},
}
this.options.druxt = options
// Register components directories.
this.nuxt.hook('components:dirs', dirs => {
dirs.push({ path: join(__dirname, 'components') })
})
// Add Druxt modules.
const druxtModules = [
'druxt',
'druxt-blocks',
'druxt-breadcrumb',
'druxt-entity',
'druxt-menu',
'druxt-router/nuxt',
'druxt-schema',
'druxt-views'
]
for (const module of druxtModules) {
await this.addModule(module)
}
// Add default layout.
if (!(await existsSync(resolve(this.options.srcDir, this.options.dir.layouts))) && options.site.layout) {
this.addLayout(resolve(__dirname, './layouts/default.vue'), 'default')
}
// Nuxt Storybook.
this.nuxt.hook('storybook:config', async ({ stories }) => {
await DruxtSiteStorybook.call(this, { options, stories })
})
}
DruxtSiteNuxtModule.meta = require('../package.json')
export { DruxtSiteNuxtModule }
/**
* Module options object.
*
* @typedef {object} ModuleOptions
* @see {@link ./typedefs/moduleOptions|ModuleOptions}
*/