From c91e145981cf98a94eae2c47c87117106f319b96 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 8 Feb 2019 11:41:52 -0500 Subject: [PATCH] refactor(generation/embarkjs): generate embarkjs in artifacts dir --- packages/embark/src/lib/constants.json | 3 ++- .../src/lib/modules/code_generator/index.js | 25 ++++++++++--------- .../embark/src/lib/modules/pipeline/index.js | 3 ++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/embark/src/lib/constants.json b/packages/embark/src/lib/constants.json index 593b3d319..7e58d2c47 100644 --- a/packages/embark/src/lib/constants.json +++ b/packages/embark/src/lib/constants.json @@ -88,6 +88,7 @@ "dir": "config", "blockchain": "blockchain.json", "storage": "storage.json", - "communication": "communication.json" + "communication": "communication.json", + "embarkjs": "embarkjs.js" } } diff --git a/packages/embark/src/lib/modules/code_generator/index.js b/packages/embark/src/lib/modules/code_generator/index.js index aa3170699..28e77ab39 100644 --- a/packages/embark/src/lib/modules/code_generator/index.js +++ b/packages/embark/src/lib/modules/code_generator/index.js @@ -149,44 +149,47 @@ class CodeGenerator { warnIfMetamask: this.blockchainConfig.isDev, blockchainClient: this.blockchainConfig.ethereumClientName }; - this.generateConfig(this.dappConfigs.blockchain, constants.dappConfig.blockchain); + this.generateArtifact(this.dappConfigs.blockchain, constants.dappConfig.blockchain, constants.dappConfig.dir); } generateStorageConfig(storageConfig) { this.dappConfigs.storage = { dappConnection: storageConfig.dappConnection }; - this.generateConfig(this.dappConfigs.storage, constants.dappConfig.storage); + this.generateArtifact(this.dappConfigs.storage, constants.dappConfig.storage, constants.dappConfig.dir); } generateCommunicationConfig(communicationConfig) { this.dappConfigs.communication = { connection: communicationConfig.connection }; - this.generateConfig(this.dappConfigs.communication, constants.dappConfig.communication); + this.generateArtifact(this.dappConfigs.communication, constants.dappConfig.communication, constants.dappConfig.dir); } - generateConfig(configObj, filepathName) { - const dir = utils.joinPath(this.embarkConfig.generationDir, constants.dappConfig.dir); - const filePath = utils.joinPath(dir, filepathName); - const configString = JSON.stringify(configObj, null, 2); + generateArtifact(artifactInput, fileName, dirName, cb = () => {}) { + const dir = utils.joinPath(this.embarkConfig.generationDir, dirName); + const filePath = utils.joinPath(dir, fileName); + if (typeof artifactInput !== 'string') { + artifactInput = JSON.stringify(artifactInput, null, 2); + } async.waterfall([ (next) => { fs.mkdirp(dir, next); }, (_dir, next) => { - this.checkIfNeedsUpdate(filePath, configString, next); + this.checkIfNeedsUpdate(filePath, artifactInput, next); }, (needsUpdate, next) => { if (!needsUpdate) { return next(); } - fs.writeFile(filePath, configString, next); + fs.writeFile(filePath, artifactInput, next); } ], (err) => { if (err) { this.logger.error(err.message || err); } + cb(err); }); } @@ -326,9 +329,7 @@ class CodeGenerator { next(); }, function writeFile(next) { - fs.mkdirpSync(fs.dappPath(".embark")); - fs.writeFileSync(fs.dappPath(".embark", 'embark.js'), code); - next(); + self.generateArtifact(code, constants.dappConfig.embarkjs, '', next); } ], function(_err, _result) { cb(); diff --git a/packages/embark/src/lib/modules/pipeline/index.js b/packages/embark/src/lib/modules/pipeline/index.js index 818ccdffd..2acc31072 100644 --- a/packages/embark/src/lib/modules/pipeline/index.js +++ b/packages/embark/src/lib/modules/pipeline/index.js @@ -14,6 +14,7 @@ class Pipeline { this.buildDir = embark.config.buildDir; this.contractsFiles = embark.config.contractsFiles; this.assetFiles = embark.config.assetFiles; + this.embarkConfig = embark.config.embarkConfig; this.events = embark.events; this.logger = embark.config.logger; this.plugins = embark.config.plugins; @@ -154,7 +155,7 @@ class Pipeline { (next) => self.buildContracts(next), (next) => self.buildWeb3JS(next), function createImportList(next) { - importsList["Embark/EmbarkJS"] = fs.dappPath(".embark", 'embark.js'); + importsList["Embark/EmbarkJS"] = fs.dappPath(self.embarkConfig.generationDir, constants.dappConfig.embarkjs); importsList["Embark/web3"] = fs.dappPath(".embark", 'web3_instance.js'); importsList["Embark/contracts"] = fs.dappPath(".embark/contracts", '');