-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·56 lines (45 loc) · 1.03 KB
/
cli.js
File metadata and controls
executable file
·56 lines (45 loc) · 1.03 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
#!/usr/bin/env node
'use strict';
const api = require('./api');
const chalk = require('chalk');
const dns = require('dns');
const logUpdate = require('log-update');
const meow = require('meow');
const ora = require('ora');
// help
meow(`
Usage
$ happy
`);
// check connection
dns.lookup('fast.com', err => {
if (err && err.code === 'ENOTFOUND') {
console.log(chalk.red('\n Please check you internet connection.\n'));
process.exit(1);
}
});
// variables and functions
let data = {};
const spinner = ora();
const news = () => chalk.cyan('* ' + data.news[0] + '\n* ' + data.news[1] + '\n* ' + data.news[2]);
function exit() {
logUpdate('\n' + news() + '\n' + chalk.cyan.dim('Source: http://www.sunnyskyz.com/good-news\n'));
process.exit();
}
// update value
setInterval(() => {
const pre = '\n ' + chalk.gray.dim(spinner.frame()) + chalk.cyan(' Getting fresh happy news!\n');
if (!data.isDone) {
logUpdate(pre);
return;
} else {
exit();
}
}, 100);
// api
api((err, result) => {
if (err) {
throw err;
}
data = result;
});