From 86cd2a15d10d28bba0d0346ce1d166e08e0d7273 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 18 Feb 2017 14:45:57 -0500 Subject: [PATCH] move merge to utils module --- lib/config.js | 21 ++++++++++----------- lib/utils.js | 12 ++++++++++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/config.js b/lib/config.js index f56c9903..532531bc 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,5 +1,4 @@ var fs = require('fs'); -var merge = require('merge'); var Plugins = require('./plugins.js'); var utils = require('./utils.js'); @@ -62,17 +61,17 @@ Config.prototype.loadContractsConfigFile = function() { if (configPlugins.length > 0) { configPlugins.forEach(function(plugin) { 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")); - configObject = merge.recursive(configObject, contractsConfig); + configObject = utils.recursiveMerge(configObject, contractsConfig); var defaultContractsConfig = configObject['default']; var envContractsConfig = configObject[this.env]; - var mergedConfig = merge.recursive(defaultContractsConfig, envContractsConfig); + var mergedConfig = utils.recursiveMerge(defaultContractsConfig, envContractsConfig); this.contractsConfig = mergedConfig; }; @@ -84,17 +83,17 @@ Config.prototype.loadStorageConfigFile = function() { //if (configPlugins.length > 0) { // configPlugins.forEach(function(plugin) { // 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")); - configObject = merge.recursive(configObject, storageConfig); + configObject = utils.recursiveMerge(configObject, storageConfig); var defaultStorageConfig = configObject['default']; var envStorageConfig = configObject[this.env]; - var mergedConfig = merge.recursive(defaultStorageConfig, envStorageConfig); + var mergedConfig = utils.recursiveMerge(defaultStorageConfig, envStorageConfig); this.storageConfig = mergedConfig; }; @@ -105,17 +104,17 @@ Config.prototype.loadCommunicationConfigFile = function() { //if (configPlugins.length > 0) { // configPlugins.forEach(function(plugin) { // 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")); - configObject = merge.recursive(configObject, communicationConfig); + configObject = utils.recursiveMerge(configObject, communicationConfig); var defaultCommunicationConfig = configObject['default']; var envCommunicationConfig = configObject[this.env]; - var mergedConfig = merge.recursive(defaultCommunicationConfig, envCommunicationConfig); + var mergedConfig = utils.recursiveMerge(defaultCommunicationConfig, envCommunicationConfig); this.communicationConfig = mergedConfig; }; @@ -148,7 +147,7 @@ Config.prototype.loadChainTrackerFile = function() { Config.prototype.loadFiles = function(files) { var self = this; - var originalFiles = utils.filesMatchinPattern(files); + var originalFiles = utils.filesMatchingPattern(files); var readFiles = []; // get embark.js object first diff --git a/lib/utils.js b/lib/utils.js index e5143661..5cd619e8 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,11 +1,12 @@ var path = require('path'); var grunt = require('grunt'); +var merge = require('merge'); function joinPath() { return path.join.apply(path.join, arguments); } -function filesMatchinPattern(files) { +function filesMatchingPattern(files) { return grunt.file.expand({nonull: true}, files); } @@ -13,7 +14,14 @@ function fileMatchesPattern(patterns, intendedPath) { return grunt.file.isMatch(patterns, intendedPath); } +function recursiveMerge(target, source) { + return merge.recursive(target, source); +} + module.exports = { - joinPath: joinPath + joinPath: joinPath, + filesMatchingPattern: filesMatchingPattern, + fileMatchesPattern: fileMatchesPattern, + recursiveMerge: recursiveMerge };