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 https = require('https'),
zlib = require('zlib'),
path = require('path'),
fs = require('fs');
var stable = '1.7.1',
done;
function getVersion(path, cb) {
var data = '',
req = https.request({
host: 'raw.github.com',
port: 443,
path: '/timrwood/moment/' + path
}, function (res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function (e) {
zlib.gzip(data, function (error, result) {
cb(data.length, result.length);
});
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
req.end();
}
function printDiffs(stableLen, stableGzip, currentLen, currentGzip) {
var diff = currentLen - stableLen,
gzipDiff = currentGzip - stableGzip;
console.log('Filesize difference from current branch to ' + stable);
console.log(stable + ' ' + stableLen + ' / ' + stableGzip);
console.log('curr ' + currentLen + ' / ' + currentGzip);
console.log('diff ' + (diff > 0 ? '+' : '') + diff);
console.log('gzip ' + (gzipDiff > 0 ? '+' : '') + gzipDiff);
}
module.exports = function (grunt) {
grunt.registerTask('size', 'Check the codebase filesize against the latest stable version.', function () {
done = this.async();
fs.readFile(path.normalize(__dirname + '/../min/moment.min.js'), 'utf8', function (err, data) {
if (err) {
throw err;
}
zlib.gzip(data, function (error, result) {
getVersion(stable + '/min/moment.min.js', function (stableLength, stableGzipLength) {
printDiffs(stableLength, stableGzipLength, data.length, result.length);
done();
});
});
});
});
};
|