2018-10-17 21:28:25 +00:00
|
|
|
import consola from 'consola'
|
2018-10-29 22:16:16 +00:00
|
|
|
import { common } from '../options'
|
2018-11-22 15:48:26 +00:00
|
|
|
import { normalizeArg } from '../utils'
|
2018-10-17 21:28:25 +00:00
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
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'
|
2018-11-07 23:37:06 +00:00
|
|
|
},
|
2018-11-17 23:05:51 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-11-07 23:37:06 +00:00
|
|
|
modern: {
|
|
|
|
...common.modern,
|
|
|
|
description: 'Generate app in modern build (modern mode can be only client)',
|
|
|
|
prepare(cmd, options, argv) {
|
2018-11-22 15:48:26 +00:00
|
|
|
if (normalizeArg(argv.modern)) {
|
2018-11-07 23:37:06 +00:00
|
|
|
options.modern = 'client'
|
|
|
|
}
|
|
|
|
}
|
2018-10-29 22:16:16 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
async run(cmd) {
|
|
|
|
const argv = cmd.getArgv()
|
2018-10-17 21:28:25 +00:00
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
const generator = await cmd.getGenerator(
|
|
|
|
await cmd.getNuxt(
|
|
|
|
await cmd.getNuxtConfig(argv, { dev: false })
|
|
|
|
)
|
2018-10-25 07:43:42 +00:00
|
|
|
)
|
2018-10-17 21:28:25 +00:00
|
|
|
|
2018-10-29 22:16:16 +00:00
|
|
|
return generator.generate({
|
|
|
|
init: true,
|
|
|
|
build: argv.build
|
|
|
|
}).then(() => {
|
|
|
|
process.exit(0)
|
|
|
|
}).catch(err => consola.fatal(err))
|
|
|
|
}
|
2018-10-17 21:28:25 +00:00
|
|
|
}
|