diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index 16a58a59..1468b029 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -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; } diff --git a/lib/core/events.js b/lib/core/events.js index 425574e9..f7f055fc 100644 --- a/lib/core/events.js +++ b/lib/core/events.js @@ -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;