-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 1 addition & 1 deletion
2
src/__tests__/mixin.test.js → src/mixins/__tests__/schema.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |