declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
41 lines • 2.08 kB
JavaScript
;
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', async ({ 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 = await (0, evaluateProjectAgainstPracticeDeclarations_1.evaluateProjectAgainstPracticeDeclarations)({
practices,
project,
});
// convert each file evaluation in to a plan per file
const evaluationsPerFile = evaluations.reduce((summary, thisEvaluation) => {
const currentState = summary[thisEvaluation.path] ?? []; // default to empty array
return {
...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