@decaf-ts/utils
Version:
module management utils for decaf-ts
31 lines • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runAndReport = runAndReport;
const writers_1 = require("./../writers/index.cjs");
const utils_1 = require("./../utils/utils.cjs");
const logging_1 = require("@decaf-ts/logging");
const styled_string_builder_1 = require("styled-string-builder");
function runAndReport(command, opts = {}, outputConstructor = (writers_1.StandardOutputWriter), reporter, commandPrefix = "{cwd} $ ", ...args) {
try {
const cmd = (0, utils_1.runCommand)(command, opts, outputConstructor, ...args);
const p = cmd.promise;
const resolution = async (resolve, result) => {
await reporter.reportData(`${expect.getState().currentTestName || "no test name"} - ${command}`, `${(0, logging_1.sf)(commandPrefix, { cwd: opts.cwd || process.cwd() })}${command}\n${(0, styled_string_builder_1.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}`, `${(0, logging_1.sf)(commandPrefix, { cwd: opts.cwd || process.cwd() })}${command}\n${(0, styled_string_builder_1.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