declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
52 lines • 2.73 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.evaluateProjectAgainstPracticeDeclarations = void 0;
const chalk_1 = __importDefault(require("chalk"));
const simple_leveled_log_methods_1 = require("simple-leveled-log-methods");
const type_fns_1 = require("type-fns");
const logger_1 = require("../../../utils/logger");
const withDurationReporting_1 = require("../../../utils/wrappers/withDurationReporting");
const evaluateProjectAgainstPracticeDeclaration_1 = require("./evaluateProjectAgainstPracticeDeclaration");
const SKIP_BROKEN = process.env.SKIP_BROKEN?.toLocaleLowerCase() === 'true'; // TODO: pass in an argument through the oclif cli args
const colorDurationInSeconds = (durationInSeconds) => {
const message = `${durationInSeconds} seconds`;
if (durationInSeconds < 3)
return chalk_1.default.gray(message);
if (durationInSeconds < 7)
return chalk_1.default.yellow(message);
return chalk_1.default.red(message);
};
/**
* given:
* - practice declarations
* - directory to project
*
* does:
* - check that the project conforms to the practices specified
*
* note: not checking against use case specifically because we may be asked to apply multiple use cases to the same project
*/
const evaluateProjectAgainstPracticeDeclarations = async ({ practices, project, }) => {
return (await Promise.all(practices.map((practice) => (0, withDurationReporting_1.withDurationReporting)(`practice:${practice.name}`, () => (0, evaluateProjectAgainstPracticeDeclaration_1.evaluteProjectAgainstPracticeDeclaration)({
practice,
project,
}).catch((error) => {
console.log(chalk_1.default.yellow(` ⚠️ broken practice:${practice.name}`)); // tslint:disable-line: no-console
console.log(chalk_1.default.yellow(` > ${error.message}`)); // tslint:disable-line: no-console
if (logger_1.ACTIVE_LOG_LEVEL === simple_leveled_log_methods_1.LOG_LEVEL.DEBUG)
console.error(error); // only show this if running in debug mode
if (SKIP_BROKEN !== true)
throw error;
return null;
}), {
reportingThresholdSeconds: 0.5,
log: ({ durationInSeconds }) => console.log(chalk_1.default.gray(` > took ${colorDurationInSeconds(durationInSeconds)}`)), // tslint:disable-line: no-console
})())))
.flat()
.filter(type_fns_1.isPresent);
};
exports.evaluateProjectAgainstPracticeDeclarations = evaluateProjectAgainstPracticeDeclarations;
//# sourceMappingURL=evaluateProjectAgainstPracticeDeclarations.js.map