From ed9be59abe764e0462cd8e7be1e13b671faae493 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 26 Jul 2018 16:00:25 +0100 Subject: [PATCH] Use console and override evaluator --- lib/dashboard/repl.js | 30 ++++++++++++++++-------------- lib/index.js | 7 ++++++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/dashboard/repl.js b/lib/dashboard/repl.js index 28129bed..8f23b586 100644 --- a/lib/dashboard/repl.js +++ b/lib/dashboard/repl.js @@ -1,34 +1,36 @@ const repl = require("repl"); +const Console = require('./console.js'); + class REPL { constructor(options) { this.env = options.env; this.plugins = options.plugins; + this.events = options.events; + this.console = new Console({ + events: this.events, + plugins: this.plugins, + version: options.version + }); + } + + enhancedEval(cmd, context, filename, callback) { + this.console.executeCmd(cmd.trim(), (result) => { + callback(null, result); + }); } start(done) { this.replServer = repl.start({ prompt: "Embark (" + this.env + ") > ", - useGlobal: true + useGlobal: true, + eval: this.enhancedEval.bind(this) }); this.replServer.on("exit", () => { process.exit(); }); - let self = this; - this.replServer.defineCommand('profile', { - help: 'Profile a contract', - action(contract) { - this.clearBufferedCommand(); - let pluginCmds = self.plugins.getPluginsProperty('console', 'console'); - for (let pluginCmd of pluginCmds) { - pluginCmd.call(self, `profile ${contract}`, {}); - } - this.displayPrompt(); - } - }); - done(); } diff --git a/lib/index.js b/lib/index.js index 3db589bc..455deeb6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -284,7 +284,12 @@ class Embark { }); }, function startREPL(callback) { - let repl = new REPL({env: engine.env, plugins: engine.plugins}); + let repl = new REPL({ + env: engine.env, + plugins: engine.plugins, + version: engine.version, + events: engine.events + }); repl.start(callback); } ], function (err, _result) {