only log loaded plugins in list plugins and warn when plugin is not right

This commit is contained in:
Jonathan Rainville 2018-04-24 15:53:19 -04:00
parent 51c2c8f880
commit 97e91d4c44
3 changed files with 13 additions and 7 deletions

View File

@ -235,7 +235,6 @@ class Engine {
self.context = constants.contexts.simulator;
}
if (oldContext !== self.context) {
console.log('Emiting context change');
self.events.emit(constants.events.contextChange, self.context);
}
let versionNumber = version.split("/")[1].split("-")[0];

View File

@ -28,14 +28,19 @@ var Plugin = function(options) {
this.logger = options.logger;
this.events = options.events;
this.config = options.config;
this.loaded = false;
this.context = options.pluginConfig.context || constants.contexts.any;
};
Plugin.prototype.loadPlugin = function(currentContext) {
if (this.context !== constants.contexts.any && this.context !== currentContext) {
this.events.on(constants.events.contextChange, this.loadPlugin.bind(this));
return;
if (currentContext) {
this.logger.warn(`Plugin ${this.name} can only be loaded in the context of the ${this.context}`);
}
return this.events.on(constants.events.contextChange, this.loadPlugin.bind(this));
}
this.loaded = true;
this.logger.info(`Loaded plugin ${this.name}`);
this.events.removeListener(constants.events.contextChange, this.loadPlugin.bind(this));
if (this.shouldInterceptLogs) {
this.interceptLogs(this.pluginModule);

View File

@ -20,10 +20,12 @@ Plugins.prototype.loadPlugins = function() {
};
Plugins.prototype.listPlugins = function() {
var list = [];
for (var className in this.pluginList) {
list.push(className);
}
const list = [];
this.plugins.forEach(plugin => {
if (plugin.loaded) {
list.push(plugin.name);
}
});
return list;
};