@@ -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' ) ;
1210const Table = require ( 'cli-table3' ) ;
13- const comma = require ( 'comma-number' ) ;
1411const 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 ' ) ;
1815const 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' ) ;
2019const 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} ) ( ) ;
0 commit comments