-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlazyterminal.js
343 lines (267 loc) · 10.6 KB
/
lazyterminal.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/**
* Include required modules here
*
*/
const boganipsum = require("boganipsum");
const colors = require("colors");
const progress = require("cli-progress");
const lodash = require("lodash");
var readline = require("readline");
/**
* Main Application Wrapper
*
* @return object
*/
const lazyterminal = {
/**
* All possible answers to user prompt
*
* @return array
*/
possibleAnswers: ["slow", "medium", "fast", "random"],
/**
* Boot up the console app here
*
* @return function
*/
startApp: function(){
console.info("\n Welcome, you lazy piece of shit!".green);
this.askTheQuestionAndGetAnAnswer();
},
/**
* Handle user prompt and prompt validation, if user input is valid then we start working
*
* @return function
*/
askTheQuestionAndGetAnAnswer: function(){
var question = " Press ENTER for random speed".green + " (or type slow, medium or fast): ";
var rl = null;
rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question(question, (answer) => {
rl.close()
if (answer.length===0) {
return this.startWorking(answer);
} else {
return this.possibleAnswers.includes(answer) ? this.startWorking(answer) : this.askTheQuestionAndGetAnAnswer();
}
});
},
/**
* Using this function, we quickly decide if to show a random line or progress bar
*
* @return function
*/
startWorking: function(speed) {
var type = lodash.sample(["line", "progress"]);
type == "line" ? this.showLine(speed) : this.showProgress(speed);
},
/**
* Using this function, we generate a random line with zero meaning lol
*
* @return function
*/
showLine: function(speed){
var randomMessage = this.getMessage();
var randomColor = this.getColor();
var randomStatus = this.getStatus();
var randomModule = this.getModule();
var randomDate = this.getFormattedDate();
console.log(randomDate+ " " +randomModule.grey + " " + randomStatus.magenta + " " + randomMessage[randomColor]);
setTimeout(() => {
this.startWorking(speed);
}, this.getShortTime(speed));
},
/**
* Using this function, we show a random progress bar using various presets
*
* @return function
*/
showProgress: function(speed){
theme = 'shades-classic';
const bar = new progress.SingleBar({
}, progress.Presets[lodash.sample(['rect', 'legacy', 'shades-classic'])]);
var meter = lodash.random(10, 80);
bar.start(100, meter);
setInterval(() => {
bar.update(meter += lodash.random(10, 20));
}, lodash.random(50, 100));
setTimeout(() => {
bar.stop();
this.startWorking(speed);
}, this.getShortTime(speed));
},
/**
* Using this function, we get a random message line to display on our console
*
* @return function
*/
getMessage: function(){
var senteces = [
"it worked if it ends with ok",
"cli [ 'node', '" + this.getSystemInfos() + "', 'install', '--verbose' ]",
"using [email protected] " + this.getSystemInfos(),
"using [email protected]",
"readDependencies using package.json deps",
"install where, deps " + this.getSystemInfos() + ", [ '" + this.getNodePackage() + "' ] ]",
"readDependencies using package.json deps",
"already installed skipping " + this.getNodePackage() + "@" + this.getVersion(),
"already installed skipping [email protected] " + this.getSystemInfos(),
"build /Users/samuel/Documents/bebusy",
"linkStuff [ false, false, false, '/Users/samuel/Documents' ]",
"rebuildBundles " + this.getNodePackage() + "@" + this.getVersion(),
"rebuildBundles [ '.bin', 'boganipsum', 'colors' ]",
"install " + this.getNodePackage() + "@" + this.getVersion(),
"postinstall " + this.getNodePackage() + "@" + this.getVersion(),
"prepublish " + this.getNodePackage() + "@" + this.getVersion(),
"preinstall " + this.getNodePackage() + "@" + this.getVersion(),
"linkStuff " + this.getNodePackage() + "@" + this.getVersion(),
"linkBins " + this.getNodePackage() + "@" + this.getVersion(),
"linkMans " + this.getNodePackage() + "@" + this.getVersion(),
"exit [ 0, true ]",
"ok",
"etag " + this.getHexNumber()
];
return lodash.sample(senteces);
},
/**
* Using this function, we grab some info about the user's enviroment so it looks more realistic
*
* @return function
*/
getSystemInfos: function(){
var env = process.env;
var systemPaths = [ env.TMPDIR, env.PATH, env.PWD, env.HOME ];
return lodash.sample(systemPaths);
},
/**
* Using this function, we generate a random version number - we follow semantic versioning :-)
*
* @return function
*/
getVersion: function(){
var mayorV = lodash.random(1, 9);
var minorV = lodash.random(1, 9);
var devV = lodash.random(1, 9);
return "v" + mayorV + "." + minorV + "." + devV;
},
/**
* Using this function, we generate a random hexcode
*
* @return function
*/
getHexNumber: function(){
var stringSize = 60;
var generatedHexString = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i=0; i<stringSize; i++){
generatedHexString += possible.charAt(Math.floor(Math.random() * possible.length));
}
return generatedHexString;
},
/**
* Using this function, we determine our pace based on the input we got from the user, remember?
*
* @return function
*/
getShortTime: function(speed){
if (speed==="fast") {
return lodash.random(1, 5) * 5;
} else if (speed==="medium") {
return lodash.random(5, 10) * 10;
} else if (speed==="slow") {
return lodash.random(10, 20) * 15;
} else if (speed==="random") {
return lodash.random(1, 20) * 20;
}
},
/**
* Using this function, we get a random module command/action name
*
* @return function
*/
getModule: function(){
var modules = [
"npm", "install", "download", "parse", "ok", "verb", "WARN", "info"
];
return lodash.sample(modules);
},
/**
* Using this function, we get the name of random package to display in the commandline
*
* @return function
*/
getNodePackage: function(){
var modules = [
"axios", "lodash", "sentry-cli", "babel", "nodemon", "mongoose", "underscore", "async", "request", "lodash", "commander", "express", "optimist", "colors", "coffee-script",
"mkdirp", "debug", "q", "chalk", "yeoman-generator", "moment", "glob", "through2", "jade", "uglify-js",
"socket.io", "gulp-util", "redis", "cheerio", "through", "node-uuid", "connect", "winston", "mime",
"minimist", "bluebird", "grunt", "handlebars", "mongodb", "rimraf", "semver", "ejs", "mongoose", "marked",
"xml2js", "lodash.string", "fs-extra", "mocha", "js-yaml", "superagent", "less", "extend", "esprima",
"jquery", "stylus", "body-parser", "xtend", "jsdom", "event-stream", "shelljs", "minimatch", "prompt",
"browserify", "wrench", "ws", "mysql", "readable-stream", "yosay", "inherits", "when", "pkginfo",
"backbone", "nopt", "cli-color", "concat-stream", "passport", "nodemailer", "gulp", "chai", "inquirer",
"nconf", "validator", "yargs", "mustache", "qs", "clean-css", "npm", "ncp", "should", "open", "aws-sdk",
"graceful-fs", "temp", "http-proxy", "iconv-lite", "requirejs", "socket.io-client", "hiredis", "uuid",
"promise", "escodegen", "bower", "oauth", "log4js", "cli-table"
];
return lodash.sample(modules);
},
/**
* Using this function, we fetch a random status for the current operation to display in the commandline
*
* @return function
*/
getStatus: function(){
var allColors = [
"100 Continue", "101 Switching Protocols", "102 Processing", "200 OK", "201 Created", "202 Accepted",
"203 Non-Authoritative Information", "204 No Content", "205 Reset Content", "206 Partial Content",
"207 Multi-Status", "208 Already Reported", "226 IM Used (RFC 3229)", "300 Multiple Choices",
"301 Moved Permanently", "302 Found", "303 See Other", "304 Not Modified", "305 Use Proxy",
"306 Switch Proxy", "307 Temporary Redirect", "308 Permanent Redirect", "prepublish", "postinstall",
"install", "rebuildBundles", "linkMans", "linkBins", "linkStuff", "install", "about to build", "addNamed",
"lock", "etag", "parsed url", "search", "query", "host", "auth", "slashes", "cache add", "GET", "POST",
"trying", "installOne", "tar unpack"
];
return lodash.sample(allColors);
},
/**
* Using this function, we fetch a random color to format our output on the console
*
* @return function
*/
getColor: function(){
var allColors = [ "white", "grey", "green", "blue", "cyan", "white", "gray" ];
return lodash.sample(allColors);
},
/**
* Using this function, we generate some random text. I mean how do we even start without doing that? :-)
*
* @return function
*/
generateIpsum: function(){
for (var i=0; i<1000; i++){
console.log( boganipsum({ sentenceMin: 200, sentenceMax: 205 }) );
}
},
/**
* Using this function, we fetch and output the current time to make it look even more realsitic
*
* @return function
*/
getFormattedDate: function(){
var date = new Date();
var leadingZero = function(nmbr){
if (nmbr<10) { return ("0" + nmbr) } else { return nmbr }
};
var formattedTime = "";
formattedTime += leadingZero( date.getHours() );
formattedTime += ":" + leadingZero( date.getMinutes() );
formattedTime += ":" + leadingZero( date.getSeconds() );
return formattedTime;
},
}
//Of course, we need to export :)
module.exports = lazyterminal