UNPKG

declapract

Version:

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

52 lines 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readDeclarePracticesConfig = void 0; const ActionDeclarePracticesConfigInput_1 = require("../../domain/objects/ActionDeclarePracticesConfigInput"); const DeclaredPractices_1 = require("../../domain/objects/DeclaredPractices"); const readYmlFile_1 = require("../../utils/fileio/readYmlFile"); const getDirOfPath_1 = require("../../utils/filepaths/getDirOfPath"); const UserInputError_1 = require("../UserInputError"); const readExampleDeclarations_1 = require("./readPracticeDeclarations/readExampleDeclarations"); const readPracticeDeclarations_1 = require("./readPracticeDeclarations/readPracticeDeclarations"); const readUseCaseDeclarations_1 = require("./readPracticeDeclarations/readUseCaseDeclarations"); const readDeclarePracticesConfig = async ({ configPath, }) => { const configDir = (0, getDirOfPath_1.getDirOfPath)(configPath); const getAbsolutePathFromRelativeToConfigPath = (relpath) => `${configDir}/${relpath}`; // get the yml const contents = await (async () => { try { return await (0, readYmlFile_1.readYmlFile)({ filePath: configPath }); } catch (error) { throw new UserInputError_1.UserInputError(`could not read config. ${error.message}. See '${configPath}'`); } })(); // validate it into an input object const configInput = new ActionDeclarePracticesConfigInput_1.ActionDeclarePracticesConfigInput(contents); // applies runtime validation // define the practices based on the input const practices = await (0, readPracticeDeclarations_1.readPracticeDeclarations)({ declaredPracticesDirectory: getAbsolutePathFromRelativeToConfigPath(configInput.declare.practices), }); // define the examples based on the input const examples = configInput.declare.examples ? await (0, readExampleDeclarations_1.readExampleDeclarations)({ declarationsRootDirectory: configDir, declaredExamplesDirectory: getAbsolutePathFromRelativeToConfigPath(configInput.declare.examples), }) : []; // define the use cases based on the input const useCases = await (0, readUseCaseDeclarations_1.readUseCaseDeclarations)({ declaredUseCasesPath: getAbsolutePathFromRelativeToConfigPath(configInput.declare['use-cases']), practices, examples, }); // return the config return new DeclaredPractices_1.DeclaredPractices({ rootDir: configDir, practices, useCases, examples, }); }; exports.readDeclarePracticesConfig = readDeclarePracticesConfig; //# sourceMappingURL=readDeclarePracticesConfig.js.map