-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrepl.js
43 lines (43 loc) · 1.09 KB
/
repl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use strict";
const args = process.argv;
for (var index = 0; index < args.length; index++) {
if (args[index]=="-l" || args[index]=="--legacy") {
require("./cli.js");
return;
}
}
const repl = require('repl');
const fs = require('fs');
const path = require("path");
const vt = require("./code.js");
const firstDirectory = process.cwd();
const replServer = repl.start({prompt: '> '});
replServer.defineCommand('pwd', {
help: 'Prints the working directory.',
action(garbage) {
this.lineParser.reset();
this.bufferedCommand = '';
console.log(process.cwd());
this.displayPrompt();
}
});
replServer.defineCommand('cd', {
help: 'Sets the working directory.',
action(input) {
if (input=="") {
this.lineParser.reset();
this.bufferedCommand = '';
process.chdir(firstDirectory);
this.displayPrompt();
return;
}
this.lineParser.reset();
this.bufferedCommand = '';
if (path.isAbsolute(input)) {
process.chdir(input);
} else {
process.chdir(path.normalize(path.join(process.cwd(), input)));
}
this.displayPrompt();
}
});