UNPKG

@eklmv/jscpd-badge-reporter

Version:

Reporter for jscpd. Generate a badges with copy/paste level.

39 lines 1.21 kB
// src/index.ts import { badgen } from "badgen"; import { join } from "path"; import { ensureDirSync, writeFileSync } from "fs-extra"; import { green } from "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({ color: this.getColor(statistic), status: this.getStatus(statistic), subject: "Copy/Paste", ...badgeOptions }); const path = badgeOptions.path ? badgeOptions.path : join(this.options.output, "jscpd-badge.svg"); ensureDirSync(this.options.output); writeFileSync(path, badge); console.log(green(`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"; } }; export { BadgeReporter as default }; //# sourceMappingURL=index.mjs.map