turbo-gulp
Version:
Gulp tasks to boost high-quality projects.
33 lines (32 loc) • 1.2 kB
JavaScript
import { Incident } from "incident";
import { SpawnedProcess } from "./node-async";
const nycBin = require.resolve("nyc/bin/nyc.js");
export async function execNyc(cmd, args = [], options) {
return new SpawnedProcess(nycBin, cmd === null ? args : [cmd, ...args], Object.assign({ stdio: "pipe" }, options)).toPromise();
}
export async function report(options) {
const args = ["--reporter", "lcov"];
args.push("--temp-directory", options.tempDirectory);
await execNyc("report", args);
}
export async function run(options) {
const args = [];
args.push("--cwd", options.cwd);
for (const reporter of options.reporters) {
args.push("--reporter", reporter);
}
args.push("--report-dir", options.reportDir);
args.push("--temp-dir", options.tempDir);
if (options.colors) {
args.push("--color");
}
args.push("--", ...options.command);
const result = await execNyc(null, args, { cwd: options.cwd, stdio: "inherit" });
if (result.exit.type === "code") {
if (result.exit.code === 0) {
return;
}
throw Incident("CoverageError");
}
throw new Incident("UnexpectedExitValue", { exit: result.exit });
}