-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·58 lines (50 loc) · 1.35 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
#!/usr/bin/env node
const api = require('./api');
const chalk = require('chalk');
const figlet = require('figlet');
const ora = require('ora');
const R = require('ramda');
const util = require('./util');
const { getStats } = require('./api');
/**
* TODO
*/
const pkgList = R.drop(2, process.argv);
const token = process.env.NPM_PKG_STATS_TOKEN;
console.log(chalk.magenta(figlet.textSync('npm pkg stats', { font: 'Big' })));
const spinner = ora({
text: 'Getting stats...',
color: 'magenta',
});
spinner.start();
Promise.all(R.map(getStats(token), pkgList))
.then(
R.pipe(
R.tap(() => console.log('\n')),
R.ifElse(
R.pipe(R.length, R.equals(1)),
R.pipe(R.head, api.makeVerticalTable, R.toString, console.log),
pkgStatsList => {
const labelList = R.pipe(
R.reduce(
(result, pkgStats) => R.concat(R.keys(pkgStats), result),
[],
),
R.uniq,
)(pkgStatsList);
const valueList = R.map(
R.pipe(R.values, util.fillWith(api.nilValue, labelList.length)),
pkgStatsList,
);
console.log(
api.makeHorizontalTable({ labelList, valueList }).toString(),
);
},
),
() => spinner.stop(),
),
)
.catch(err => {
console.error(err);
spinner.stop();
});