-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.js
51 lines (41 loc) · 2.28 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
44
45
46
47
48
49
50
51
// # repl.js
// Provides an interactive environment for testing SWEETnet components.
var colors = require('colors');
var repl = require('repl');
var fs = require('fs');
var vm = require('vm');
var readline = require('readline');
var hasAnsi = require('has-ansi');
var stripAnsi = require('strip-ansi');
// http://stackoverflow.com/questions/23569878/adding-color-to-repl-prompt-node
var _setPrompt = readline.Interface.prototype.setPrompt;
readline.Interface.prototype.setPrompt = function() {
if (arguments.length === 1 && hasAnsi(arguments[0])) {
return _setPrompt.call(this, arguments[0], stripAnsi(arguments[0]).length);
} else {
return _setPrompt.apply(this, arguments);
}
};
console.log('Welcome to ' + 'SWEET'.bold + 'net! Type ' + 'help()'.underline +
' for help.');
console.log('=========================================='.rainbow);
var SWEETrepl = repl.start('SWEETnet'.blue + ' $ ');
vm.runInContext(fs.readFileSync('./util/repl_setup.js', 'utf8'), SWEETrepl.context);
SWEETrepl.context.help = function () {
console.log('================================================================================'.rainbow);
console.log('SWEET'.bold + 'net Online Help 🌺');
console.log('\nThis repl is just an enhanced node repl with some handy objects preloaded,');
console.log('think of this as a shell into the SWEETnet system. Some of the objects include:');
console.log('\n\t' + 'config'.bold + ' - the configuration file defined at the root of the project');
console.log('\t' + 'bot.create(name)'.bold + ' - creates a bot with given name');
console.log('\nThe server objects are all provided:');
console.log('\n\t' + 'apiServer'.bold);
console.log('\t' + 'messageServer'.bold);
console.log('\t' + 'videoServer'.bold);
console.log('\nEach of these has a listen and start method. The listen method takes a port as');
console.log('argument and starts the server. The start method starts the server an the port');
console.log('as given in the configuration file.');
console.log('\nb1, b2, b3, b4 are preconstructed bots for testing.');
console.log('\nTab complete can be used to explore methods on these objects.');
console.log('================================================================================'.rainbow);
};