@eklmv/jscpd-badge-reporter
Version:
Reporter for jscpd. Generate a badges with copy/paste level.
39 lines (37 loc) • 1.36 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts
var _badgen = require('badgen');
var _path = require('path');
var _fsextra = require('fs-extra');
var _safe = require('colors/safe');
var BadgeReporter = class {
constructor(options) {
this.options = options;
}
// @ts-ignore
report(clones, statistic) {
const badgeOptions = this.options.reportersOptions ? this.options.reportersOptions.badge || {} : {};
if (this.options.output) {
const badge = _badgen.badgen.call(void 0, {
color: this.getColor(statistic),
status: this.getStatus(statistic),
subject: "Copy/Paste",
...badgeOptions
});
const path = badgeOptions.path ? badgeOptions.path : _path.join.call(void 0, this.options.output, "jscpd-badge.svg");
_fsextra.ensureDirSync.call(void 0, this.options.output);
_fsextra.writeFileSync.call(void 0, path, badge);
console.log(_safe.green.call(void 0, `Badge saved to ${path}`));
}
}
getStatus(statistic) {
return statistic ? statistic.total.percentage + "%" : "N/A";
}
getColor(statistic) {
if (this.options.threshold === void 0) {
return "grey";
}
return statistic.total.percentage < this.options.threshold ? "green" : "red";
}
};
exports.default = BadgeReporter;
//# sourceMappingURL=index.js.map