Report build size change
This commit is contained in:
parent
587eafca2a
commit
43a405214c
34
Jakefile.js
34
Jakefile.js
@ -24,24 +24,42 @@ task('lint', function () {
|
||||
|
||||
desc('Combine and compress Leaflet source files');
|
||||
task('build', ['lint'], function (compsBase32, buildName) {
|
||||
var name = buildName || 'custom',
|
||||
path = 'dist/leaflet' + (compsBase32 ? '-' + name : '');
|
||||
var pathPart = 'dist/leaflet' + (buildName ? '-' + buildName : ''),
|
||||
srcPath = pathPart + '-src.js',
|
||||
path = pathPart + '.js';
|
||||
|
||||
var files = build.getFiles(compsBase32);
|
||||
|
||||
console.log('Concatenating ' + files.length + ' files...');
|
||||
var content = build.combineFiles(files);
|
||||
console.log('\tUncompressed size: ' + content.length);
|
||||
|
||||
build.save(path + '-src.js', COPYRIGHT + content);
|
||||
console.log('\tSaved to ' + path);
|
||||
var oldSrc = build.load(srcPath),
|
||||
newSrc = COPYRIGHT + content,
|
||||
srcDelta = build.getSizeDelta(newSrc, oldSrc);
|
||||
|
||||
console.log('\tUncompressed size: ' + newSrc.length + ' bytes (' + srcDelta + ')');
|
||||
|
||||
if (newSrc === oldSrc) {
|
||||
console.log('\tNo changes');
|
||||
} else {
|
||||
build.save(srcPath, newSrc);
|
||||
console.log('\tSaved to ' + srcPath);
|
||||
}
|
||||
|
||||
console.log('Compressing...');
|
||||
var compressed = COPYRIGHT + build.uglify(content);
|
||||
console.log('\tCompressed size: ' + compressed.length);
|
||||
|
||||
build.save(path + '.js', compressed);
|
||||
var oldCompressed = build.load(path),
|
||||
newCompressed = COPYRIGHT + build.uglify(content),
|
||||
delta = build.getSizeDelta(newCompressed, oldCompressed);
|
||||
|
||||
console.log('\tCompressed size: ' + newCompressed.length + ' bytes (' + delta + ')');
|
||||
|
||||
if (newCompressed === oldCompressed) {
|
||||
console.log('\tNo changes');
|
||||
} else {
|
||||
build.save(path, newCompressed);
|
||||
console.log('\tSaved to ' + path);
|
||||
}
|
||||
});
|
||||
|
||||
task('default', ['build']);
|
@ -37,7 +37,7 @@ exports.getFiles = function (compsBase32) {
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
};
|
||||
|
||||
exports.uglify = function (code) {
|
||||
var pro = uglifyjs.uglify;
|
||||
@ -48,7 +48,7 @@ exports.uglify = function (code) {
|
||||
ast = pro.ast_squeeze_more(ast);
|
||||
|
||||
return pro.gen_code(ast);
|
||||
}
|
||||
};
|
||||
|
||||
exports.combineFiles = function (files) {
|
||||
var content = '';
|
||||
@ -56,8 +56,24 @@ exports.combineFiles = function (files) {
|
||||
content += fs.readFileSync(files[i], 'utf8') + '\r\n\r\n';
|
||||
}
|
||||
return content;
|
||||
}
|
||||
};
|
||||
|
||||
exports.save = function (savePath, compressed) {
|
||||
fs.writeFileSync(savePath, compressed, 'utf8');
|
||||
}
|
||||
return fs.writeFileSync(savePath, compressed, 'utf8');
|
||||
};
|
||||
|
||||
exports.load = function (loadPath) {
|
||||
try {
|
||||
return fs.readFileSync(loadPath, 'utf8');
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
exports.getSizeDelta = function (newContent, oldContent) {
|
||||
if (!oldContent) {
|
||||
return 'new';
|
||||
}
|
||||
var delta = newContent.length - oldContent.length;
|
||||
return (delta >= 0 ? '+' : '') + delta;
|
||||
};
|
Loading…
Reference in New Issue
Block a user