support js files besides json files

This commit is contained in:
Iuri Matias 2018-05-11 18:10:48 -04:00
parent bd0e4a9960
commit 8b22305833
1 changed files with 12 additions and 7 deletions

View File

@ -75,7 +75,7 @@ Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, ena
return configToReturn; return configToReturn;
} }
if (!fs.existsSync(configFilePath)) { if (!fs.existsSync(configFilePath + '.js') && !fs.existsSync(configFilePath + ' .json')) {
// TODO: remove this if // TODO: remove this if
if (this.logger) { if (this.logger) {
this.logger.warn(__("no config file found at %s using default config", configFilePath)); this.logger.warn(__("no config file found at %s using default config", configFilePath));
@ -83,7 +83,12 @@ Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, ena
return defaultConfig['default'] || {}; return defaultConfig['default'] || {};
} }
let config = fs.readJSONSync(configFilePath); let config;
if (fs.existsSync(configFilePath + '.js')) {
config = require(fs.dappPath(configFilePath + '.js'));
} else {
config = fs.readJSONSync(configFilePath);
}
let configObject = utils.recursiveMerge(defaultConfig, config); let configObject = utils.recursiveMerge(defaultConfig, config);
if (env) { if (env) {
@ -109,7 +114,7 @@ Config.prototype.loadBlockchainConfigFile = function() {
} }
}; };
let configFilePath = this._getFileOrOject(this.configDir, 'blockchain.json', 'blockchain'); let configFilePath = this._getFileOrOject(this.configDir, 'blockchain', 'blockchain');
this.blockchainConfig = this._mergeConfig(configFilePath, configObject, this.env, true); this.blockchainConfig = this._mergeConfig(configFilePath, configObject, this.env, true);
}; };
@ -142,7 +147,7 @@ Config.prototype.loadContractsConfigFile = function() {
configObject = utils.recursiveMerge(configObject, pluginConfig); configObject = utils.recursiveMerge(configObject, pluginConfig);
}); });
let configFilePath = this._getFileOrOject(this.configDir, 'contracts.json', 'contracts'); let configFilePath = this._getFileOrOject(this.configDir, 'contracts', 'contracts');
const newContractsConfig = this._mergeConfig(configFilePath, configObject, this.env); const newContractsConfig = this._mergeConfig(configFilePath, configObject, this.env);
@ -193,7 +198,7 @@ Config.prototype.loadStorageConfigFile = function() {
} }
}; };
let configFilePath = this._getFileOrOject(this.configDir, 'storage.json', 'storage'); let configFilePath = this._getFileOrOject(this.configDir, 'storage', 'storage');
this.storageConfig = this._mergeConfig(configFilePath, configObject, this.env); this.storageConfig = this._mergeConfig(configFilePath, configObject, this.env);
}; };
@ -210,7 +215,7 @@ Config.prototype.loadCommunicationConfigFile = function() {
} }
}; };
let configFilePath = this._getFileOrOject(this.configDir, 'communication.json', 'communication'); let configFilePath = this._getFileOrOject(this.configDir, 'communication', 'communication');
this.communicationConfig = this._mergeConfig(configFilePath, configObject, this.env); this.communicationConfig = this._mergeConfig(configFilePath, configObject, this.env);
}; };
@ -220,7 +225,7 @@ Config.prototype.loadWebServerConfigFile = function() {
"enabled": true, "host": "localhost", "port": 8000 "enabled": true, "host": "localhost", "port": 8000
}; };
let configFilePath = this._getFileOrOject(this.configDir, 'webserver.json', 'webserver'); let configFilePath = this._getFileOrOject(this.configDir, 'webserver', 'webserver');
this.webServerConfig = this._mergeConfig(configFilePath, configObject, false); this.webServerConfig = this._mergeConfig(configFilePath, configObject, false);
}; };