Commit 6bc56631521153ffff2d6e79bbe0fee1806f76b6

Authored by Adhidarma Hadiwinoto
1 parent 983e087eb8
Exists in master

config-reload

Showing 1 changed file with 31 additions and 0 deletions Side-by-side Diff

... ... @@ -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;