( commandOrArgs: string | string[], captureOutput = false, )
| 18 | export function logAndExec(args: string[], captureOutput?: boolean): string; |
| 19 | export function logAndExec(command: string, captureOutput?: boolean): string; |
| 20 | export function logAndExec( |
| 21 | commandOrArgs: string | string[], |
| 22 | captureOutput = false, |
| 23 | ): string { |
| 24 | let command: string; |
| 25 | if (typeof commandOrArgs === "string") { |
| 26 | command = commandOrArgs; |
| 27 | } else { |
| 28 | command = [ |
| 29 | commandOrArgs[0], |
| 30 | // Quote each argument |
| 31 | ...commandOrArgs |
| 32 | .slice(1) |
| 33 | .map((arg) => |
| 34 | arg.startsWith("-") ? arg : `'${arg.replaceAll("'", "'\\''")}'`, |
| 35 | ), |
| 36 | ].join(" "); |
| 37 | } |
| 38 | |
| 39 | console.log(`$ ${command}`); |
| 40 | if (captureOutput) { |
| 41 | return cp.execSync(command, { stdio: "pipe", encoding: "utf-8" }).trim(); |
| 42 | } else { |
| 43 | cp.execSync(command, { stdio: "inherit" }); |
| 44 | return ""; |
| 45 | } |
| 46 | } |
no test coverage detected
searching dependent graphs…