simplify buildContracts and buildWeb3JS methodsgst

This commit is contained in:
Iuri Matias 2018-05-16 15:07:47 -04:00
parent 4dcd644b7c
commit 8ae6c6a646
1 changed files with 23 additions and 15 deletions

View File

@ -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);
}
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);
}