2021-04-09 15:52:45 +00:00
|
|
|
import mri from 'mri'
|
2021-11-22 17:19:34 +00:00
|
|
|
import { red } from 'colorette'
|
2021-10-07 10:15:15 +00:00
|
|
|
import consola from 'consola'
|
2021-10-18 19:31:15 +00:00
|
|
|
import { checkEngines } from './utils/engines'
|
2021-07-26 14:04:35 +00:00
|
|
|
import { commands, Command, NuxtCommand } from './commands'
|
2021-04-09 15:52:45 +00:00
|
|
|
import { showHelp } from './utils/help'
|
2021-04-15 19:17:44 +00:00
|
|
|
import { showBanner } from './utils/banner'
|
2021-01-20 14:43:43 +00:00
|
|
|
|
|
|
|
async function _main () {
|
2021-04-09 15:52:45 +00:00
|
|
|
const _argv = process.argv.slice(2)
|
2021-07-02 12:45:15 +00:00
|
|
|
const args = mri(_argv, {
|
|
|
|
boolean: [
|
|
|
|
'no-clear'
|
|
|
|
]
|
|
|
|
})
|
2021-04-09 15:52:45 +00:00
|
|
|
// @ts-ignore
|
2021-11-22 17:19:34 +00:00
|
|
|
const command = args._.shift() || 'usage'
|
2021-03-28 21:01:51 +00:00
|
|
|
|
2021-07-02 12:45:15 +00:00
|
|
|
showBanner(command === 'dev' && args.clear !== false)
|
2021-03-28 21:01:51 +00:00
|
|
|
|
2021-04-09 15:52:45 +00:00
|
|
|
if (!(command in commands)) {
|
|
|
|
console.log('\n' + red('Invalid command ' + command))
|
2021-11-22 17:19:34 +00:00
|
|
|
|
|
|
|
await commands.usage().then(r => r.invoke())
|
|
|
|
process.exit(1)
|
2021-04-09 15:52:45 +00:00
|
|
|
}
|
2021-03-28 21:01:51 +00:00
|
|
|
|
2021-10-18 19:31:15 +00:00
|
|
|
// Check Node.js version in background
|
|
|
|
setTimeout(() => { checkEngines() }, 1000)
|
|
|
|
|
2021-04-09 15:52:45 +00:00
|
|
|
try {
|
2021-10-02 14:05:26 +00:00
|
|
|
// @ts-ignore default.default is hotfix for #621
|
2021-10-02 16:01:17 +00:00
|
|
|
const cmd = await commands[command as Command]() as NuxtCommand
|
2021-04-09 15:52:45 +00:00
|
|
|
if (args.h || args.help) {
|
|
|
|
showHelp(cmd.meta)
|
|
|
|
} else {
|
|
|
|
await cmd.invoke(args)
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
onFatalError(err)
|
2021-01-20 15:44:52 +00:00
|
|
|
}
|
2021-04-09 15:52:45 +00:00
|
|
|
}
|
2021-01-20 15:44:52 +00:00
|
|
|
|
2021-07-26 14:04:35 +00:00
|
|
|
function onFatalError (err: unknown) {
|
2021-10-07 10:15:15 +00:00
|
|
|
consola.error(err)
|
2021-04-09 15:52:45 +00:00
|
|
|
process.exit(1)
|
2021-01-20 14:43:43 +00:00
|
|
|
}
|
|
|
|
|
2021-10-07 10:15:15 +00:00
|
|
|
// Wrap all console logs with consola for better DX
|
|
|
|
consola.wrapConsole()
|
|
|
|
|
|
|
|
process.on('unhandledRejection', err => consola.error('[unhandledRejection]', err))
|
|
|
|
process.on('uncaughtException', err => consola.error('[uncaughtException]', err))
|
2021-04-15 19:17:44 +00:00
|
|
|
|
2021-01-20 14:43:43 +00:00
|
|
|
export function main () {
|
2021-04-09 15:52:45 +00:00
|
|
|
_main().catch(onFatalError)
|
2021-01-20 14:43:43 +00:00
|
|
|
}
|