UNPKG

@allgemein/moduls

Version:

Commons-moduls handles and manages contextual moduls for complex and modular applications.

41 lines 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SettingsLoader = void 0; const lodash_1 = require("lodash"); const AbstractModuleLoader_1 = require("../AbstractModuleLoader"); const SettingsHandle_1 = require("./SettingsHandle"); const Helper_1 = require("../../utils/Helper"); const base_1 = require("@allgemein/base"); class SettingsLoader extends AbstractModuleLoader_1.AbstractModuleLoader { getSettings() { let settings = {}; for (let x of this.handles()) { settings[x.module.name] = x.settings; } return settings; } async loadOne(modul) { let handle = null; let filepath = base_1.PlatformUtils.join(modul.path, this._options.ref); let ext = base_1.PlatformUtils.pathExtname(filepath, false); if (base_1.PlatformUtils.fileExist(filepath)) { handle = new SettingsHandle_1.SettingsHandle(modul); let file = await Helper_1.Helper.readFile(filepath); let settings = {}; switch (ext) { case 'json': settings = JSON.parse(file.toString('utf8')); break; default: throw new Error('Cannot load settings from ' + ext); } if (this._options.path) { settings = (0, lodash_1.get)(settings, this._options.path); } handle.settings = settings; } return handle; } } exports.SettingsLoader = SettingsLoader; //# sourceMappingURL=SettingsLoader.js.map