| 17 | ]; |
| 18 | |
| 19 | function runCommand( |
| 20 | file: string, |
| 21 | args: string[], |
| 22 | cwd: string, |
| 23 | log: string[], |
| 24 | ): Promise<void> { |
| 25 | const command = [file, ...args].join(" "); |
| 26 | log.push(`Running: ${command} in ${cwd}`); |
| 27 | return new Promise((resolve, reject) => { |
| 28 | subprocess.execFile( |
| 29 | file, |
| 30 | args, |
| 31 | { cwd, encoding: "utf-8", maxBuffer: 64 * 1024 * 1024 }, |
| 32 | (error, stdout, stderr) => { |
| 33 | if (stdout) log.push(stdout); |
| 34 | if (stderr) log.push(stderr); |
| 35 | if (error) { |
| 36 | log.push(`✗ Failed: ${command} in ${cwd}`); |
| 37 | reject(error); |
| 38 | } else { |
| 39 | log.push(`✓ Success: ${command}`); |
| 40 | resolve(); |
| 41 | } |
| 42 | }, |
| 43 | ); |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | // Templates deploy in parallel, so each one's output is buffered and printed |
| 48 | // as a single block when it finishes. |