-
Notifications
You must be signed in to change notification settings - Fork 133
/
repl
executable file
·38 lines (32 loc) · 822 Bytes
/
repl
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
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var repl = require('repl');
var r = repl.start('> ');
var c = r.context;
c._load = function () {
c.Segment = require('./');
var segment = new c.Segment();
segment.useDefault();
c.segment = segment;
c.s = function () {
return c.segment.doSegment.apply(c.segment, arguments);
};
c.ss = function () {
var list = c.s.apply(null, arguments);
return list.map(function (v) { return v.w; }).join('/');
};
};
c.reload = function () {
var t = Date.now();
var dir = path.resolve(__dirname) + path.sep;
for (var i in require.cache) {
if (i.indexOf(dir) === 0) {
delete require.cache[i];
// console.log('delete %s', i);
}
}
c._load();
console.log('OK. (spent %sms)', Date.now() - t);
}
c._load();