(
command: string,
dispatcher: TaskEventDispatcher = () => { },
options: Options = {},
cb?: (process: ExecaChildProcess) => void
)
| 3 | import { getSystemPath, getSystemProxy } from "./env"; |
| 4 | |
| 5 | export async function runCommand( |
| 6 | command: string, |
| 7 | dispatcher: TaskEventDispatcher = () => { }, |
| 8 | options: Options = {}, |
| 9 | cb?: (process: ExecaChildProcess) => void |
| 10 | ): Promise<{ |
| 11 | stderr: string, |
| 12 | exitCode: number, |
| 13 | stdout: string, |
| 14 | }> { |
| 15 | const { systemProxy, systemProxyString } = await getSystemProxy(); |
| 16 | if (systemProxy) { |
| 17 | logger.info("run command with proxy:" + command + " " + systemProxyString); |
| 18 | } else { |
| 19 | logger.info("run command without proxy") |
| 20 | } |
| 21 | const SHELL_ENV_PATH = getSystemPath({ |
| 22 | CONDA_SCRIPTS_PATH: conda.info?.CONDA_SCRIPTS_PATH || "", |
| 23 | CONDA_ENV_PATH: conda.env?.CONDA_ENV_PATH || "" |
| 24 | }); |
| 25 | const subProcess = execaCommand(command, { |
| 26 | env: { |
| 27 | ...process.env, |
| 28 | PATH: SHELL_ENV_PATH, |
| 29 | ...systemProxy, |
| 30 | }, |
| 31 | // shell: isMac ? "/bin/zsh" : true, |
| 32 | ...options |
| 33 | }); |
| 34 | |
| 35 | cb && cb(subProcess); |
| 36 | |
| 37 | subProcess.stdout?.on('data', (chunk) => { |
| 38 | logger.info("out", chunk.toString()); |
| 39 | dispatcher && dispatcher({ |
| 40 | message: chunk.toString() |
| 41 | }) |
| 42 | }); |
| 43 | |
| 44 | subProcess.stderr?.on('data', (chunk) => { |
| 45 | logger.error(`run command "${command}" error: ${chunk.toString()}`); |
| 46 | dispatcher && dispatcher({ |
| 47 | message: chunk.toString() |
| 48 | }) |
| 49 | }); |
| 50 | |
| 51 | const { exitCode, stderr, stdout } = await subProcess; |
| 52 | |
| 53 | dispatcher && dispatcher({ |
| 54 | data: { |
| 55 | exitCode, |
| 56 | stderr, |
| 57 | stdout, |
| 58 | }, |
| 59 | message: stderr + stdout |
| 60 | }); |
| 61 | |
| 62 | if (exitCode !== 0) { |
no test coverage detected