simplify buildContracts and buildWeb3JS methodsgst

This commit is contained in:
Iuri Matias 2018-05-16 15:07:47 -04:00
parent 4dcd644b7c
commit 8ae6c6a646

View File

@ -179,31 +179,39 @@ class Pipeline {
); );
} }
buildContracts(callback) { buildContracts(cb) {
const self = this; const self = this;
fs.mkdirp(fs.dappPath(this.buildDir, 'contracts'), (err) => {
if (err) { async.waterfall([
return callback(err); function makeDirectory(next) {
} fs.mkdirp(fs.dappPath(self.buildDir, 'contracts'), (err, _result) => {
self.events.request('contracts:list', (contracts) => { next(err)
});
},
function getContracts(next) {
self.events.request('contracts:list', (contracts) => {
next(null, contracts);
});
},
function writeContractsJSON(contracts, next) {
async.each(contracts, (contract, eachCb) => { async.each(contracts, (contract, eachCb) => {
fs.writeJson(fs.dappPath(this.buildDir, 'contracts', contract.className + ".json"), contract, {spaces: 2}, eachCb); fs.writeJson(fs.dappPath(self.buildDir, 'contracts', contract.className + ".json"), contract, {spaces: 2}, eachCb);
}, () => {callback()}); }, () => {next()});
}); }
}); ], cb);
} }
buildWeb3JS(cb) { buildWeb3JS(cb) {
const self = this; const self = this;
async.waterfall([ async.waterfall([
function makeDirectory(next) {
fs.mkdirp(fs.dappPath(".embark"), (err, _result) => {
next(err);
});
},
function getWeb3Code(next) { function getWeb3Code(next) {
self.events.request('code-generator:web3js', 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) { function writeFile(code, next) {
fs.writeFile(fs.dappPath(".embark", 'web3_instance.js'), code, next); fs.writeFile(fs.dappPath(".embark", 'web3_instance.js'), code, next);
} }