2022-03-17 18:49:59 +00:00
|
|
|
import mri from 'mri'
|
2022-12-11 21:44:52 +00:00
|
|
|
import type { Command, NuxtCommand } from './commands'
|
|
|
|
import { commands } from './commands'
|
2022-03-17 18:49:59 +00:00
|
|
|
|
2023-03-08 11:32:00 +00:00
|
|
|
export async function runCommand (command: string, argv = process.argv.slice(2), options: Record<string, any> = {}) {
|
2022-03-17 18:49:59 +00:00
|
|
|
const args = mri(argv)
|
|
|
|
args.clear = false // used by dev
|
|
|
|
const cmd = await commands[command as Command]() as NuxtCommand
|
|
|
|
if (!cmd) {
|
|
|
|
throw new Error(`Invalid command ${command}`)
|
|
|
|
}
|
2023-03-08 11:32:00 +00:00
|
|
|
await cmd.invoke(args, options)
|
2022-03-17 18:49:59 +00:00
|
|
|
}
|