Nuxt/packages/cli/src/commands/generate.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

import consola from 'consola'
import { common } from '../options'
export default {
name: 'generate',
description: 'Generate a static web application (server-rendered)',
usage: 'generate <dir>',
options: {
...common,
build: {
type: 'boolean',
default: true,
description: 'Only generate pages for dynamic routes. Nuxt has to be built once before using this option'
},
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
}
}
},
modern: {
...common.modern,
description: 'Generate app in modern build (modern mode can be only client)',
prepare(cmd, options, argv) {
2018-11-08 09:18:56 +00:00
if (argv.modern !== undefined) {
options.modern = 'client'
}
}
}
},
async run(cmd) {
const argv = cmd.getArgv()
const generator = await cmd.getGenerator(
await cmd.getNuxt(
await cmd.getNuxtConfig(argv, { dev: false })
)
)
return generator.generate({
init: true,
build: argv.build
}).then(() => {
process.exit(0)
}).catch(err => consola.fatal(err))
}
}