UNPKG

1.46 kBJavaScriptView Raw
1var verify = require('check-more-types').verify;
2var Table = require('easy-table');
3var colorProbability = require('./stats').colorProbability;
4
5function markProbability(val, width) {
6 if (width === null) {
7 return val;
8 }
9 return Table.padLeft(val, width);
10}
11
12function printModulesTable(modules, options) {
13 verify.array(modules, 'expect an array of modules');
14 var haveStats = modules.some(function (m) {
15 return typeof m.stats === 'object';
16 });
17
18 var t = new Table();
19 modules.forEach(function (info) {
20 verify.string(info.name, 'missing module name ' + info);
21 verify.string(info.version, 'missing module version ' + info);
22
23 t.cell('package', info.name);
24 t.cell('current', info.from);
25 t.cell('available', info.version);
26
27 if (haveStats && info.stats) {
28 var stats = info.stats;
29 verify.object(stats, 'expected stats object');
30
31 var total = +stats.success + stats.failure;
32 var probability = total ? stats.success / total : null;
33 var probabilityStr = colorProbability(probability, options);
34 t.cell('success %', probabilityStr, markProbability);
35 t.cell('successful updates', info.stats.success, Table.Number(0));
36 t.cell('failed updates', info.stats.failure, Table.Number(0));
37 }
38 t.newRow();
39 });
40 console.log(t.toString());
41}
42
43module.exports = printModulesTable;