mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-16 19:04:48 +00:00
50 lines
1.1 KiB
TypeScript
Executable File
50 lines
1.1 KiB
TypeScript
Executable File
import 'v8-compile-cache'
|
|
import mri from 'mri'
|
|
import { red, cyan } from 'colorette'
|
|
import { commands } from './commands'
|
|
import { showHelp } from './utils/help'
|
|
import { showBanner } from './utils/banner'
|
|
import { error } from './utils/log'
|
|
|
|
async function _main () {
|
|
const _argv = process.argv.slice(2)
|
|
const args = mri(_argv)
|
|
// @ts-ignore
|
|
let command = args._.shift() || 'usage'
|
|
|
|
showBanner(command === 'dev')
|
|
|
|
if (!(command in commands)) {
|
|
console.log('\n' + red('Invalid command ' + command))
|
|
command = 'usage'
|
|
}
|
|
|
|
if (command === 'usage') {
|
|
console.log(`\nUsage: ${cyan(`nu ${Object.keys(commands).join('|')} [args]`)}\n`)
|
|
process.exit(1)
|
|
}
|
|
|
|
try {
|
|
const cmd = await commands[command]()
|
|
if (args.h || args.help) {
|
|
showHelp(cmd.meta)
|
|
} else {
|
|
await cmd.invoke(args)
|
|
}
|
|
} catch (err) {
|
|
onFatalError(err)
|
|
}
|
|
}
|
|
|
|
function onFatalError (err) {
|
|
error(err)
|
|
process.exit(1)
|
|
}
|
|
|
|
process.on('unhandledRejection', err => error('[unhandledRejection]', err))
|
|
process.on('uncaughtException', err => error('[uncaughtException]', err))
|
|
|
|
export function main () {
|
|
_main().catch(onFatalError)
|
|
}
|