-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·60 lines (47 loc) · 1.46 KB
/
cli.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
#!/usr/bin/env node
'use strict';
const dns = require('dns');
const chalk = require('chalk');
const got = require('got');
const logUpdate = require('log-update');
const ora = require('ora');
const updateNotifier = require('update-notifier');
const pkg = require('./package.json');
updateNotifier({pkg}).notify();
const arg = process.argv[2];
const spinner = ora();
if (!arg || arg === '-h' || arg === '--help') {
console.log(`
Down for everyone or just me?
${chalk.cyan('Usage')} : izup <website>
${chalk.cyan('Help')} : izup google.com
`);
process.exit(1);
}
const getHostName = url => {
const match = url.match(/:\/\/(www[/\d]?\.)?(.[^/:]+)/i);
if (match !== null && match.length > 2 && typeof match[2] === 'string' && match[2].length > 0) {
return match[2];
}
return url;
};
dns.lookup('downforeveryoneorjustme.com', err => {
if (err) {
logUpdate(`\n${chalk.red.bold('›')} ${chalk.dim('Please check your internet connection!')}\n`);
} else {
logUpdate();
spinner.text = 'Please wait';
spinner.start();
const url = getHostName(arg);
got(`http://downforeveryoneorjustme.com/${url}`).then(res => {
const a = res.body;
const b = a.split('down?</h1>')[1].split('<a href="')[0].trim().split('<p>')[1].split('<a')[0].trim();
if (b === `It's just you.`) {
logUpdate(`\n ${chalk.cyan.bold('✔')} No kidding. It's up!\n`);
} else {
logUpdate(`\n ${chalk.red.bold('✖')} Can't do anything. It's down!\n`);
}
spinner.stop();
});
}
});