UNPKG

jsev

Version:

Environment for building Web API's.

41 lines 1.54 kB
"use strict"; // Use console logging in here because we need to load the configuration before the logging module is usable var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); const path_1 = require("path"); async function importConfiguration(cfgPath, cfgFile) { const path = path_1.join(cfgPath, cfgFile); try { const cfg = await Promise.resolve().then(() => __importStar(require(path))); return cfg; } catch (err) { if (err.code !== "MODULE_NOT_FOUND") { throw err; } console.warn(`Configuration ${cfgFile} not found`); // tslint:disable-line:no-console } } async function loadConfiguration(cfgPath) { const env = process.env.NODE_ENV; const defaultCfg = { env, name: process.env.name || "app", port: 8080, }; const cfgs = [await importConfiguration(cfgPath, "config.js")]; if (env) { const envCfgName = `config.${env}.js`; cfgs.push(await importConfiguration(cfgPath, envCfgName)); } return lodash_1.merge(defaultCfg, ...cfgs.filter((x) => x).map((x) => (x.default ? x.default : x))); } exports.loadConfiguration = loadConfiguration; //# sourceMappingURL=index.js.map