2016-11-10 11:33:52 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2016-11-10 14:24:22 +00:00
|
|
|
// Show logs
|
|
|
|
process.env.DEBUG = 'nuxt:*'
|
|
|
|
|
2016-12-09 18:40:59 +00:00
|
|
|
var fs = require('fs')
|
2017-06-11 13:48:20 +00:00
|
|
|
var parseArgs = require('minimist')
|
2016-12-09 18:40:59 +00:00
|
|
|
var Nuxt = require('../')
|
|
|
|
var resolve = require('path').resolve
|
2016-11-10 11:33:52 +00:00
|
|
|
|
2017-06-11 13:48:20 +00:00
|
|
|
var argv = parseArgs(process.argv.slice(2), {
|
|
|
|
alias: {
|
|
|
|
h: 'help',
|
|
|
|
c: 'config-file'
|
|
|
|
},
|
|
|
|
boolean: ['h'],
|
|
|
|
string: ['c'],
|
|
|
|
default: {
|
|
|
|
c: 'nuxt.config.js'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (argv.help) {
|
|
|
|
console.log(`
|
|
|
|
Description
|
|
|
|
Generate a static web application (server-rendered)
|
|
|
|
Usage
|
|
|
|
$ nuxt generate <dir>
|
|
|
|
Options
|
|
|
|
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
|
|
|
--help, -h Displays this message
|
|
|
|
`)
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
var rootDir = resolve(argv._[0] || '.')
|
|
|
|
var nuxtConfigFile = resolve(rootDir, argv['config-file'])
|
2016-12-07 17:47:47 +00:00
|
|
|
|
2016-12-09 18:40:59 +00:00
|
|
|
var options = {}
|
2016-11-10 11:33:52 +00:00
|
|
|
if (fs.existsSync(nuxtConfigFile)) {
|
|
|
|
options = require(nuxtConfigFile)
|
2017-06-11 13:48:20 +00:00
|
|
|
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
|
|
|
console.error(`> Could not load config file ${argv['config-file']}`)
|
|
|
|
process.exit(1)
|
2016-11-10 11:33:52 +00:00
|
|
|
}
|
|
|
|
if (typeof options.rootDir !== 'string') {
|
|
|
|
options.rootDir = rootDir
|
|
|
|
}
|
2017-02-03 14:09:27 +00:00
|
|
|
options.dev = false // Force production mode (no webpack middleware called)
|
2017-06-14 18:51:14 +00:00
|
|
|
options.runBuild = true // Force doing production build before init
|
2016-11-10 11:33:52 +00:00
|
|
|
|
2016-12-08 15:41:20 +00:00
|
|
|
console.log('[nuxt] Generating...') // eslint-disable-line no-console
|
2017-05-31 14:21:16 +00:00
|
|
|
var nuxt = module.exports = new Nuxt(options)
|
|
|
|
nuxt.generate()
|
2017-06-11 13:48:20 +00:00
|
|
|
.then(() => {
|
|
|
|
console.log('[nuxt] Generate done') // eslint-disable-line no-console
|
2017-06-12 17:37:28 +00:00
|
|
|
process.exit(0)
|
2017-06-11 13:48:20 +00:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err) // eslint-disable-line no-console
|
|
|
|
process.exit(1)
|
|
|
|
})
|