Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const generate = (nuxtentConfig, config = {}) => async () => {
const mergedConfig = {
...baseConfig(nuxtentConfig),
...config
}
// Build a fresh nuxt
nuxt = new Nuxt(mergedConfig)
const builder = new Builder(nuxt)
const generator = new Generator(nuxt, builder)
await generator.generate()
serve()
}
const generate = async (config = {}) => {
const mergedConfig = {
...baseConfig,
...config
};
// Build a fresh nuxt
nuxt = new Nuxt(mergedConfig);
const builder = new Builder(nuxt);
generator = new Generator(nuxt, builder);
await generator.generate();
serve(true);
};
process.on('message', async ({ action, target }) => {
if (action !== 'build') {
console.warn('Unknown action')
process.send({ status: 'error', err: `Nuxt process: unknown action ('${action}')` })
return
}
await nuxt.ready()
// https://github.com/nuxt/nuxt.js/blob/dev/packages/builder/src/builder.js
const builder = new Builder(nuxt)
// https://github.com/nuxt/nuxt.js/blob/dev/packages/generator/src/generator.js
const generator = new Generator(nuxt, builder)
if (target === 'development') {
builder.build().then(() => {
nuxt.listen(SERVER_PORT)
process.send({ status: 'ok' })
}).catch(err => {
console.error(err)
process.send({ status: 'error', err: err.message })
})
} else {
generator.generate({ build: true, init: true }).then(({ errors }) => {
if (errors.length === 0) process.send({ status: 'ok' })
else process.send({ status: 'error', err: 'Error occurred while generating pages' })
}).catch(err => {
console.error(err)
process.send({ status: 'error', err: err.message })
async setUp () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000
let builder = new Builder(this.nuxt)
let generator = new Generator(this.nuxt, builder)
await builder.build()
await generator.generate()
await this.nuxt.listen(this.port)
}
module.exports = async (sourceDir, cliOptions = {}) => {
process.env.NODE_ENV = "production";
const outDir = cliOptions.outDir || path.join(sourceDir, "dist");
const { nuxtConfig } = generateConfig(sourceDir, cliOptions);
nuxtConfig.generate.dir = outDir;
if (!cliOptions.analyze) {
delete nuxtConfig.build.analyze;
}
const nuxt = new Nuxt(nuxtConfig);
const builder = new Builder(nuxt);
const generator = new Generator(nuxt, builder);
const generateOptions = {
init: true,
build: true
};
try {
await generator.generate(generateOptions);
process.exit(0);
} catch (error) {
logger.fatal(error);
}
};