mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-18 02:07:14 +00:00
61 lines
1.4 KiB
JavaScript
Executable File
61 lines
1.4 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
// Show logs
|
|
process.env.DEBUG = 'nuxt:*'
|
|
|
|
var fs = require('fs')
|
|
var parseArgs = require('minimist')
|
|
var Nuxt = require('../')
|
|
var resolve = require('path').resolve
|
|
|
|
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'])
|
|
|
|
var options = {}
|
|
if (fs.existsSync(nuxtConfigFile)) {
|
|
options = require(nuxtConfigFile)
|
|
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
|
console.error(`> Could not load config file ${argv['config-file']}`)
|
|
process.exit(1)
|
|
}
|
|
if (typeof options.rootDir !== 'string') {
|
|
options.rootDir = rootDir
|
|
}
|
|
options.dev = false // Force production mode (no webpack middleware called)
|
|
|
|
console.log('[nuxt] Generating...') // eslint-disable-line no-console
|
|
var nuxt = module.exports = new Nuxt(options)
|
|
nuxt.generate()
|
|
.then(() => {
|
|
console.log('[nuxt] Generate done') // eslint-disable-line no-console
|
|
})
|
|
.catch((err) => {
|
|
console.error(err) // eslint-disable-line no-console
|
|
process.exit(1)
|
|
})
|