UNPKG

pandora

Version:
56 lines 2.21 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = require("path"); const extend = require("extend"); /** * Class DefaultConfigurator */ class DefaultConfigurator { constructor(context) { this.configPlace = './config'; this.resolvedConfig = null; this.context = context; } getAllProperties(options = { force: false }) { return __awaiter(this, void 0, void 0, function* () { if (!this.resolvedConfig || options.force) { const appDir = this.context.appDir; const configDir = path_1.join(appDir, this.configPlace); const env = this.context.env; this.resolvedConfig = this.loadConfigByFile(configDir, env); } return this.resolvedConfig; }); } loadConfigByFile(loadDir, env) { const configFiles = [ './config', './config.default', `./config.${env}` ]; let config = {}; for (const fileName of configFiles) { try { const target = path_1.join(loadDir, fileName); let mod = require(target); mod = mod.default || mod; const extendConfig = 'function' === typeof mod ? mod(this.context) : mod; config = extend(true, config, extendConfig); } catch (err) { // Ignore } } return config; } } exports.DefaultConfigurator = DefaultConfigurator; //# sourceMappingURL=DefaultConfigurator.js.map