UNPKG

@decaf-ts/utils

Version:

module management utils for decaf-ts

28 lines 1.51 kB
import { StandardOutputWriter } from "./../writers/index.js"; import { runCommand } from "./../utils/utils.js"; import { sf } from "@decaf-ts/logging"; import { style } from "styled-string-builder"; export function runAndReport(command, opts = {}, outputConstructor = (StandardOutputWriter), reporter, commandPrefix = "{cwd} $ ", ...args) { try { const cmd = runCommand(command, opts, outputConstructor, ...args); const p = cmd.promise; const resolution = async (resolve, result) => { await reporter.reportData(`${expect.getState().currentTestName || "no test name"} - ${command}`, `${sf(commandPrefix, { cwd: opts.cwd || process.cwd() })}${command}\n${style("SUCCESS").green.bold}\n${result}`, "text", true); resolve(result); }; const rejection = async (reject, error) => { await reporter.reportData(`${expect.getState().currentTestName || "no test name"} - ${command}`, `${sf(commandPrefix, { cwd: opts.cwd || process.cwd() })}${command}\n${style("FAIL").red.bold}\n${error}`, "text", true); reject(error); }; cmd.promise = new Promise((resolve, reject) => { return p .then(async (r) => await resolution(resolve, r)) .catch(async (e) => await rejection(reject, e)); }); return cmd; } catch (e) { throw new Error(`Unable to create reportable command runner for ${commandPrefix}: ${e}`); } } //# sourceMappingURL=utils.js.map