Skip to content

Commit

Permalink
[#21] Updated project structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Aug 10, 2020
1 parent 362df15 commit de09121
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 45 deletions.
47 changes: 3 additions & 44 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,10 @@
import consola from 'consola'
import { resolve } from 'path'
import { DruxtSchemaModule } from './module'

import { DruxtSchema } from './druxtSchema'
export { DruxtSchema }

export { DruxtSchemaMixin } from './mixin'
export { DruxtSchemaMixin } from './mixins/schema'

export { DruxtSchemaStore } from './store'

export default function (moduleOptions = {}) {
// Use root level Druxt options.
if (typeof this.options === 'undefined' || !this.options.druxt) {
throw new TypeError('Druxt settings missing.')
}
const options = this.options.druxt

// Add plugin.
this.addPlugin({
src: resolve(__dirname, '../nuxt/plugin.js'),
fileName: 'druxt-schema.js',
options
})

// Add Vuex plugin.
// @TODO - Ensure Vuex store is available.
this.addPlugin({
src: resolve(__dirname, '../nuxt/store.js'),
fileName: 'store/druxt-schema.js',
options
})

this.nuxt.hook('builder:prepared', async (nuxt, buildOptions) => {
// Generate schemas.
const druxtSchema = new DruxtSchema(options.baseUrl, options)
const { schemas } = await druxtSchema.get()

for (const name in schemas) {
const schema = schemas[name]
if (typeof schema === 'undefined') continue

this.addTemplate({
src: resolve(__dirname, '../nuxt/schema.json'),
fileName: `schemas/${name}.json`,
options: { schema }
})
}

consola.success('Druxt schema generated')
})
}
export default DruxtSchemaModule
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { shallowMount, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'

import { DruxtSchemaMixin, DruxtSchemaStore } from '..'
import { DruxtSchemaMixin, DruxtSchemaStore } from '../..'

// Setup local vue instance.
const localVue = createLocalVue()
Expand Down
File renamed without changes.
48 changes: 48 additions & 0 deletions src/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import consola from 'consola'
import { resolve } from 'path'

import { DruxtSchema } from './druxtSchema'

const DruxtSchemaModule = function (moduleOptions = {}) {
// Use root level Druxt options.
if (typeof this.options === 'undefined' || !this.options.druxt) {
throw new TypeError('Druxt settings missing.')
}
const options = this.options.druxt

// Add plugin.
this.addPlugin({
src: resolve(__dirname, '../nuxt/plugin.js'),
fileName: 'druxt-schema.js',
options
})

// Add Vuex plugin.
// @TODO - Ensure Vuex store is available.
this.addPlugin({
src: resolve(__dirname, '../nuxt/store.js'),
fileName: 'store/druxt-schema.js',
options
})

this.nuxt.hook('builder:prepared', async (nuxt, buildOptions) => {
// Generate schemas.
const druxtSchema = new DruxtSchema(options.baseUrl, options)
const { schemas } = await druxtSchema.get()

for (const name in schemas) {
const schema = schemas[name]
if (typeof schema === 'undefined') continue

this.addTemplate({
src: resolve(__dirname, '../nuxt/schema.json'),
fileName: `schemas/${name}.json`,
options: { schema }
})
}

consola.success('Druxt schema generated')
})
}

export { DruxtSchemaModule }

0 comments on commit de09121

Please sign in to comment.