@@ -1,16 +1,24 @@
1−const repl = require('repl');
1+const repl = require("repl");
2−const path = require('path');
2+const path = require("path");
3−const fs = require('fs');
3+const fs = require("fs");
4−const vm = require('vm');
4+const vm = require("vm");
5−const rl = require(path.join(process.cwd(), 'prybar_assets', 'nodejs', 'readline-sync.js'));
5+const rl = require(path.join(
6−const tty = require('tty');
11+const tty = require("tty");
7−const Module = require('module');
12+const Module = require("module");
15+if (!process.env.PRYBAR_QUIET) {
16+ console.log("Node " + process.version + " on " + process.platform);
11// Red errors.
19// Red errors.
12function logError(msg) {
20function logError(msg) {
13− process.stdout.write('\u001b[0m\u001b[31m' + msg + '\u001b[0m');
21+ process.stdout.write("\u001b[0m\u001b[31m" + msg + "\u001b[0m");
16// The nodejs repl operates in raw mode and does some funky stuff to
24// The nodejs repl operates in raw mode and does some funky stuff to
@@ -42,17 +50,17 @@ function handleError(e) {
42 r.lastError = e;
50 r.lastError = e;
45− if (e && typeof e === 'object' && e.stack && e.name) {
53+ if (e && typeof e === "object" && e.stack && e.name) {
46− if (e.name === 'SyntaxError') {
54+ if (e.name === "SyntaxError") {
47 e.stack = e.stack
55 e.stack = e.stack
48− .replace(/^repl:\d+\r?\n/, '')
56+ .replace(/^repl:\d+\r?\n/, "")
49− .replace(/^\s+at\s.*\n?/gm, '');
57+ .replace(/^\s+at\s.*\n?/gm, "");
52 logError(e.stack);
60 logError(e.stack);
54 // For some reason needs a newline to flush.
62 // For some reason needs a newline to flush.
55− logError('Thrown: ' + r.writer(e) + '\n');
63+ logError("Thrown: " + r.writer(e) + "\n");
@@ -64,18 +72,18 @@ function handleError(e) {
65function start(context) {
73function start(context) {
66 r = repl.start({
74 r = repl.start({
67− prompt: process.env.NODE_PROMPT,
75+ prompt: process.env.PRYBAR_PS1,
69 if (context) r.context = context;
77 if (context) r.context = context;
71 // remove the internal error and ours for red etc.
79 // remove the internal error and ours for red etc.
72− r._domain.removeListener('error', r._domain.listeners('error')[0]);
80+ r._domain.removeListener("error", r._domain.listeners("error")[0]);
73− r._domain.on('error', handleError);
81+ r._domain.on("error", handleError);
74− process.on('uncaughtException', handleError);
82+ process.on("uncaughtException", handleError);
77global.alert = console.log;
85global.alert = console.log;
78−global.prompt = p => {
86+global.prompt = (p) => {
79 pauseRepl();
87 pauseRepl();
80 clearLine();
88 clearLine();
@@ -91,7 +99,7 @@ global.prompt = p => {
91 return ret;
99 return ret;
94−global.confirm = q => {
102+global.confirm = (q) => {
95 pauseRepl();
103 pauseRepl();
96 clearLine();
104 clearLine();
@@ -103,13 +111,23 @@ global.confirm = q => {
103 if (r) setImmediate(() => r.displayPrompt());
111 if (r) setImmediate(() => r.displayPrompt());
104 return ret;
112 return ret;
115+if (process.env.PRYBAR_CODE) {
116+ vm.runInThisContext(process.env.PRYBAR_CODE);
117+ if (process.env.PRYBAR_INTERACTIVE) {
120+} else if (process.env.PRYBAR_EXP) {
106−console.log(process.argv)
121+ console.log(vm.runInThisContext(process.env.PRYBAR_EXP));
107−if (process.argv[2]) {
122+ if (process.env.PRYBAR_INTERACTIVE) {
125+} else if (process.env.PRYBAR_FILE) {
108− const mainPath = path.resolve(process.argv[2]);
126+ const mainPath = path.resolve(process.env.PRYBAR_FILE);
109− const main = fs.readFileSync(mainPath, 'utf-8');
127+ const main = fs.readFileSync(mainPath, "utf-8");
110 const module = new Module(mainPath, null);
128 const module = new Module(mainPath, null);
112− module.id = '.';
130+ module.id = ".";
113 module.filename = mainPath;
131 module.filename = mainPath;
114 module.paths = Module._nodeModulePaths(path.dirname(mainPath));
132 module.paths = Module._nodeModulePaths(path.dirname(mainPath));
@@ -136,7 +154,7 @@ if (process.argv[2]) {
138 console.log(
156 console.log(
139− '\u001b[0m\u001b[90mHint: hit control+c anytime to enter REPL.\u001b[0m',
157+ "\u001b[0m\u001b[90mHint: hit control+c anytime to enter REPL.\u001b[0m"
141 const context = vm.createContext(sandbox);
159 const context = vm.createContext(sandbox);
@@ -162,14 +180,15 @@ if (process.argv[2]) {
163 module.loaded = true;
181 module.loaded = true;
165− if (typeof res !== 'undefined') {
183+ if (typeof res !== "undefined") {
166 console.log(res);
184 console.log(res);
188+ if (process.env.PRYBAR_INTERACTIVE) {
170− process.on('SIGINT', () => start(context));
189+ process.once("SIGINT", () => start(context));
172− process.on('beforeExit', () => start(context));
190+ process.once("beforeExit", () => start(context));
192+} else if (process.env.PRYBAR_INTERACTIVE) {