UNPKG

declapract

Version:

A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.

62 lines 3.5 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _a; 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 = ((_a = process.env.SKIP_BROKEN) === null || _a === void 0 ? void 0 : _a.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 = (_b) => __awaiter(void 0, [_b], void 0, function* ({ practices, project, }) { return (yield 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