Skip to content

Instantly share code, notes, and snippets.

@Orion98MC
Created September 2, 2011 08:35
Show Gist options
  • Save Orion98MC/1188186 to your computer and use it in GitHub Desktop.
Save Orion98MC/1188186 to your computer and use it in GitHub Desktop.
var fs = require('fs'), vm = require('vm'), path = require('path');
var repl = require('repl');
// Add source ability
repl.REPLServer.prototype.source = function (file) {
if (!~file.indexOf('.')) file += '.js';
if (path.existsSync(file)) {
vm.runInContext(fs.readFileSync(file).toString(), this.context);
} else {
this.outputStream.write('ERROR: file not found "' + file + '"\n');
}
this.displayPrompt();
}
var server = repl.start();
// In REPL "./ file" will source "file.js"
server.defineCommand('/', {
help: 'Source file',
action: function (file) {
this.source(file);
}
});
// From command line arguments
for (var i = 2; i < process.argv.length; i++) {
server.source(process.argv[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment