Skip to content

Commit 5e6fbac

Browse files
committed
👌 IMPROVE: Infra + messaging
1 parent 779464c commit 5e6fbac

File tree

8 files changed

+122
-95
lines changed

8 files changed

+122
-95
lines changed

index.js

Lines changed: 15 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,105 +7,30 @@ process.on('unhandledRejection', err => {
77
handleError(`UNHANDLED ERROR`, err);
88
});
99

10-
const chalk = require('chalk');
11-
const axios = require('axios');
1210
const Table = require('cli-table3');
13-
const comma = require('comma-number');
1411
const cli = require('./utils/cli.js');
15-
const welcome = require('cli-welcome');
16-
const pkgJSON = require('./package.json');
17-
const logSymbols = require('log-symbols');
12+
const init = require('./utils/init.js');
13+
const getAll = require('./utils/getAll.js');
14+
const theEnd = require('./utils/theEnd.js');
1815
const handleError = require('cli-handle-error');
19-
const updateNotifier = require('update-notifier');
16+
const getCountry = require('./utils/getCountry.js');
17+
const getWorldwide = require('./utils/getWorldwide.js');
18+
const { single, colored, style } = require('./utils/table.js');
2019
const xcolor = cli.flags.xcolor;
21-
const green = chalk.green;
22-
const red = chalk.red;
23-
const dim = chalk.dim;
2420

2521
(async () => {
26-
welcome(
27-
`corona-cli`,
28-
`by Awais.dev\n${pkgJSON.description}\n\n${dim(
29-
`Stargaze the repo for updates ↓\nhttps://github.com/ahmadawais/corona-cli`
30-
)}`,
31-
{
32-
bgColor: `#007C91`,
33-
color: `#FFFFFF`,
34-
bold: true,
35-
clear: true,
36-
version: `v${pkgJSON.version}`
37-
}
38-
);
39-
updateNotifier({
40-
pkg: pkgJSON,
41-
shouldNotifyInNpmScript: true
42-
}).notify({ isGlobal: true });
43-
4422
// Init.
23+
init();
4524
const [country] = cli.input;
4625

47-
const headSingle = [
48-
`Country`,
49-
`Cases`,
50-
`Cases ${dim(`(today)`)}`,
51-
`Deaths`,
52-
`Deaths ${dim(`(today)`)}`,
53-
`Recovered`,
54-
`Active`,
55-
`Critical`,
56-
`Per Million`
57-
];
58-
59-
const headColored = [
60-
`Country`,
61-
`Cases`,
62-
`Cases ${dim(`(today)`)}`,
63-
`${red(`Deaths`)}`,
64-
`${red(`Deaths (today)`)}`,
65-
`${green(`Recovered`)}`,
66-
`Active`,
67-
`${red(`Critical`)}`,
68-
`Per Million`
69-
];
70-
71-
const head = xcolor ? headSingle : headColored;
72-
const table = new Table({
73-
head,
74-
style: { head: ['cyan'] }
75-
});
76-
77-
// Overall.
78-
const all = await axios.get(`https://corona.lmao.ninja/all`);
79-
let data = Object.values(all.data);
80-
data = data.map(d => comma(d));
81-
table.push([`Worldwide`, data[0], `—`, data[1], `—`, data[2], `—`, `—`, `—`]);
82-
83-
if (country) {
84-
const api = await axios.get(`https://corona.lmao.ninja/countries/${country}`);
85-
if (api.data === 'Country not found') {
86-
console.log(`${red(`${logSymbols.error} Nops. A country named "${country}" does not exist…`)}\n`);
87-
process.exit(0);
88-
}
89-
let data = Object.values(api.data);
90-
data = data.map(d => comma(d));
91-
table.push(data);
92-
console.log(table.toString());
93-
}
26+
// Table
27+
const head = xcolor ? single : colored;
28+
const table = new Table({ head, style });
9429

95-
if (!country) {
96-
const api = await axios.get(`https://corona.lmao.ninja/countries`);
97-
const all = api.data;
98-
all.map(one => {
99-
let data = Object.values(one);
100-
data = data.map(d => comma(d));
101-
return table.push(data);
102-
});
103-
console.log(table.toString());
104-
}
30+
// Display data.
31+
await getWorldwide(table);
32+
await getCountry(table, country);
33+
await getAll(table, country);
10534

106-
console.log(
107-
dim(
108-
`\nFound a bug? Report here ↓\nhttps://github.com/ahmadawais/corona-cli/issues\nFollow on twitter → https://twitter.com/MrAhmadAwais\n`
109-
)
110-
);
35+
theEnd();
11136
})();

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![DOWNLOADS](https://img.shields.io/npm/dt/corona-cli?label=DOWNLOADS%20%20❯&colorA=6A788D&colorB=6A788D&style=flat)](https://www.npmjs.com/package/corona-cli) [![Learn VSCode](https://img.shields.io/badge/-VSCODE.pro%20%E2%86%92-gray.svg?colorB=6A788D&style=flat)](https://VSCode.pro/?utm_source=GitHubFOSS)
44
[![Follow @MrAhmadAwais on Twitter](https://img.shields.io/badge/FOLLOW%20@MRAHMADAWAIS%20%E2%86%92-gray.svg?colorA=6A788D&colorB=6A788D&style=flat)](https://twitter.com/mrahmadawais/)
55

6-
> Track the Coronavirus disease (COVID-19).
6+
> Track the Coronavirus disease (COVID-19) or the Novel Coronavirus Strain.
77
88
<br>
99

@@ -12,11 +12,11 @@
1212
## Install
1313

1414
```sh
15-
npm install -g corona-cli
16-
17-
# OR run directly with npx.
18-
15+
# Run directly with npx.
1916
npx corona-cli
17+
18+
# OR Install globally.
19+
npm install -g corona-cli
2020
```
2121

2222
<br>

utils/getAll.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const chalk = require('chalk');
2+
const axios = require('axios');
3+
const comma = require('comma-number');
4+
5+
module.exports = async (table, country) => {
6+
if (!country) {
7+
const api = await axios.get(`https://corona.lmao.ninja/countries`);
8+
const all = api.data;
9+
all.map(one => {
10+
let data = Object.values(one);
11+
data = data.map(d => comma(d));
12+
return table.push(data);
13+
});
14+
console.log(table.toString());
15+
}
16+
};

utils/getCountry.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const chalk = require('chalk');
2+
const axios = require('axios');
3+
const logSymbols = require('log-symbols');
4+
const comma = require('comma-number');
5+
const red = chalk.red;
6+
7+
module.exports = async (table, country) => {
8+
if (country) {
9+
const api = await axios.get(`https://corona.lmao.ninja/countries/${country}`);
10+
if (api.data === 'Country not found') {
11+
console.log(`${red(`${logSymbols.error} Nops. A country named "${country}" does not exist…`)}\n`);
12+
process.exit(0);
13+
}
14+
let data = Object.values(api.data);
15+
data = data.map(d => comma(d));
16+
table.push(data);
17+
console.log(table.toString());
18+
}
19+
};

utils/getWorldwide.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const axios = require('axios');
2+
const comma = require('comma-number');
3+
4+
module.exports = async table => {
5+
const all = await axios.get(`https://corona.lmao.ninja/all`);
6+
let data = Object.values(all.data);
7+
data = data.map(d => comma(d));
8+
table.push([`Worldwide`, data[0], `—`, data[1], `—`, data[2], `—`, `—`, `—`]);
9+
};

utils/init.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const welcome = require('cli-welcome');
2+
const pkgJSON = require('./../package.json');
3+
const updateNotifier = require('update-notifier');
4+
5+
module.exports = async () => {
6+
welcome(`corona-cli`, `by Awais.dev\n${pkgJSON.description}`, {
7+
bgColor: `#007C91`,
8+
color: `#FFFFFF`,
9+
bold: true,
10+
clear: true,
11+
version: `v${pkgJSON.version}`
12+
});
13+
updateNotifier({
14+
pkg: pkgJSON,
15+
shouldNotifyInNpmScript: true
16+
}).notify({ isGlobal: true });
17+
};

utils/table.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const chalk = require('chalk');
2+
const green = chalk.green;
3+
const red = chalk.red;
4+
const dim = chalk.dim;
5+
6+
module.exports = {
7+
single: [
8+
`Country`,
9+
`Cases`,
10+
`Cases ${dim(`(today)`)}`,
11+
`Deaths`,
12+
`Deaths ${dim(`(today)`)}`,
13+
`Recovered`,
14+
`Active`,
15+
`Critical`,
16+
`Per Million`
17+
],
18+
colored: [
19+
`Country`,
20+
`Cases`,
21+
`Cases ${dim(`(today)`)}`,
22+
`${red(`Deaths`)}`,
23+
`${red(`Deaths (today)`)}`,
24+
`${green(`Recovered`)}`,
25+
`Active`,
26+
`${red(`Critical`)}`,
27+
`Per Million`
28+
],
29+
style: { head: ['cyan'] }
30+
};

utils/theEnd.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const chalk = require('chalk');
2+
const logSymbols = require('log-symbols');
3+
const dim = chalk.dim;
4+
5+
module.exports = async () => {
6+
console.log(
7+
`\n\n${logSymbols.success} ${dim(`Star the repo for updates → https://git.io/corona-cli`)}\n${logSymbols.info} ${dim(
8+
`Follow for more CLIs → https://twitter.com/MrAhmadAwais\n\n`
9+
)}`
10+
);
11+
};

0 commit comments

Comments
 (0)