mirror of https://github.com/embarklabs/embark.git
add deployIf directive support
This commit is contained in:
parent
a56431d19a
commit
8f5b47adf4
|
@ -141,14 +141,12 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb) {
|
|||
return cb(args);
|
||||
}
|
||||
|
||||
//async.eachLimit(actionPlugins, 1, function(plugin, nextEach) {
|
||||
async.reduce(actionPlugins, args, function(current_args, plugin, nextEach) {
|
||||
if (typeof (args) === 'function') {
|
||||
plugin.call(plugin, (params) => {
|
||||
nextEach(null, (params || current_args));
|
||||
});
|
||||
} else {
|
||||
//plugin.call(plugin, ...args, nextEach);
|
||||
plugin.call(plugin, args, (params) => {
|
||||
nextEach(null, (params || current_args));
|
||||
});
|
||||
|
|
|
@ -144,11 +144,7 @@ class ContractDeployer {
|
|||
if (process.env.isTest) {
|
||||
return self.deployContract(contract, next);
|
||||
}
|
||||
// TODO: this should be a plugin API instead, if not existing, it should by default deploy the contract
|
||||
//self.events.request("deploy:contract:shouldDeploy", contract, function(trackedContract) {
|
||||
self.plugins.emitAndRunActionsForEvent('deploy:contract:shouldDeploy', {contract: contract, shouldDeploy: true}, function(_err, params) {
|
||||
console.dir(contract.className);
|
||||
console.dir(arguments);
|
||||
let trackedContract = params.contract;
|
||||
if (!params.shouldDeploy) {
|
||||
return next();
|
||||
|
|
|
@ -25,7 +25,6 @@ class DeployTracker {
|
|||
self.save();
|
||||
});
|
||||
|
||||
//this.events.setCommandHandler("deploy:contract:shouldDeploy", (contract, cb) => {
|
||||
self.embark.registerActionForEvent("deploy:contract:shouldDeploy", (params, cb) => {
|
||||
let contract = params.contract;
|
||||
let trackedContract = self.getContract(contract.className, contract.realRuntimeBytecode, contract.realArgs);
|
||||
|
|
|
@ -12,7 +12,7 @@ class SpecialConfigs {
|
|||
|
||||
this.registerAfterDeployAction();
|
||||
this.registerOnDeployAction();
|
||||
this.registerDeployIfAction()
|
||||
this.registerDeployIfAction();
|
||||
}
|
||||
|
||||
replaceWithAddresses(cmd, cb) {
|
||||
|
@ -109,19 +109,23 @@ class SpecialConfigs {
|
|||
const self = this;
|
||||
|
||||
self.embark.registerActionForEvent("deploy:contract:shouldDeploy", (params, cb) => {
|
||||
console.dir(params.contract.className)
|
||||
console.dir(params.contract.classNideployIf)
|
||||
self.embark.logger.info("===applying shouldDeploy plugin...");
|
||||
if (params.contract.deployIf === 'hello') {
|
||||
console.dir("-------------")
|
||||
console.dir("-------------")
|
||||
console.dir("contract has the param")
|
||||
console.dir("-------------")
|
||||
console.dir("-------------")
|
||||
let cmd = params.contract.deployIf;
|
||||
if (!cmd) {
|
||||
return cb(params);
|
||||
}
|
||||
params.shouldDeploy = (params.contract.deployIf !== 'hello');
|
||||
//cb(true, contract);
|
||||
cb(params);
|
||||
|
||||
self.events.request('runcode:eval', cmd, (err, result) => {
|
||||
if (err) {
|
||||
self.logger.error(params.contract.className + ' deployIf directive has an error; contract will not deploy');
|
||||
self.logger.error(err);
|
||||
params.shouldDeploy = false;
|
||||
} else if (!result) {
|
||||
self.logger.info(params.contract.className + ' deployIf directive returned false; contract will not deploy');
|
||||
params.shouldDeploy = false;
|
||||
}
|
||||
|
||||
cb(params);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
SomeContract: {
|
||||
deployIf: 'MyToken.methods.isAvailable().call()',
|
||||
args: [
|
||||
["$MyToken2", "$SimpleStorage"],
|
||||
100
|
||||
|
|
|
@ -63,4 +63,7 @@ contract Token {
|
|||
function safeToAdd(uint a, uint b) internal pure returns (bool) {
|
||||
return (a + b >= a);
|
||||
}
|
||||
function isAvailable() public constant returns (bool) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue