-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathstats.js
More file actions
59 lines (51 loc) · 1.71 KB
/
stats.js
File metadata and controls
59 lines (51 loc) · 1.71 KB
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
var execp = require('./execp');
require('colors');
module.exports = function () {
return Promise.all([
execp('cat dist/derivable.js | wc -c'),
execp('git show master:dist/derivable.js | wc -c'),
execp('cat dist/derivable.min.js | wc -c'),
execp('git show master:dist/derivable.min.js | wc -c'),
execp('cat dist/derivable.min.js | gzip -c | wc -c'),
execp('git show master:dist/derivable.min.js | gzip -c | wc -c'),
]).then(function (results) {
return results.map(function (result) { return parseInt(result); });
}).then(function (results) {
var rawNew = results[0];
var rawOld = results[1];
var minNew = results[2];
var minOld = results[3];
var zipNew = results[4];
var zipOld = results[5];
function space(n, s) {
return Array(Math.max(0, 10 + n - (s||'').length)).join(' ') + (s||'');
}
function bytes(b) {
return b.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' bytes';
}
function diff(n, o) {
var d = n - o;
return d === 0 ? '' : d < 0 ? (' ' + bytes(d)).green : (' +' + bytes(d)).red;
}
function pct(s, b) {
var p = Math.floor(10000 * (1 - (s / b))) / 100;
return (' ' + p + '%').grey;
}
console.log(' Raw: ' +
space(14, bytes(rawNew).cyan) + ' ' + space(15, diff(rawNew, rawOld))
);
console.log(' Min: ' +
space(14, bytes(minNew).cyan) + pct(minNew, rawNew) + space(15, diff(minNew, minOld))
);
console.log(' Zip: ' +
space(14, bytes(zipNew).cyan) + pct(zipNew, rawNew) + space(15, diff(zipNew, zipOld))
);
}).catch(function (error) {
setTimeout(function () {
throw error;
}, 0);
});
};
if (require.main === module) {
module.exports();
}