diffjam
Version:
cli for diffjam.com
66 lines (65 loc) • 3.57 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.logResults = exports.logAllResultDetails = exports.logPolicyResult = exports.logCheckFailedError = exports.GREEN_CHECK = exports.RED_X = void 0;
var chalk_1 = __importDefault(require("chalk"));
var lodash_1 = require("lodash");
exports.RED_X = "❌️";
exports.GREEN_CHECK = "✅";
var logCheckFailedError = function () {
console.error("\n".concat(exports.RED_X, " ").concat(chalk_1.default.red.bold("Check failed.")));
};
exports.logCheckFailedError = logCheckFailedError;
var logPolicyResult = function (result) {
if (!result.policy.isCountAcceptable(result.matches)) {
return console.error("".concat(exports.RED_X, " ").concat(chalk_1.default.red.bold(result.policy.name), ": ").concat(result.matches.length, " (expected ").concat(result.policy.baseline, " or fewer)"));
}
return console.log("".concat(exports.GREEN_CHECK, " ").concat(chalk_1.default.bold(result.policy.name), ": ").concat(result.matches.length));
};
exports.logPolicyResult = logPolicyResult;
var logBreachError = function (breach) {
console.error("".concat(exports.RED_X, " ").concat(chalk_1.default.red.bold(breach.policy.name), ": ").concat(breach.matches.length, " (expected ").concat(breach.policy.baseline, " or fewer)"));
var count = Math.min(10, breach.matches.length);
if (breach.matches.length > 10) {
console.error("First 10 examples:");
}
var examples = breach.matches.slice(0, count);
var longestFilePath = (0, lodash_1.maxBy)(examples, function (example) { return example.breachPath.length; }).breachPath.length;
var exampleLog = examples
.map(function (b) { return "".concat(chalk_1.default.magenta(b.breachPath)).concat(" ".repeat(longestFilePath - b.breachPath.length), " ").concat(b.startWholeLineFormatted); })
.join("\n");
console.log(exampleLog);
if (breach.policy.description) {
console.error(chalk_1.default.yellow(breach.policy.description));
}
};
var logAllResultDetails = function (result) {
console.log("".concat(chalk_1.default.yellow.bold(result.policy.name), " (found ").concat(result.matches.length, ", expecting ").concat(result.policy.baseline, " or fewer)"));
var matches = result.matches;
var longestFilePath = (0, lodash_1.maxBy)(matches, function (example) { return example.breachPath.length; }).breachPath.length;
var matchLog = matches
.map(function (b) { return "".concat(chalk_1.default.magenta(b.breachPath)).concat(" ".repeat(longestFilePath - b.breachPath.length), " ").concat(b.startWholeLineFormatted); })
.join("\n");
console.log(matchLog);
if (result.policy.description) {
console.error(chalk_1.default.yellow(result.policy.description));
}
};
exports.logAllResultDetails = logAllResultDetails;
var logResults = function (resultsMap, _filesChecked) {
var all = Object.values(resultsMap);
var _a = (0, lodash_1.partition)(all, function (_a) {
var policy = _a.policy, matches = _a.matches;
return policy.isCountAcceptable(matches);
}), successes = _a[0], breaches = _a[1];
breaches.forEach(logBreachError);
successes.forEach(function (s) {
if (!s.policy.hiddenFromOutput) {
(0, exports.logPolicyResult)(s);
}
});
return { breaches: breaches, successes: successes, all: all };
};
exports.logResults = logResults;