curli-config
Version:
A small library to load/validate configuration files placed in different sides of the application using environments
33 lines (32 loc) • 1.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const LoaderConfigsFile_1 = require("./LoaderConfigsFile");
const LoaderConfigsFilesGroup_1 = require("./LoaderConfigsFilesGroup");
class LoaderConfigsFileFactory {
constructor(settings) {
this.settings = settings;
this.defaultFileName = this.settings.DEFAULT_FILE_NAME;
this.fileExtencion = this.settings.FILE_NAME_EXTENSION;
this.environment = this.settings.getEnvironment();
this.forceValidateSchemas = this.settings.getForceValidateSchemas();
}
factory() {
const filesPathsCollection = this.settings.getFilesPaths().getPaths();
const arrayLoaderConfigsGroups = [];
filesPathsCollection.forEach((filesPathModel) => {
arrayLoaderConfigsGroups.push(this.buildLoaderConfigsFilesGroup(filesPathModel));
});
return arrayLoaderConfigsGroups;
}
buildLoaderConfigsFilesGroup(filesPathModel) {
const path = filesPathModel.getPath();
const group = new LoaderConfigsFilesGroup_1.LoaderConfigsFilesGroup(path, this.forceValidateSchemas);
group.add(new LoaderConfigsFile_1.LoaderConfigsFile(this.getFullFileNameByPath(path, this.defaultFileName)));
group.add(new LoaderConfigsFile_1.LoaderConfigsFile(this.getFullFileNameByPath(path, this.environment)));
return group;
}
getFullFileNameByPath(path, fileName) {
return path + '/' + fileName + this.fileExtencion;
}
}
exports.LoaderConfigsFileFactory = LoaderConfigsFileFactory;