| 33 | } |
| 34 | |
| 35 | function runCommand(command: string, args: string[], options: RunCommandOptions = {}) { |
| 36 | return new Promise<void>((resolve, reject) => { |
| 37 | const child = spawn(command, args, { |
| 38 | cwd: options.cwd ?? projectRoot, |
| 39 | env: { ...process.env, ...options.env }, |
| 40 | stdio: 'inherit', |
| 41 | shell: process.platform === 'win32', |
| 42 | }); |
| 43 | |
| 44 | child.on('error', (error) => reject(error)); |
| 45 | child.on('close', (code, signal) => { |
| 46 | if (code === 0) { |
| 47 | resolve(); |
| 48 | } else { |
| 49 | const reason = signal ? `signal ${signal}` : `exit code ${code}`; |
| 50 | reject(new Error(`Command failed (${reason}): ${command} ${args.join(' ')}`)); |
| 51 | } |
| 52 | }); |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | export async function ensureCliBuilt() { |
| 57 | if (existsSync(cliEntry)) { |