2016-12-07 02:33:31 +00:00
|
|
|
var Plugin = require('./plugin.js');
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
var Plugins = function(options) {
|
|
|
|
this.pluginList = options.plugins || [];
|
|
|
|
this.plugins = [];
|
2017-01-15 19:30:41 +00:00
|
|
|
// TODO: need backup 'NullLogger'
|
|
|
|
this.logger = options.logger;
|
2016-12-07 02:33:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Plugins.prototype.loadPlugins = function() {
|
2017-01-15 19:30:41 +00:00
|
|
|
var pluginConfig;
|
|
|
|
for (var pluginName in this.pluginList) {
|
|
|
|
pluginConfig = this.pluginList[pluginName];
|
|
|
|
this.loadPlugin(pluginName, pluginConfig);
|
2016-12-07 02:33:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-15 19:30:41 +00:00
|
|
|
Plugins.prototype.listPlugins = function() {
|
|
|
|
var list = [];
|
|
|
|
for (var className in this.pluginList) {
|
|
|
|
list.push(className);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
};
|
|
|
|
|
|
|
|
Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) {
|
2016-12-07 02:33:31 +00:00
|
|
|
var plugin = require(path.join(process.env.PWD, 'node_modules', pluginName));
|
|
|
|
|
2017-01-15 19:30:41 +00:00
|
|
|
var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger});
|
2016-12-07 02:33:31 +00:00
|
|
|
pluginWrapper.loadPlugin();
|
|
|
|
this.plugins.push(pluginWrapper);
|
|
|
|
};
|
|
|
|
|
|
|
|
Plugins.prototype.getPluginsFor = function(pluginType) {
|
|
|
|
return this.plugins.filter(function(plugin) {
|
|
|
|
return plugin.has(pluginType);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Plugins;
|