(commands: string[] = [])
| 3 | import logger from '../../logger' |
| 4 | |
| 5 | const runCommands = async (commands: string[] = []): Promise<void> => { |
| 6 | if (!commands.length) { |
| 7 | return |
| 8 | } |
| 9 | for (const command of commands) { |
| 10 | const process = { |
| 11 | title: command, |
| 12 | description: 'Running process...', |
| 13 | } |
| 14 | logger(`Command: ${command}`) |
| 15 | send({ type: 'COMMAND_START', payload: { process: { ...process, status: 'RUNNING' } } }) |
| 16 | let result: { stdout: string; stderr: string } |
| 17 | try { |
| 18 | result = await exec({ command }) |
| 19 | if (result.stderr) { |
| 20 | throw new Error(result.stderr) |
| 21 | } |
| 22 | logger(`Command output: ${result.stdout}`) |
| 23 | } catch (error: any) { |
| 24 | logger(`Command failed: ${error.message}`) |
| 25 | send({ type: 'COMMAND_FAIL', payload: { process: { ...process, status: 'FAIL' } } }) |
| 26 | return |
| 27 | } |
| 28 | send({ type: 'COMMAND_SUCCESS', payload: { process: { ...process, status: 'SUCCESS' } } }) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | export default runCommands |
no test coverage detected