From 8663dd51d69e6097e2f29eff4dd5e4bdfb7d0203 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 17 Nov 2023 16:44:34 +0000 Subject: [PATCH] Initial commit Thanks @PotOfCoffee2Go --- core/modules/commands/jsrepl.js | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 core/modules/commands/jsrepl.js diff --git a/core/modules/commands/jsrepl.js b/core/modules/commands/jsrepl.js new file mode 100644 index 000000000..91f9ee9c9 --- /dev/null +++ b/core/modules/commands/jsrepl.js @@ -0,0 +1,46 @@ +/*\ +title: $:/core/modules/commands/jsrepl.js +type: application/javascript +module-type: command + +Command to launch node.js REPL with access to $tw + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +exports.info = { + name: "jsrepl", + synchronous: true +}; + +var Command = function(params,commander,callback) { + var self = this; + this.params = params; + this.commander = commander; + this.callback = callback; +}; + +Command.prototype.execute = function() { + var self = this; + var repl = require("repl"); + this.runtime = repl.start({ + prompt: this.params.length ? this.params[0] : "$tw-jsrepl> ", + useColors: true, + ignoreUndefined: true + }); + // If REPL is reset (.clear) - context needs resetting + this.runtime.on("reset", function() { + self.runtime.context.$tw = $tw; + }); + // Initial context settings + this.runtime.context.$tw = $tw; + return null; +}; + +exports.Command = Command; + +})(); \ No newline at end of file