From 3e328801db855183bdb621e761e5c569abe75d4c Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 23 Jul 2018 17:05:01 +0100 Subject: [PATCH] nodashboard start a repl --- lib/coderunner/runCode.js | 7 ++++++- lib/dashboard/repl.js | 10 ++++++++-- lib/index.js | 9 ++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/coderunner/runCode.js b/lib/coderunner/runCode.js index 9560eec1f..7d0104107 100644 --- a/lib/coderunner/runCode.js +++ b/lib/coderunner/runCode.js @@ -23,8 +23,13 @@ function registerVar(varName, code) { __mainContext[varName] = code; } +function getContext() { + return __mainContext; +} + module.exports = { doEval: doEval, registerVar: registerVar, - initContext: initContext + initContext: initContext, + getContext: getContext }; diff --git a/lib/dashboard/repl.js b/lib/dashboard/repl.js index f416bc941..1dd5181f6 100644 --- a/lib/dashboard/repl.js +++ b/lib/dashboard/repl.js @@ -1,4 +1,5 @@ const repl = require("repl"); +const RunCode = require('../coderunner/runCode'); class REPL { constructor(options) { @@ -6,16 +7,21 @@ class REPL { } start(done) { - let replServer = repl.start({ + this.replServer = repl.start({ prompt: "Embark (" + this.env + ") > " }); + this.initializeContext(this.replServer.context); - replServer.on('exit', () => { + this.replServer.on("exit", () => { process.exit(); }); done(); } + + initializeContext(context) { + context.embark = RunCode.getContext(); + } } module.exports = REPL; diff --git a/lib/index.js b/lib/index.js index 4f430cb03..63a2beb25 100644 --- a/lib/index.js +++ b/lib/index.js @@ -155,7 +155,14 @@ class Embark { }); } engine.startService("fileWatcher"); - callback(); + + if (!options.useDashboard) { + const REPL = require('./dashboard/repl.js'); + let repl = new REPL({env: engine.env}); + repl.start(function () { + callback(); + }); + } } ], function (err, _result) { if (err) {