UNPKG

declapract

Version:

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

33 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readPracticeDeclarations = void 0; const domain_1 = require("../../../domain"); const listPathsInDirectory_1 = require("../../../utils/filepaths/listPathsInDirectory"); const UserInputError_1 = require("../../UserInputError"); const readPracticeDeclaration_1 = require("./readPracticeDeclaration/readPracticeDeclaration"); const readPracticeDeclarations = async ({ declaredPracticesDirectory, }) => { const practiceDirectories = await (0, listPathsInDirectory_1.listPathsInDirectory)({ directory: declaredPracticesDirectory, }); if (!practiceDirectories.length) throw new UserInputError_1.UserInputError(`at least one practice needs to be defined in the practices directory: '${declaredPracticesDirectory}'`); const practicesOrErrors = await Promise.all(practiceDirectories.map((directory) => (0, readPracticeDeclaration_1.readPracticeDeclaration)({ declaredPracticeDirectory: `${declaredPracticesDirectory}/${directory}`, }).catch((error) => { console.error(error); console.warn('experienced an error while attempting to readPracticeDeclaration ', { declaredPracticeDirectory: `${declaredPracticesDirectory}/${directory}`, }); return error; }))); // check if there were any errors const errors = practicesOrErrors.filter((practiceOrError) => practiceOrError instanceof Error); // if we experienced any errors, throw the last one as an example to help them debug if (errors.length) throw errors[0]; // return the practices const practices = practicesOrErrors.filter((practiceOrError) => practiceOrError instanceof domain_1.PracticeDeclaration); return practices; }; exports.readPracticeDeclarations = readPracticeDeclarations; //# sourceMappingURL=readPracticeDeclarations.js.map