forked from next-in-line/longtrail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.js
More file actions
59 lines (46 loc) · 1.31 KB
/
Copy pathrepl.js
File metadata and controls
59 lines (46 loc) · 1.31 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//const clearRequire = require('clear-require')
require('app-module-path').addPath(__dirname);
const Immutable = require('seamless-immutable')
var os = require('os');
var path = require('path');
var historyFile = path.join(os.homedir(), '.node_history');
var repl = require('repl').start('longtrail> ');
const reload = (context)=>{
/**
* Removes a module from the cache.
*
};
/*
* Load a module, clearing it from the cache if necessary.
*/
for(let key of Object.keys(require.cache)){
if(key.includes('shark/src')){
delete require.cache[key]
}
if(key.includes('shark/lib')){
delete require.cache[key]
}
if(key.includes('shark/helpers')){
delete require.cache[key]
}
if(key.includes('shark/db')){
delete require.cache[key]
}
if(key.includes('shark/config')){
delete require.cache[key]
}
}
context.app = require('./src')
return context
}
reload(repl.context)
repl.defineCommand('reload', {
help: 'Reload application "src" and set it to app',
action(name) {
this.clearBufferedCommand();
this.context = reload(this.context);
this.displayPrompt();
}
})
repl.on('reset', reload);
require('repl.history')(repl, historyFile);