declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
42 lines • 2.62 kB
JavaScript
;
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.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 = (_a) => __awaiter(void 0, [_a], void 0, function* ({ declaredPracticesDirectory, }) {
const practiceDirectories = yield (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 = yield 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