(
command: string,
args: string[],
{
allowFailure = false,
}: {
allowFailure?: boolean;
} = {},
)
| 1004 | } |
| 1005 | |
| 1006 | async function runCommand( |
| 1007 | command: string, |
| 1008 | args: string[], |
| 1009 | { |
| 1010 | allowFailure = false, |
| 1011 | }: { |
| 1012 | allowFailure?: boolean; |
| 1013 | } = {}, |
| 1014 | ): Promise<void> { |
| 1015 | await new Promise<void>((resolve, reject) => { |
| 1016 | const child = spawn(command, args, { |
| 1017 | stdio: 'inherit', |
| 1018 | windowsHide: true, |
| 1019 | }); |
| 1020 | child.once('error', (error) => { |
| 1021 | if (allowFailure) { |
| 1022 | resolve(); |
| 1023 | return; |
| 1024 | } |
| 1025 | reject(error); |
| 1026 | }); |
| 1027 | child.once('exit', (code) => { |
| 1028 | if (!allowFailure && code !== 0) { |
| 1029 | reject(new Error(`Command failed (${command} ${args.join(' ')}): exit ${code}`)); |
| 1030 | return; |
| 1031 | } |
| 1032 | resolve(); |
| 1033 | }); |
| 1034 | }); |
| 1035 | } |
| 1036 | |
| 1037 | async function runPowerShellScript(script: string): Promise<void> { |
| 1038 | const powershell = process.platform === 'win32' ? 'powershell.exe' : 'powershell'; |
no test coverage detected