mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
65 lines
1.5 KiB
JavaScript
Executable File
65 lines
1.5 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
// Show logs
|
|
process.env.DEBUG = 'nuxt:*'
|
|
|
|
const fs = require('fs')
|
|
const parseArgs = require('minimist')
|
|
const debug = require('debug')('nuxt:generate')
|
|
|
|
const { Nuxt } = require('../')
|
|
const resolve = require('path').resolve
|
|
|
|
const 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)
|
|
}
|
|
|
|
const rootDir = resolve(argv._[0] || '.')
|
|
const 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)
|
|
options.runBuild = true // Force doing production build before init
|
|
|
|
debug('Generating...')
|
|
const nuxt = module.exports = new Nuxt(options)
|
|
nuxt.generate()
|
|
.then(() => {
|
|
debug('Generate done')
|
|
process.exit(0)
|
|
})
|
|
.catch((err) => {
|
|
console.error(err) // eslint-disable-line no-console
|
|
process.exit(1)
|
|
})
|