Tidy up config, fix a couple minor bugs

This commit is contained in:
Bryan Ashby 2020-06-11 22:40:20 -06:00
parent 920684852c
commit fb9d83ab6f
No known key found for this signature in database
GPG key ID: B49EB437951D2542

View file

@ -1,6 +1,7 @@
// deps // deps
const paths = require('path'); const paths = require('path');
const async = require('async'); const async = require('async');
const moment = require('moment');
const _ = require('lodash'); const _ = require('lodash');
const mapValuesDeep = require('deepdash/getMapValuesDeep')(_); const mapValuesDeep = require('deepdash/getMapValuesDeep')(_);
@ -55,7 +56,7 @@ module.exports = class ConfigLoader {
config, config,
(defaultVal, configVal, key, target, source) => { (defaultVal, configVal, key, target, source) => {
var path; var path;
while (true) { while (true) { // eslint-disable-line no-constant-condition
if (!stack.length) { if (!stack.length) {
stack.push({source, path : []}); stack.push({source, path : []});
} }
@ -118,7 +119,9 @@ module.exports = class ConfigLoader {
case 'object' : case 'object' :
try { try {
value = JSON.parse(value); value = JSON.parse(value);
} catch(e) { } } catch(e) {
// ignored
}
break; break;
case 'date' : case 'date' :
@ -142,7 +145,7 @@ module.exports = class ConfigLoader {
} }
_resolveEnvironmentVariable(spec) { _resolveEnvironmentVariable(spec) {
const [prefix, varName, type, array] = spec.split(':'); const [, varName, type, array] = spec.split(':');
if (!varName) { if (!varName) {
return; return;
} }
@ -175,13 +178,8 @@ module.exports = class ConfigLoader {
}); });
} }
_configFileChanged({fileName, fileRoot, configCache}) { _configFileChanged({fileName, fileRoot}) {
const reCachedPath = paths.join(fileRoot, fileName); const reCachedPath = paths.join(fileRoot, fileName);
configCache.getConfig(reCachedPath, (err, config) => {
if (err) {
return console.stdout(`Configuration ${reCachedPath} is invalid: ${err.message}`); // eslint-disable-line no-console
}
if (this.configPaths.includes(reCachedPath)) { if (this.configPaths.includes(reCachedPath)) {
this._reload(this.baseConfigPath, err => { this._reload(this.baseConfigPath, err => {
if (!err) { if (!err) {
@ -190,7 +188,6 @@ module.exports = class ConfigLoader {
} }
}); });
} }
});
} }
_resolveIncludes(configRoot, config, cb) { _resolveIncludes(configRoot, config, cb) {