diff --git a/core/config.js b/core/config.js index 927d7bbf..791845b8 100644 --- a/core/config.js +++ b/core/config.js @@ -37,6 +37,12 @@ exports.Config = class Config extends ConfigLoader { } } }, + onReload : err => { + if (!err) { + const Events = require('./events.js'); + Events.emit(Events.getSystemEvents().ConfigChanged); + } + }, }; systemConfigInstance = new Config(options); diff --git a/core/config_loader.js b/core/config_loader.js index c922cddd..f8f3fe71 100644 --- a/core/config_loader.js +++ b/core/config_loader.js @@ -8,13 +8,26 @@ const mapValuesDeep = require('deepdash/getMapValuesDeep')(_); module.exports = class ConfigLoader { constructor( - { hotReload = true, defaultConfig = {}, defaultsCustomizer = null } = { hotReload : true, defaultConfig : {}, defaultsCustomizer : null } ) + { + hotReload = true, + defaultConfig = {}, + defaultsCustomizer = null, + onReload = null, + } = + { + hotReload : true, + defaultConfig : {}, + defaultsCustomizer : null, + onReload : null, + } + ) { this.current = {}; this.hotReload = hotReload; this.defaultConfig = defaultConfig; this.defaultsCustomizer = defaultsCustomizer; + this.onReload = onReload; } init(baseConfigPath, cb) { @@ -135,10 +148,6 @@ module.exports = class ConfigLoader { } } break; - - case 'regex' : - // :TODO: What flags to use, etc.? - break; } return value; @@ -182,9 +191,8 @@ module.exports = class ConfigLoader { const reCachedPath = paths.join(fileRoot, fileName); if (this.configPaths.includes(reCachedPath)) { this._reload(this.baseConfigPath, err => { - if (!err) { - const Events = require('./events.js'); - Events.emit(Events.getSystemEvents().ConfigChanged); + if (_.isFunction(this.onReload)) { + this.onReload(err, reCachedPath); } }); }