mirror of https://github.com/embarklabs/embark.git
add new plugin method for generalized event actions
This commit is contained in:
parent
f08bb56337
commit
4f45b4fa13
|
@ -84,13 +84,14 @@ class DeployManager {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function runAfterDeploy(callback) {
|
function runAfterDeploy(callback) {
|
||||||
let afterDeployPlugins = self.plugins.getPluginsProperty('afterContractsDeployActions', 'afterContractsDeployActions');
|
self.plugins.runActionsForEvent('contracts:deploy:afterAll', callback);
|
||||||
|
//let afterDeployPlugins = self.plugins.getPluginsProperty('afterContractsDeployActions', 'afterContractsDeployActions');
|
||||||
|
|
||||||
async.eachLimit(afterDeployPlugins, 1, function(plugin, nextEach) {
|
//async.eachLimit(afterDeployPlugins, 1, function(plugin, nextEach) {
|
||||||
plugin.call(plugin, nextEach);
|
// plugin.call(plugin, nextEach);
|
||||||
}, () => {
|
//}, () => {
|
||||||
callback();
|
// callback();
|
||||||
});
|
//});
|
||||||
}
|
}
|
||||||
], function (err, _result) {
|
], function (err, _result) {
|
||||||
done(err);
|
done(err);
|
||||||
|
|
|
@ -27,6 +27,7 @@ var Plugin = function(options) {
|
||||||
this.embarkjs_init_code = {};
|
this.embarkjs_init_code = {};
|
||||||
this.afterContractsDeployActions = [];
|
this.afterContractsDeployActions = [];
|
||||||
this.onDeployActions = [];
|
this.onDeployActions = [];
|
||||||
|
this.eventActions = {};
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
|
@ -215,6 +216,14 @@ Plugin.prototype.registerOnDeployContracts = function(cb) {
|
||||||
this.pluginTypes.push('onDeployActions');
|
this.pluginTypes.push('onDeployActions');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Plugin.prototype.registerActionForEvent = function(eventName, cb) {
|
||||||
|
if (!this.eventActions[eventName]) {
|
||||||
|
this.eventActions[eventName] = [];
|
||||||
|
}
|
||||||
|
this.eventActions[eventName].push(cb);
|
||||||
|
this.pluginTypes.push('eventActions');
|
||||||
|
}
|
||||||
|
|
||||||
Plugin.prototype.runFilePipeline = function() {
|
Plugin.prototype.runFilePipeline = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const async = require('async');
|
||||||
var Plugin = require('./plugin.js');
|
var Plugin = require('./plugin.js');
|
||||||
var utils = require('../utils/utils.js');
|
var utils = require('../utils/utils.js');
|
||||||
|
|
||||||
|
@ -98,18 +99,31 @@ Plugins.prototype.getPluginsFor = function(pluginType) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugins.prototype.getPluginsProperty = function(pluginType, property) {
|
Plugins.prototype.getPluginsProperty = function(pluginType, property, sub_property) {
|
||||||
let matchingPlugins = this.plugins.filter(function(plugin) {
|
let matchingPlugins = this.plugins.filter(function(plugin) {
|
||||||
return plugin.has(pluginType);
|
return plugin.has(pluginType);
|
||||||
});
|
});
|
||||||
|
|
||||||
let matchingProperties = matchingPlugins.map((plugin) => {
|
let matchingProperties = matchingPlugins.map((plugin) => {
|
||||||
|
if (sub_property) {
|
||||||
|
return plugin[property][sub_property];
|
||||||
|
}
|
||||||
return plugin[property];
|
return plugin[property];
|
||||||
});
|
});
|
||||||
|
|
||||||
//return flattened list
|
//return flattened list
|
||||||
if (matchingProperties.length === 0) return [];
|
if (matchingProperties.length === 0) return [];
|
||||||
return matchingProperties.reduce((a,b) => { return a.concat(b); });
|
return matchingProperties.reduce((a,b) => { return a.concat(b); }) || [];
|
||||||
|
};
|
||||||
|
|
||||||
|
//Plugins.prototype.runActionsForEvent = function(eventName, args, cb) {
|
||||||
|
Plugins.prototype.runActionsForEvent = function(eventName, cb) {
|
||||||
|
let actionPlugins = this.getPluginsProperty('eventActions', 'eventActions', eventName);
|
||||||
|
|
||||||
|
async.eachLimit(actionPlugins, 1, function(plugin, nextEach) {
|
||||||
|
//plugin.call(plugin, ...args, nextEach);
|
||||||
|
plugin.call(plugin, nextEach);
|
||||||
|
}, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Plugins;
|
module.exports = Plugins;
|
||||||
|
|
|
@ -48,7 +48,8 @@ class SpecialConfigs {
|
||||||
registerAfterDeployAction() {
|
registerAfterDeployAction() {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
this.embark.registerAfterAllContractsDeploy((cb) => {
|
//this.embark.registerAfterAllContractsDeploy((cb) => {
|
||||||
|
this.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => {
|
||||||
let afterDeployCmds = self.contractsConfig.afterDeploy || [];
|
let afterDeployCmds = self.contractsConfig.afterDeploy || [];
|
||||||
|
|
||||||
async.mapLimit(afterDeployCmds, 1, (cmd, nextMapCb) => {
|
async.mapLimit(afterDeployCmds, 1, (cmd, nextMapCb) => {
|
||||||
|
|
Loading…
Reference in New Issue