UNPKG

openhim-mediator-shell-script

Version:
96 lines (80 loc) 2.32 kB
var conf, confFile, fs, load, mediatorConf, ops, path, stdio, updateConf; fs = require('fs'); path = require('path'); stdio = require('stdio'); conf = {}; mediatorConf = {}; if (process.env.NODE_ENV !== 'test') { ops = stdio.getopt({ conf: { key: 'c', args: 1, description: 'The backend configuration to use. See config/default.json for an example.' }, mediatorConf: { key: 'm', args: 1, description: 'The mediator configuration to use. See config/mediator.json for an example.' } }); } confFile = null; updateConf = function(config) { var _confI, _spl, i, key, param, results; results = []; for (param in config) { _spl = param.split('-'); _confI = conf; results.push((function() { var j, len, results1; results1 = []; for (i = j = 0, len = _spl.length; j < len; i = ++j) { key = _spl[i]; if (i === _spl.length - 1) { results1.push(_confI[key] = config[param]); } else { if (!_confI[key]) { _confI[key] = {}; } results1.push(_confI = _confI[key]); } } return results1; })()); } return results; }; load = function() { var mediatorConfFile; if ((ops != null ? ops.conf : void 0) != null) { confFile = ops.conf; } else if (process.env.NODE_ENV === 'development') { confFile = path.resolve(global.appRoot + "/config", 'development.json'); } else if (process.env.NODE_ENV === 'test') { confFile = path.resolve(global.appRoot + "/config", 'test.json'); } else { confFile = path.resolve(global.appRoot + "/config", 'default.json'); } conf = JSON.parse(fs.readFileSync(confFile)); if ((ops != null ? ops.mediatorConf : void 0) != null) { mediatorConfFile = ops.mediatorConf; } else { mediatorConfFile = path.resolve(global.appRoot + "/config", 'mediator.json'); } mediatorConf = JSON.parse(fs.readFileSync(mediatorConfFile)); if (mediatorConf.config != null) { return updateConf(mediatorConf.config); } }; exports.getConf = function() { return conf; }; exports.getConfName = function() { return confFile; }; exports.getMediatorConf = function() { return mediatorConf; }; exports.load = load; exports.updateConf = updateConf; //# sourceMappingURL=config.js.map