embark/cmd/dashboard/repl.js

43 lines
892 B
JavaScript
Raw Normal View History

2018-07-23 12:30:58 +00:00
const repl = require("repl");
2018-07-26 15:56:50 +00:00
const util = require("util");
2018-07-23 12:30:58 +00:00
class REPL {
constructor(options) {
2018-07-26 15:00:25 +00:00
this.events = options.events;
2018-08-31 08:24:45 +00:00
this.env = options.env
2018-07-26 15:00:25 +00:00
}
enhancedEval(cmd, context, filename, callback) {
2018-08-31 08:24:45 +00:00
this.events.request('console:executeCmd', cmd.trim(), callback);
2018-07-23 12:30:58 +00:00
}
2018-07-26 15:56:50 +00:00
enhancedWriter(output) {
if ((typeof output) === "string") {
return output;
} else {
return util.inspect(output, {colors: true});
}
}
2018-07-23 12:30:58 +00:00
start(done) {
2018-07-23 16:05:01 +00:00
this.replServer = repl.start({
2018-07-24 08:40:48 +00:00
prompt: "Embark (" + this.env + ") > ",
2018-07-26 15:00:25 +00:00
useGlobal: true,
2018-07-26 15:56:50 +00:00
eval: this.enhancedEval.bind(this),
writer: this.enhancedWriter.bind(this)
2018-07-23 12:30:58 +00:00
});
2018-08-24 13:05:19 +00:00
this.events.request("runcode:getContext", (context) => {
this.replServer.context = context;
});
2018-07-23 16:05:01 +00:00
this.replServer.on("exit", () => {
2018-07-23 12:41:13 +00:00
process.exit();
});
2018-07-23 12:30:58 +00:00
done();
}
2018-07-23 16:05:01 +00:00
2018-07-23 12:30:58 +00:00
}
module.exports = REPL;