move merge to utils module

This commit is contained in:
Iuri Matias 2017-02-18 14:45:57 -05:00
parent 58b1f504d5
commit 86cd2a15d1
2 changed files with 20 additions and 13 deletions

View File

@ -1,5 +1,4 @@
var fs = require('fs'); var fs = require('fs');
var merge = require('merge');
var Plugins = require('./plugins.js'); var Plugins = require('./plugins.js');
var utils = require('./utils.js'); var utils = require('./utils.js');
@ -62,17 +61,17 @@ Config.prototype.loadContractsConfigFile = function() {
if (configPlugins.length > 0) { if (configPlugins.length > 0) {
configPlugins.forEach(function(plugin) { configPlugins.forEach(function(plugin) {
plugin.contractsConfigs.forEach(function(pluginConfig) { plugin.contractsConfigs.forEach(function(pluginConfig) {
configObject = merge.recursive(configObject, pluginConfig); configObject = utils.recursiveMerge(configObject, pluginConfig);
}); });
}); });
} }
var contractsConfig = JSON.parse(fs.readFileSync(this.configDir + "contracts.json")); var contractsConfig = JSON.parse(fs.readFileSync(this.configDir + "contracts.json"));
configObject = merge.recursive(configObject, contractsConfig); configObject = utils.recursiveMerge(configObject, contractsConfig);
var defaultContractsConfig = configObject['default']; var defaultContractsConfig = configObject['default'];
var envContractsConfig = configObject[this.env]; var envContractsConfig = configObject[this.env];
var mergedConfig = merge.recursive(defaultContractsConfig, envContractsConfig); var mergedConfig = utils.recursiveMerge(defaultContractsConfig, envContractsConfig);
this.contractsConfig = mergedConfig; this.contractsConfig = mergedConfig;
}; };
@ -84,17 +83,17 @@ Config.prototype.loadStorageConfigFile = function() {
//if (configPlugins.length > 0) { //if (configPlugins.length > 0) {
// configPlugins.forEach(function(plugin) { // configPlugins.forEach(function(plugin) {
// plugin.contractsConfigs.forEach(function(pluginConfig) { // plugin.contractsConfigs.forEach(function(pluginConfig) {
// configObject = merge.recursive(configObject, pluginConfig); // configObject = utils.recursiveMerge(configObject, pluginConfig);
// }); // });
// }); // });
//} //}
var storageConfig = JSON.parse(fs.readFileSync(this.configDir + "storage.json")); var storageConfig = JSON.parse(fs.readFileSync(this.configDir + "storage.json"));
configObject = merge.recursive(configObject, storageConfig); configObject = utils.recursiveMerge(configObject, storageConfig);
var defaultStorageConfig = configObject['default']; var defaultStorageConfig = configObject['default'];
var envStorageConfig = configObject[this.env]; var envStorageConfig = configObject[this.env];
var mergedConfig = merge.recursive(defaultStorageConfig, envStorageConfig); var mergedConfig = utils.recursiveMerge(defaultStorageConfig, envStorageConfig);
this.storageConfig = mergedConfig; this.storageConfig = mergedConfig;
}; };
@ -105,17 +104,17 @@ Config.prototype.loadCommunicationConfigFile = function() {
//if (configPlugins.length > 0) { //if (configPlugins.length > 0) {
// configPlugins.forEach(function(plugin) { // configPlugins.forEach(function(plugin) {
// plugin.contractsConfigs.forEach(function(pluginConfig) { // plugin.contractsConfigs.forEach(function(pluginConfig) {
// configObject = merge.recursive(configObject, pluginConfig); // configObject = utils.recursiveMerge(configObject, pluginConfig);
// }); // });
// }); // });
//} //}
var communicationConfig = JSON.parse(fs.readFileSync(this.configDir + "communication.json")); var communicationConfig = JSON.parse(fs.readFileSync(this.configDir + "communication.json"));
configObject = merge.recursive(configObject, communicationConfig); configObject = utils.recursiveMerge(configObject, communicationConfig);
var defaultCommunicationConfig = configObject['default']; var defaultCommunicationConfig = configObject['default'];
var envCommunicationConfig = configObject[this.env]; var envCommunicationConfig = configObject[this.env];
var mergedConfig = merge.recursive(defaultCommunicationConfig, envCommunicationConfig); var mergedConfig = utils.recursiveMerge(defaultCommunicationConfig, envCommunicationConfig);
this.communicationConfig = mergedConfig; this.communicationConfig = mergedConfig;
}; };
@ -148,7 +147,7 @@ Config.prototype.loadChainTrackerFile = function() {
Config.prototype.loadFiles = function(files) { Config.prototype.loadFiles = function(files) {
var self = this; var self = this;
var originalFiles = utils.filesMatchinPattern(files); var originalFiles = utils.filesMatchingPattern(files);
var readFiles = []; var readFiles = [];
// get embark.js object first // get embark.js object first

View File

@ -1,11 +1,12 @@
var path = require('path'); var path = require('path');
var grunt = require('grunt'); var grunt = require('grunt');
var merge = require('merge');
function joinPath() { function joinPath() {
return path.join.apply(path.join, arguments); return path.join.apply(path.join, arguments);
} }
function filesMatchinPattern(files) { function filesMatchingPattern(files) {
return grunt.file.expand({nonull: true}, files); return grunt.file.expand({nonull: true}, files);
} }
@ -13,7 +14,14 @@ function fileMatchesPattern(patterns, intendedPath) {
return grunt.file.isMatch(patterns, intendedPath); return grunt.file.isMatch(patterns, intendedPath);
} }
function recursiveMerge(target, source) {
return merge.recursive(target, source);
}
module.exports = { module.exports = {
joinPath: joinPath joinPath: joinPath,
filesMatchingPattern: filesMatchingPattern,
fileMatchesPattern: fileMatchesPattern,
recursiveMerge: recursiveMerge
}; };