From 2c2a09ca68a099084f7a9f596a33941a4a035ff5 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 25 Jan 2019 17:16:52 -0500 Subject: [PATCH] feature(@embark/deploytracker) support configuring deployment tracking file on a per environment basis; put default dev on temporary directory --- packages/embark/src/lib/core/config.js | 11 ---------- packages/embark/src/lib/core/fs.js | 5 +++++ .../src/lib/modules/deploytracker/index.js | 20 ++++++++++++++++--- packages/embark/templates/.gitignore | 1 - 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/embark/src/lib/core/config.js b/packages/embark/src/lib/core/config.js index 4e7383ac5..43acd47b4 100644 --- a/packages/embark/src/lib/core/config.js +++ b/packages/embark/src/lib/core/config.js @@ -99,7 +99,6 @@ Config.prototype.loadConfigFiles = function(options) { this.loadContractsConfigFile(); this.loadExternalContractsFiles(); this.loadWebServerConfigFile(); - this.loadChainTrackerFile(); this.loadPluginContractFiles(); this._updateBlockchainCors(); @@ -116,7 +115,6 @@ Config.prototype.reloadConfig = function() { this.loadAssetFiles(); this.loadContractsConfigFile(); this.loadExternalContractsFiles(); - this.loadChainTrackerFile(); this._updateBlockchainCors(); }; @@ -541,15 +539,6 @@ Config.prototype.loadAssetFiles = function () { }); }; -Config.prototype.loadChainTrackerFile = function() { - if (!fs.existsSync(this.chainsFile)) { - this.logger.info(this.chainsFile + ' ' + __('file not found, creating it...')); - fs.writeJSONSync(this.chainsFile, {}); - } - - this.chainTracker = fs.readJSONSync(this.chainsFile); -}; - function findMatchingExpression(filename, filesExpressions) { for (let fileExpression of filesExpressions) { var matchingFiles = utils.filesMatchingPattern(fileExpression); diff --git a/packages/embark/src/lib/core/fs.js b/packages/embark/src/lib/core/fs.js index e23bf319c..c97ee0fa4 100644 --- a/packages/embark/src/lib/core/fs.js +++ b/packages/embark/src/lib/core/fs.js @@ -108,6 +108,10 @@ function writeJSONSync() { return restrictPath(fs.writeJSONSync, fs.writeJSONSync, 1, arguments); } +function outputJSONSync() { + return restrictPath(fs.outputJSONSync, fs.outputJSONSync, 1, arguments); +} + function writeJson() { return restrictPath(fs.writeJson, fs.writeJson, 1, arguments); } @@ -219,6 +223,7 @@ module.exports = { move, moveSync, outputFileSync, + outputJSONSync, pkgPath, readFile, readFileSync, diff --git a/packages/embark/src/lib/modules/deploytracker/index.js b/packages/embark/src/lib/modules/deploytracker/index.js index 274e9f098..26fe8a8f9 100644 --- a/packages/embark/src/lib/modules/deploytracker/index.js +++ b/packages/embark/src/lib/modules/deploytracker/index.js @@ -11,12 +11,26 @@ class DeployTracker { // TODO: unclear where it comes from this.env = options.env; - //this.chainConfig = options.chainConfig; - this.chainConfig = embark.config.chainTracker; + this.chainConfig = {}; + this.chainFile = embark.config.contractsConfig.tracking; + this.loadChainTrackerFile(); this.registerEvents(); } + loadChainTrackerFile() { + if (this.chainFile === false) return; + if (this.chainFile === undefined) this.chainFile = ".embark/chains.json"; + this.chainFile = fs.dappPath(this.chainFile); + if (!fs.existsSync(this.chainFile)) { + this.logger.info(this.chainFile + ' ' + __('file not found, creating it...')); + fs.outputJSONSync(this.chainFile, {}); + } + + this.chainConfig = fs.readJSONSync(this.chainFile); + } + registerEvents() { + if (this.chainFile === false) return; const self = this; this.embark.registerActionForEvent("deploy:beforeAll", this.setCurrentChain.bind(this)); @@ -91,7 +105,7 @@ class DeployTracker { if (this.chainConfig === false) { return; } - fs.writeJSONSync("./chains.json", this.chainConfig, {spaces: 2}); + fs.writeJSONSync(this.chainFile, this.chainConfig, {spaces: 2}); } } diff --git a/packages/embark/templates/.gitignore b/packages/embark/templates/.gitignore index 359a5e976..24c6e72da 100644 --- a/packages/embark/templates/.gitignore +++ b/packages/embark/templates/.gitignore @@ -1,5 +1,4 @@ **/.embark -**/chains.json **/config/production/password **/config/livenet/password **/coverage