From 94c493e854c5e98f4e8fe4a794c31cce252cd7e1 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 27 Apr 2018 15:10:24 -0400 Subject: [PATCH] redeploy with right config on config change --- lib/constants.json | 3 ++- lib/contracts/contracts.js | 7 +++++-- lib/core/config.js | 9 +++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/constants.json b/lib/constants.json index d6bc7a60b..06d6a28c2 100644 --- a/lib/constants.json +++ b/lib/constants.json @@ -13,6 +13,7 @@ "any": "any" }, "events": { - "contractFilesChanged": "contractFilesChanged" + "contractFilesChanged": "contractFilesChanged", + "contractConfigChanged": "contractConfigChanged" } } diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index 2dd8e9a75..10f567085 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -19,8 +19,11 @@ class ContractsManager { this.deployOnlyOnConfig = false; this.events = options.events; - this.events.on(constants.events.contractFilesChanged, (newContracts) => { - this.contractFiles = newContracts; + this.events.on(constants.events.contractFilesChanged, (newContractFiles) => { + this.contractFiles = newContractFiles; + }); + this.events.on(constants.events.contractConfigChanged, (newContracts) => { + this.contractsConfig = newContracts; }); } diff --git a/lib/core/config.js b/lib/core/config.js index 99e0e9c0d..3b6333ddf 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -142,7 +142,12 @@ Config.prototype.loadContractsConfigFile = function() { let configFilePath = this._getFileOrOject(this.configDir, 'contracts.json', 'contracts'); - this.contractsConfig = this._mergeConfig(configFilePath, configObject, this.env); + const newContractsConfig = this._mergeConfig(configFilePath, configObject, this.env); + + if (!deepEqual(newContractsConfig, this.contractsConfig)) { + this.events.emit(constants.events.contractConfigChanged, newContractsConfig); + this.contractsConfig = newContractsConfig; + } }; Config.prototype.loadExternalContractsFiles = function() { @@ -220,7 +225,7 @@ Config.prototype.loadWebServerConfigFile = function() { Config.prototype.loadEmbarkConfigFile = function() { const contracts = this.embarkConfig.contracts; const newContractsFiles = this.loadFiles(contracts); - if (newContractsFiles.length !== this.contractFiles || deepEqual(newContractsFiles, this.contractFiles)) { + if (!this.contractFiles || newContractsFiles.length !== this.contractFiles.length || !deepEqual(newContractsFiles, this.contractFiles)) { this.events.emit(constants.events.contractFilesChanged, newContractsFiles); this.contractsFiles = newContractsFiles; }