Support old and new console plugin with a warning

This commit is contained in:
Anthony Laibe 2018-08-10 15:54:21 +01:00 committed by Iuri Matias
parent f2939ae91b
commit 774a14c850
5 changed files with 16 additions and 4 deletions

View File

@ -107,6 +107,7 @@ class EmbarkController {
plugins: engine.plugins, plugins: engine.plugins,
version: engine.version, version: engine.version,
events: engine.events, events: engine.events,
logger: engine.logger,
ipc: engine.ipc ipc: engine.ipc
}).startConsole(); }).startConsole();
return callback(); return callback();
@ -342,6 +343,7 @@ class EmbarkController {
plugins: engine.plugins, plugins: engine.plugins,
version: engine.version, version: engine.version,
events: engine.events, events: engine.events,
logger: engine.logger,
ipc: engine.ipc ipc: engine.ipc
}); });
repl.start(callback); repl.start(callback);

View File

@ -5,6 +5,7 @@ class Console {
this.events = options.events; this.events = options.events;
this.plugins = options.plugins; this.plugins = options.plugins;
this.version = options.version; this.version = options.version;
this.logger = options.logger;
this.ipc = options.ipc; this.ipc = options.ipc;
if (this.ipc.isServer()) { if (this.ipc.isServer()) {
@ -38,7 +39,13 @@ class Console {
var pluginCmds = this.plugins.getPluginsProperty('console', 'console'); var pluginCmds = this.plugins.getPluginsProperty('console', 'console');
for (let pluginCmd of pluginCmds) { for (let pluginCmd of pluginCmds) {
let pluginResult = pluginCmd.call(this, cmd, {}); let pluginResult = pluginCmd.call(this, cmd, {});
if (pluginResult.match()) { if(typeof pluginResult !== 'object'){
if (pluginResult !== false && pluginResult !== 'false' && pluginResult !== undefined) {
this.logger.warn("[DEPRECATED] In future versions of embark, we expect the console command to return an object " +
"having 2 functions: match and process.");
return callback(null, pluginResult);
}
} else if (pluginResult.match()) {
return pluginResult.process(callback); return pluginResult.process(callback);
} }
} }

View File

@ -34,7 +34,8 @@ class Dashboard {
events: self.events, events: self.events,
plugins: self.plugins, plugins: self.plugins,
version: self.version, version: self.version,
ipc: self.ipc ipc: self.ipc,
logger: self.logger
}); });
callback(); callback();
}, },

View File

@ -5,6 +5,7 @@ const Console = require('./console.js');
class REPL { class REPL {
constructor(options) { constructor(options) {
this.logger = options.logger;
this.env = options.env; this.env = options.env;
this.plugins = options.plugins; this.plugins = options.plugins;
this.events = options.events; this.events = options.events;
@ -17,7 +18,8 @@ class REPL {
events: this.events, events: this.events,
plugins: this.plugins, plugins: this.plugins,
version: this.version, version: this.version,
ipc: this.ipc ipc: this.ipc,
logger: this.logger
}); });
} }

View File

@ -54,7 +54,7 @@ class WebServer {
return { return {
match: () => cmd === "webserver start", match: () => cmd === "webserver start",
process: (callback) => self.events.request("start-webserver", callback) process: (callback) => self.events.request("start-webserver", callback)
} };
}); });
self.embark.registerConsoleCommand((cmd, _options) => { self.embark.registerConsoleCommand((cmd, _options) => {