Nuxt/bin/nuxt-generate

57 lines
1.4 KiB
Plaintext
Raw Normal View History

2016-11-10 11:33:52 +00:00
#!/usr/bin/env node
2017-06-16 12:42:45 +00:00
const parseArgs = require('minimist')
2018-03-31 16:22:14 +00:00
const consola = require('consola')
const { Nuxt, Builder, Generator } = require('..')
const { loadNuxtConfig } = require('./common/utils')
2017-06-16 12:42:45 +00:00
const argv = parseArgs(process.argv.slice(2), {
2017-06-11 13:48:20 +00:00
alias: {
h: 'help',
2017-08-18 10:54:35 +00:00
c: 'config-file',
2017-08-19 13:22:53 +00:00
s: 'spa',
u: 'universal'
2017-06-11 13:48:20 +00:00
},
boolean: ['h', 's', 'u', 'build'],
2017-08-19 13:22:53 +00:00
string: ['c'],
2017-06-11 13:48:20 +00:00
default: {
c: 'nuxt.config.js',
build: true
2017-06-11 13:48:20 +00:00
}
})
if (argv.help) {
2018-03-31 16:22:14 +00:00
process.stderr.write(`
2017-06-11 13:48:20 +00:00
Description
Generate a static web application (server-rendered)
Usage
$ nuxt generate <dir>
Options
2017-08-19 13:22:53 +00:00
--spa Launch in SPA mode
--universal Launch in Universal mode (default)
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
--help, -h Displays this message
--no-build Just run generate for faster builds when just dynamic routes changed. Nuxt build is needed before this command.
2017-06-11 13:48:20 +00:00
`)
process.exit(0)
}
const options = loadNuxtConfig(argv)
2016-12-07 17:47:47 +00:00
2017-02-03 14:09:27 +00:00
options.dev = false // Force production mode (no webpack middleware called)
2016-11-10 11:33:52 +00:00
const nuxt = new Nuxt(options)
const builder = new Builder(nuxt)
const generator = new Generator(nuxt, builder)
const generateOptions = {
init: true,
build: argv.build
}
2018-01-11 16:11:50 +00:00
generator
.generate(generateOptions)
2017-06-16 12:42:45 +00:00
.then(() => {
process.exit(0)
})
2018-07-25 15:57:43 +00:00
.catch(err => consola.fatal(err))