2016-11-08 00:18:26 +00:00
|
|
|
#!/usr/bin/env node
|
2018-06-01 12:26:13 +00:00
|
|
|
|
2018-03-31 16:22:14 +00:00
|
|
|
const consola = require('consola')
|
2018-10-17 21:28:25 +00:00
|
|
|
const cli = require('../dist/cli.js')
|
2016-11-07 01:34:58 +00:00
|
|
|
|
2018-01-11 14:11:49 +00:00
|
|
|
// Global error handler
|
2018-10-17 21:28:25 +00:00
|
|
|
process.on('unhandledRejection', (err) => {
|
|
|
|
consola.error(err)
|
|
|
|
})
|
2016-11-07 01:34:58 +00:00
|
|
|
|
2018-04-01 19:36:30 +00:00
|
|
|
// Exit process on fatal errors
|
|
|
|
consola.add({
|
|
|
|
log(logObj) {
|
|
|
|
if (logObj.type === 'fatal') {
|
|
|
|
process.stderr.write('Nuxt Fatal Error :(\n')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-06-16 12:42:45 +00:00
|
|
|
const defaultCommand = 'dev'
|
2018-10-17 21:28:25 +00:00
|
|
|
const commands = new Set([
|
|
|
|
defaultCommand,
|
|
|
|
'build',
|
|
|
|
'start',
|
|
|
|
'generate'
|
|
|
|
])
|
2016-11-07 01:34:58 +00:00
|
|
|
|
2018-07-20 15:42:31 +00:00
|
|
|
let cmd = process.argv[2]
|
2016-11-07 01:34:58 +00:00
|
|
|
|
|
|
|
if (commands.has(cmd)) {
|
2017-01-20 11:43:48 +00:00
|
|
|
process.argv.splice(2, 1)
|
2016-11-07 01:34:58 +00:00
|
|
|
} else {
|
|
|
|
cmd = defaultCommand
|
|
|
|
}
|
|
|
|
|
2018-10-17 21:28:25 +00:00
|
|
|
// Apply default NODE_ENV if not provided
|
|
|
|
if (!process.env.NODE_ENV) {
|
|
|
|
process.env.NODE_ENV = cmd === 'dev' ? 'development' : 'production'
|
|
|
|
}
|
2016-11-07 01:34:58 +00:00
|
|
|
|
2018-10-17 21:28:25 +00:00
|
|
|
cli[cmd]().then(m => m.default()).catch((error) => {
|
|
|
|
consola.fatal(error)
|
|
|
|
})
|