fix multiple issues with multiple file writes

This commit is contained in:
Iuri Matias 2017-10-21 14:21:18 -04:00
parent be7d4b0d4d
commit 398aff3af7
2 changed files with 15 additions and 11 deletions

View File

@ -28,28 +28,28 @@ class CodeGenerator {
let self = this;
// deprecated events; to remove in embark 2.7.0
this.events.setCommandHandler('abi-vanila', function(cb) {
this.events.setCommandHandlerOnce('abi-vanila', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false});
let contractsJSON = self.generateContractsJSON();
cb(vanillaABI, contractsJSON);
});
this.events.setCommandHandler('abi', function(cb) {
this.events.setCommandHandlerOnce('abi', function(cb) {
let embarkJSABI = self.generateABI({useEmbarkJS: true});
let contractsJSON = self.generateContractsJSON();
cb(embarkJSABI, contractsJSON);
});
this.events.setCommandHandler('abi-contracts-vanila', function(cb) {
this.events.setCommandHandlerOnce('abi-contracts-vanila', function(cb) {
let vanillaContractsABI = self.generateContracts(false, true, false);
let contractsJSON = self.generateContractsJSON();
cb(vanillaContractsABI, contractsJSON);
});
this.events.setCommandHandler('abi-vanila-deployment', function(cb) {
this.events.setCommandHandlerOnce('abi-vanila-deployment', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true});
let contractsJSON = self.generateContractsJSON();
@ -57,35 +57,34 @@ class CodeGenerator {
});
// new events
this.events.setCommandHandler('code-vanila', function(cb) {
this.events.setCommandHandlerOnce('code-vanila', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false});
let contractsJSON = self.generateContractsJSON();
cb(vanillaABI, contractsJSON);
});
this.events.setCommandHandler('code', function(cb) {
this.events.setCommandHandlerOnce('code', function(cb) {
let embarkJSABI = self.generateABI({useEmbarkJS: true});
let contractsJSON = self.generateContractsJSON();
cb(embarkJSABI, contractsJSON);
});
this.events.setCommandHandler('code-contracts-vanila', function(cb) {
this.events.setCommandHandlerOnce('code-contracts-vanila', function(cb) {
let vanillaContractsABI = self.generateContracts(false, true, false);
let contractsJSON = self.generateContractsJSON();
cb(vanillaContractsABI, contractsJSON);
});
this.events.setCommandHandler('code-vanila-deployment', function(cb) {
this.events.setCommandHandlerOnce('code-vanila-deployment', function(cb) {
let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true});
let contractsJSON = self.generateContractsJSON();
cb(vanillaABI, contractsJSON);
});
}
generateProvider(isDeployment) {
@ -222,8 +221,6 @@ class CodeGenerator {
result += Templates.exec_when_env_loaded({block: block});
}
console.log(result);
return result;
}

View File

@ -42,4 +42,11 @@ EventEmitter.prototype.setCommandHandler = function(requestName, cb) {
});
};
EventEmitter.prototype.setCommandHandlerOnce = function(requestName, cb) {
log("setting command handler for: ", requestName);
return this.once('request:' + requestName, function(_cb) {
cb.call(this, _cb);
});
};
module.exports = EventEmitter;