forked from daren.hsu/line_push
133 lines
3.3 KiB
JavaScript
133 lines
3.3 KiB
JavaScript
/*!
|
|
* @nuxt/cli v2.13.3 (c) 2016-2020
|
|
|
|
* - All the amazing contributors
|
|
* Released under the MIT License.
|
|
* Website: https://nuxtjs.org
|
|
*/
|
|
'use strict';
|
|
|
|
const index = require('./cli-index.js');
|
|
require('path');
|
|
require('@nuxt/config');
|
|
require('exit');
|
|
const utils = require('@nuxt/utils');
|
|
require('chalk');
|
|
require('std-env');
|
|
require('wrap-ansi');
|
|
require('boxen');
|
|
require('consola');
|
|
require('minimist');
|
|
require('hable');
|
|
require('fs');
|
|
require('execa');
|
|
|
|
const generate = {
|
|
name: 'generate',
|
|
description: 'Generate a static web application (server-rendered)',
|
|
usage: 'generate <dir>',
|
|
options: {
|
|
...index.common,
|
|
...index.locking,
|
|
build: {
|
|
type: 'boolean',
|
|
default: true,
|
|
description: 'Only generate pages for dynamic routes, used for incremental builds. Generate has to be run once without this option before using it'
|
|
},
|
|
devtools: {
|
|
type: 'boolean',
|
|
default: false,
|
|
description: 'Enable Vue devtools',
|
|
prepare (cmd, options, argv) {
|
|
options.vue = options.vue || {};
|
|
options.vue.config = options.vue.config || {};
|
|
if (argv.devtools) {
|
|
options.vue.config.devtools = true;
|
|
}
|
|
}
|
|
},
|
|
quiet: {
|
|
alias: 'q',
|
|
type: 'boolean',
|
|
description: 'Disable output except for errors',
|
|
prepare (cmd, options, argv) {
|
|
// Silence output when using --quiet
|
|
options.build = options.build || {};
|
|
if (argv.quiet) {
|
|
options.build.quiet = true;
|
|
}
|
|
}
|
|
},
|
|
modern: {
|
|
...index.common.modern,
|
|
description: 'Generate app in modern build (modern mode can be only client)',
|
|
prepare (cmd, options, argv) {
|
|
if (index.normalizeArg(argv.modern)) {
|
|
options.modern = 'client';
|
|
}
|
|
}
|
|
},
|
|
'fail-on-error': {
|
|
type: 'boolean',
|
|
default: false,
|
|
description: 'Exit with non-zero status code if there are errors when generating pages'
|
|
}
|
|
},
|
|
async run (cmd) {
|
|
const config = await cmd.getNuxtConfig({
|
|
dev: false,
|
|
_build: cmd.argv.build,
|
|
_generate: true
|
|
});
|
|
|
|
if (config.target === utils.TARGETS.static) {
|
|
throw new Error("Please use `nuxt export` when using `target: 'static'`")
|
|
}
|
|
|
|
// Forcing static target anyway
|
|
config.target = utils.TARGETS.static;
|
|
|
|
// Disable analyze if set by the nuxt config
|
|
config.build = config.build || {};
|
|
config.build.analyze = false;
|
|
|
|
// Set flag to keep the prerendering behaviour
|
|
config._legacyGenerate = true;
|
|
|
|
const nuxt = await cmd.getNuxt(config);
|
|
|
|
if (cmd.argv.lock) {
|
|
await cmd.setLock(await index.createLock({
|
|
id: 'build',
|
|
dir: nuxt.options.buildDir,
|
|
root: config.rootDir
|
|
}));
|
|
|
|
nuxt.hook('build:done', async () => {
|
|
await cmd.releaseLock();
|
|
|
|
await cmd.setLock(await index.createLock({
|
|
id: 'generate',
|
|
dir: nuxt.options.generate.dir,
|
|
root: config.rootDir
|
|
}));
|
|
});
|
|
}
|
|
|
|
const generator = await cmd.getGenerator(nuxt);
|
|
await nuxt.server.listen(0);
|
|
|
|
const { errors } = await generator.generate({
|
|
init: true,
|
|
build: cmd.argv.build
|
|
});
|
|
|
|
await nuxt.close();
|
|
if (cmd.argv['fail-on-error'] && errors.length > 0) {
|
|
throw new Error('Error generating pages, exiting with non-zero code')
|
|
}
|
|
}
|
|
};
|
|
|
|
exports.default = generate;
|