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) {
|
||||
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) {
|
||||
plugin.call(plugin, nextEach);
|
||||
}, () => {
|
||||
callback();
|
||||
});
|
||||
//async.eachLimit(afterDeployPlugins, 1, function(plugin, nextEach) {
|
||||
// plugin.call(plugin, nextEach);
|
||||
//}, () => {
|
||||
// callback();
|
||||
//});
|
||||
}
|
||||
], function (err, _result) {
|
||||
done(err);
|
||||
|
|
|
@ -27,6 +27,7 @@ var Plugin = function(options) {
|
|||
this.embarkjs_init_code = {};
|
||||
this.afterContractsDeployActions = [];
|
||||
this.onDeployActions = [];
|
||||
this.eventActions = {};
|
||||
this.logger = options.logger;
|
||||
this.events = options.events;
|
||||
this.config = options.config;
|
||||
|
@ -215,6 +216,14 @@ Plugin.prototype.registerOnDeployContracts = function(cb) {
|
|||
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() {
|
||||
var self = this;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const async = require('async');
|
||||
var Plugin = require('./plugin.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) {
|
||||
return plugin.has(pluginType);
|
||||
});
|
||||
|
||||
let matchingProperties = matchingPlugins.map((plugin) => {
|
||||
if (sub_property) {
|
||||
return plugin[property][sub_property];
|
||||
}
|
||||
return plugin[property];
|
||||
});
|
||||
|
||||
//return flattened list
|
||||
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;
|
||||
|
|
|
@ -48,7 +48,8 @@ class SpecialConfigs {
|
|||
registerAfterDeployAction() {
|
||||
const self = this;
|
||||
|
||||
this.embark.registerAfterAllContractsDeploy((cb) => {
|
||||
//this.embark.registerAfterAllContractsDeploy((cb) => {
|
||||
this.embark.registerActionForEvent("contracts:deploy:afterAll", (cb) => {
|
||||
let afterDeployCmds = self.contractsConfig.afterDeploy || [];
|
||||
|
||||
async.mapLimit(afterDeployCmds, 1, (cmd, nextMapCb) => {
|
||||
|
|
Loading…
Reference in New Issue