mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-09 21:46:12 +00:00
47dcb1552c
Add persistent automatically loaded history file for repl console and Embark dashboard. Default location of the history file is stored in DEFAULT_CMD_HISTORY_PATH pointing to DAPP_PATH/.embark/cmd_history. The history is automatically saved and loaded on startup. test/console: Pass Embark object to constructor. Update console test to pass Embark object to constructor. Refs: https://github.com/embark-framework/embark/issues/939
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
const repl = require("repl");
|
|
const util = require("util");
|
|
let fs = require('../../lib/core/fs');
|
|
|
|
class REPL {
|
|
constructor(options) {
|
|
this.events = options.events;
|
|
this.env = options.env;
|
|
}
|
|
|
|
enhancedEval(cmd, context, filename, callback) {
|
|
this.events.request('console:executeCmd', cmd.trim(), function (err, message) {
|
|
callback(err, message || ''); // This way, we don't print undefined
|
|
});
|
|
}
|
|
|
|
enhancedWriter(output) {
|
|
if ((typeof output) === "string") {
|
|
return output;
|
|
}
|
|
return util.inspect(output, {colors: true});
|
|
}
|
|
|
|
start(done) {
|
|
this.replServer = repl.start({
|
|
prompt: "Embark (" + this.env + ") > ",
|
|
useGlobal: true,
|
|
eval: this.enhancedEval.bind(this),
|
|
writer: this.enhancedWriter.bind(this)
|
|
});
|
|
|
|
this.events.request('console:history', (err, history) => {
|
|
history
|
|
.split('\n')
|
|
.forEach((cmd) => { this.replServer.history.push(cmd); });
|
|
});
|
|
|
|
this.events.request("runcode:getContext", (context) => {
|
|
this.replServer.context = context;
|
|
});
|
|
|
|
this.replServer.on("exit", () => {
|
|
process.exit();
|
|
});
|
|
|
|
done();
|
|
}
|
|
}
|
|
|
|
module.exports = REPL;
|