From 8ae6c6a6460c65db13dc8d93b41c4f02e4efa8c3 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 16 May 2018 15:07:47 -0400 Subject: [PATCH] simplify buildContracts and buildWeb3JS methodsgst --- lib/pipeline/pipeline.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index e12f3d72..1bf377cc 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -179,31 +179,39 @@ class Pipeline { ); } - buildContracts(callback) { + buildContracts(cb) { const self = this; - fs.mkdirp(fs.dappPath(this.buildDir, 'contracts'), (err) => { - if (err) { - return callback(err); - } - self.events.request('contracts:list', (contracts) => { + + async.waterfall([ + function makeDirectory(next) { + fs.mkdirp(fs.dappPath(self.buildDir, 'contracts'), (err, _result) => { + next(err) + }); + }, + function getContracts(next) { + self.events.request('contracts:list', (contracts) => { + next(null, contracts); + }); + }, + function writeContractsJSON(contracts, next) { async.each(contracts, (contract, eachCb) => { - fs.writeJson(fs.dappPath(this.buildDir, 'contracts', contract.className + ".json"), contract, {spaces: 2}, eachCb); - }, () => {callback()}); - }); - }); + fs.writeJson(fs.dappPath(self.buildDir, 'contracts', contract.className + ".json"), contract, {spaces: 2}, eachCb); + }, () => {next()}); + } + ], cb); } buildWeb3JS(cb) { const self = this; async.waterfall([ + function makeDirectory(next) { + fs.mkdirp(fs.dappPath(".embark"), (err, _result) => { + next(err); + }); + }, function getWeb3Code(next) { self.events.request('code-generator:web3js', next); }, - function makeDirectory(code, next) { - fs.mkdirp(fs.dappPath(".embark"), (err, _result) => { - next(err, code); - }); - }, function writeFile(code, next) { fs.writeFile(fs.dappPath(".embark", 'web3_instance.js'), code, next); }