Environment variable for REPL startup file #1693

Closed
wants to merge 5 commits into
from
View
@@ -55,6 +55,9 @@ If set to 1 then colors will not be used in the REPL.
.IP NODE_USE_UV
If set to 1 then Node will use the new libuv-based backend.
+.IP NODE_STARTUP
+If set to the name of a file then the REPL will try to execute this file at startup
+
.SH V8 OPTIONS
--crankshaft (use crankshaft)
View
@@ -107,8 +107,26 @@
var Module = NativeModule.require('module');
if (NativeModule.require('tty').isatty(fd)) {
+
// REPL
- Module.requireRepl().start();
+ var ctx = Module.requireRepl().start().context;
+
+ var stup = process.env.NODE_STARTUP;
+ if (stup) {
+ var path = NativeModule.require('path');
+ var fs = NativeModule.require('fs');
+ var vm = NativeModule.require('vm');
+
+ path.exists(stup, function(exists) {
+ if (exists) {
+ fs.readFile(stup, function(err, data) {
+ if (! err) {
+ vm.runInContext(data.toString('utf8'), ctx);
+ }
+ });
+ }
+ });
+ }
} else {
// Read all of stdin - execute it.