UNPKG

declapract

Version:

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

48 lines 2.85 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPlansForProject = void 0; const domain_1 = require("../../../domain"); const ProjectCheckContext_1 = require("../../../domain/objects/ProjectCheckContext"); const withDurationReporting_1 = require("../../../utils/wrappers/withDurationReporting"); const evaluateProjectAgainstPracticeDeclarations_1 = require("../evaluate/evaluateProjectAgainstPracticeDeclarations"); const getRequiredActionForFile_1 = require("./getRequiredActionForFile"); /** * get the plans required to make a project follow the declared practices */ exports.getPlansForProject = (0, withDurationReporting_1.withDurationReporting)('getPlansForProject', (_a) => __awaiter(void 0, [_a], void 0, function* ({ practices, projectRootDirectory, projectVariables, }) { // define the project context const project = new ProjectCheckContext_1.ProjectCheckContext({ projectVariables, projectPractices: practices.map((practice) => practice.name), getProjectRootDirectory: () => projectRootDirectory, }); // evaluate the project against the practices const evaluations = yield (0, evaluateProjectAgainstPracticeDeclarations_1.evaluateProjectAgainstPracticeDeclarations)({ practices, project, }); // convert each file evaluation in to a plan per file const evaluationsPerFile = evaluations.reduce((summary, thisEvaluation) => { var _a; const currentState = (_a = summary[thisEvaluation.path]) !== null && _a !== void 0 ? _a : []; // default to empty array return Object.assign(Object.assign({}, summary), { [thisEvaluation.path]: [...currentState, thisEvaluation] }); // append this evaluation }, {}); // compose evaluations into plans const plans = Object.entries(evaluationsPerFile).map(([path, evaluationsForFile]) => new domain_1.FileActionPlan({ path, evaluations: evaluationsForFile, action: (0, getRequiredActionForFile_1.getRequiredActionForFile)({ evaluations: evaluationsForFile }), })); // return the plans return plans; })); //# sourceMappingURL=getPlansForProject.js.map