-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.ts
More file actions
43 lines (38 loc) · 1.19 KB
/
run.ts
File metadata and controls
43 lines (38 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { ArgsDef, CommandDef } from 'citty'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import { runCommand as _runCommand } from 'citty'
import { isNuxiCommand } from './commands/_utils'
globalThis.__nuxt_cli__ = globalThis.__nuxt_cli__ || {
// Programmatic usage fallback
startTime: Date.now(),
entry: fileURLToPath(
new URL('../../bin/nuxi.mjs', import.meta.url),
),
devEntry: fileURLToPath(
new URL('../dev/index.mjs', import.meta.url),
),
}
// To provide subcommands call it as `runCommand(<command>, [<subcommand>, ...])`
export async function runCommand<T extends ArgsDef = ArgsDef>(
command: CommandDef<T>,
argv: string[] = process.argv.slice(2),
data: { overrides?: Record<string, any> } = {},
) {
argv.push('--no-clear') // Dev
if (command.meta && 'name' in command.meta && typeof command.meta.name === 'string') {
const name = command.meta.name
if (!(isNuxiCommand(name))) {
throw new Error(`Invalid command ${name}`)
}
}
else {
throw new Error(`Invalid command, must be named`)
}
return await _runCommand(command, {
rawArgs: argv,
data: {
overrides: data.overrides || {},
},
})
}