UNPKG

@moonsong-labs/moonwall-cli

Version:

Testing framework for the Moon family of projects

51 lines (49 loc) 1.21 kB
// src/internal/runner.ts import child_process from "child_process"; import { promisify } from "node:util"; import Debug from "debug"; var debug = Debug("actions:runner"); var execAsync = promisify(child_process.exec); async function runTask(cmd, { cwd, env } = { cwd: process.cwd() }, title) { debug(`${title ? `Title: ${title} ` : ""}Running task on directory ${cwd}: ${cmd} `); try { const result = await execAsync(cmd, { cwd, env }); return result.stdout; } catch (error) { console.log(error); debug(`Caught exception in command execution. Error[${error.status}] ${error.message} `); throw error; } } async function spawnTask(cmd, { cwd, env } = { cwd: process.cwd() }, title) { debug(`${title ? `Title: ${title} ` : ""}Running task on directory ${process.cwd()}: ${cmd} `); try { const process2 = child_process.spawn( cmd.split(" ")[0], cmd.split(" ").slice(1).filter((a) => a.length > 0), { cwd, env } ); return process2; } catch (error) { console.log(error); debug(`Caught exception in command execution. Error[${error.status}] ${error.message} `); throw error; } } export { runTask, spawnTask };