Compare View
Commits (2)
Changes
Showing 2 changed files Side-by-side Diff
config-reload.js
... | ... | @@ -0,0 +1,31 @@ |
1 | +"use strict"; | |
2 | + | |
3 | +const config = require('./config'); | |
4 | +const logger = require('./logger'); | |
5 | + | |
6 | +function replace(new_config) { | |
7 | + for (let key in new_config) { | |
8 | + config[key] = new_config[key]; | |
9 | + } | |
10 | + | |
11 | + _removeIfNotExists(new_config); | |
12 | +} | |
13 | + | |
14 | +function reload() { | |
15 | + const configFile = process.cwd() + "/config.json"; | |
16 | + const new_config = require(configFile); | |
17 | + | |
18 | + replace(new_config); | |
19 | +} | |
20 | + | |
21 | +function _removeIfNotExists(new_config) { | |
22 | + for (let key in config) { | |
23 | + if (!new_config[key]) { | |
24 | + logger.verbose('Removing old config key: ' + key); | |
25 | + del config[key]; | |
26 | + } | |
27 | + } | |
28 | +} | |
29 | + | |
30 | +exports.replace = replace; | |
31 | +exports.reload = reload; |