declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
52 lines • 2.96 kB
JavaScript
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.apply = void 0;
const domain_1 = require("../../domain");
const applyPlans_1 = require("../usage/plan/apply/applyPlans");
const filterPracticeEvaluationsFromPlans_1 = require("../usage/plan/filterPracticeEvaluationsFromPlans");
const getPlansForProject_1 = require("../usage/plan/getPlansForProject");
const readUsePracticesConfig_1 = require("../usage/readUsePracticesConfig");
const getScopedPractices_1 = require("./getScopedPractices");
const apply = (_a) => __awaiter(void 0, [_a], void 0, function* ({ usePracticesConfigPath, filter, }) {
var _b, _c;
// read the usage config
console.log('🔎 reading configs and declarations...'); // tslint:disable-line: no-console
const config = yield (0, readUsePracticesConfig_1.readUsePracticesConfig)({
configPath: usePracticesConfigPath,
});
// grab the desired practices
const practices = (0, getScopedPractices_1.getDesiredPractices)({ config, filter });
// get plans for this project
console.log('🔬️ evaluating project...'); // tslint:disable-line: no-console
const plans = yield (0, getPlansForProject_1.getPlansForProject)({
practices,
projectRootDirectory: config.rootDir,
projectVariables: config.variables,
});
// filter out the practices to the ones that can be automatically applied + for the practices specified
const plansToApply = (yield (0, filterPracticeEvaluationsFromPlans_1.filterPracticeEvaluationsFromPlans)({
plans,
filter: {
byFixable: true,
byPracticeNames: (_b = filter === null || filter === void 0 ? void 0 : filter.practiceNames) !== null && _b !== void 0 ? _b : undefined,
byFilePaths: (_c = filter === null || filter === void 0 ? void 0 : filter.filePaths) !== null && _c !== void 0 ? _c : undefined,
},
})).filter((plan) => plan.action === domain_1.RequiredAction.FIX_AUTOMATIC);
// display the plans
console.log('🔧 applying fixes...'); // tslint:disable-line: no-console
yield (0, applyPlans_1.applyPlans)({
plans: plansToApply,
projectRootDirectory: config.rootDir,
});
});
exports.apply = apply;
//# sourceMappingURL=apply.js.map
;