UNPKG

declapract

Version:

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

61 lines 3.47 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.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 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ configPath, }) { const configDir = (0, getDirOfPath_1.getDirOfPath)(configPath); const getAbsolutePathFromRelativeToConfigPath = (relpath) => `${configDir}/${relpath}`; // get the yml const contents = yield (() => __awaiter(void 0, void 0, void 0, function* () { try { return yield (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 = yield (0, readPracticeDeclarations_1.readPracticeDeclarations)({ declaredPracticesDirectory: getAbsolutePathFromRelativeToConfigPath(configInput.declare.practices), }); // define the examples based on the input const examples = configInput.declare.examples ? yield (0, readExampleDeclarations_1.readExampleDeclarations)({ declarationsRootDirectory: configDir, declaredExamplesDirectory: getAbsolutePathFromRelativeToConfigPath(configInput.declare.examples), }) : []; // define the use cases based on the input const useCases = yield (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