-
Notifications
You must be signed in to change notification settings - Fork 1
/
console.js
33 lines (26 loc) · 856 Bytes
/
console.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
const repl = require('repl')
const path = require('path')
const glob = require('glob')
const history = require('repl.history')
var historyFile = path.join(__dirname, '.node_history')
// Load all modules in src
function loadVariables () {
const AllJsFilesPattern = path.join(__dirname, './lib/**/*.js')
const allSrcFiles = glob.sync(AllJsFilesPattern)
return allSrcFiles.reduce(function (contextSum, file) {
const module = path.basename(file, '.js')
contextSum[module] = require(file)
return contextSum
}, {})
}
const initialContext = loadVariables()
const replServer = repl.start({
terminal: true,
prompt: 'Perezoso Console > '
})
history(replServer, historyFile)
Object.assign(replServer.context, initialContext)
function reload () {
Object.assign(replServer.context, loadVariables())
}
replServer.context.reload = reload