embark-area-51/lib/core/plugins.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

var Plugin = require('./plugin.js');
2017-02-18 20:07:19 +00:00
var utils = require('./utils.js');
var Plugins = function(options) {
this.pluginList = options.plugins || [];
2017-02-06 11:42:58 +00:00
this.interceptLogs = options.interceptLogs;
this.plugins = [];
// TODO: need backup 'NullLogger'
this.logger = options.logger;
2017-03-04 17:42:24 +00:00
this.events = options.events;
this.config = options.config;
};
Plugins.prototype.loadPlugins = function() {
var pluginConfig;
for (var pluginName in this.pluginList) {
pluginConfig = this.pluginList[pluginName];
this.loadPlugin(pluginName, pluginConfig);
}
};
Plugins.prototype.listPlugins = function() {
var list = [];
for (var className in this.pluginList) {
list.push(className);
}
return list;
};
Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) {
2017-02-18 19:10:01 +00:00
var pluginPath = utils.joinPath(process.env.PWD, 'node_modules', pluginName);
2017-01-26 11:34:00 +00:00
var plugin = require(pluginPath);
var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs, events: this.events, config: this.config});
pluginWrapper.loadPlugin();
this.plugins.push(pluginWrapper);
};
Plugins.prototype.getPluginsFor = function(pluginType) {
return this.plugins.filter(function(plugin) {
return plugin.has(pluginType);
});
};
module.exports = Plugins;