-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·82 lines (72 loc) · 2.04 KB
/
index.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
#!/usr/bin/env node
const fetch = require('node-fetch');
const open = require('open');
const arg = require('arg');
const inquirer = require('inquirer');
function ParseCliArgsIntoOptions() {
const args = arg(
{
'--website': Boolean,
'--yes': Boolean,
'-w': '--website',
'-y': '--yes',
},
{
argv: process.argv.slice(2),
}
);
return {
website: args['--website'] || false,
};
}
async function PromptForOptions(options) {
const questions = [];
if (!options.website) {
questions.push({
type: 'confirm',
name: 'website',
message: 'Open the website on your browser?',
default: false,
});
}
const answers = await inquirer.prompt(questions);
return {
...options,
website: options.website || answers.website,
};
}
async function LaunchWebsite(result) {
let options = ParseCliArgsIntoOptions();
options = await PromptForOptions(options);
if (options.website == true) {
open(`https://${result.domain}`);
}
}
const website = process.argv[2];
function CheckWeb(name) {
if (name.indexOf('.') > -1) {
const info = fetch(`https://isitup.org/${name}.json`)
.then(response => response.json());
info.then(function (result) {
if (result.response_code == 200) {
console.log('\x1b[32m%s\x1b[0m', 'website is up and running');
LaunchWebsite(result)
} else if (result.response_code == 301) {
console.log('\x1b[32m%s\x1b[0m', 'website has been moved permanently but is up');
LaunchWebsite(result)
} else if (result.response_code == 302) {
console.log('\x1b[34m%s\x1b[0m', 'temporary redirect, website is up');
LaunchWebsite(result)
} else if (result.response_code == 403) {
console.log('\x1b[33m%s\x1b[0m', 'information not found');
LaunchWebsite(result)
}
else {
console.log('\x1b[31m%s\x1b[0m', 'website is down')
}
});
} else {
console.log('\x1b[31m%s\x1b[0m', 'please append your url extension e.g(mouse.com)')
}
}
CheckWeb(website);