Leaflet/Jakefile.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

var build = require('./build/build.js'),
2012-07-12 15:39:22 +08:00
lint = require('./build/hint.js');
2011-12-12 08:32:53 +08:00
2012-05-10 16:11:52 +08:00
var COPYRIGHT = '/*\n Copyright (c) 2010-2012, CloudMade, Vladimir Agafonkin\n' +
2012-11-02 21:16:17 +08:00
' Leaflet is an open-source JavaScript library for mobile-friendly interactive maps.\n' +
' http://leafletjs.com\n*/\n';
2011-12-12 08:32:53 +08:00
2011-12-13 03:48:20 +08:00
desc('Check Leaflet source for errors with JSHint');
task('lint', function () {
2012-07-12 15:39:22 +08:00
var files = build.getFiles();
2012-02-13 22:25:57 +08:00
console.log('Checking for JS errors...');
2012-02-13 22:25:57 +08:00
var errorsFound = lint.jshint(files);
2012-02-13 22:25:57 +08:00
if (errorsFound > 0) {
console.log(errorsFound + ' error(s) found.\n');
fail();
} else {
console.log('\tCheck passed');
}
});
2011-12-13 03:48:20 +08:00
desc('Combine and compress Leaflet source files');
task('build', ['lint'], function (compsBase32, buildName) {
2011-12-12 08:32:53 +08:00
2011-12-12 18:44:16 +08:00
var files = build.getFiles(compsBase32);
2011-12-12 08:32:53 +08:00
console.log('Concatenating ' + files.length + ' files...');
2012-02-13 22:25:57 +08:00
2012-07-12 15:39:22 +08:00
var content = build.combineFiles(files),
newSrc = COPYRIGHT + content,
pathPart = 'dist/leaflet' + (buildName ? '-' + buildName : ''),
srcPath = pathPart + '-src.js',
oldSrc = build.load(srcPath),
srcDelta = build.getSizeDelta(newSrc, oldSrc);
2012-02-13 22:25:57 +08:00
2011-12-13 06:41:56 +08:00
console.log('\tUncompressed size: ' + newSrc.length + ' bytes (' + srcDelta + ')');
2012-02-13 22:25:57 +08:00
2011-12-13 06:41:56 +08:00
if (newSrc === oldSrc) {
console.log('\tNo changes');
} else {
build.save(srcPath, newSrc);
console.log('\tSaved to ' + srcPath);
}
2012-02-13 22:25:57 +08:00
console.log('Compressing...');
2011-12-12 08:32:53 +08:00
2012-07-12 15:39:22 +08:00
var path = pathPart + '.js',
oldCompressed = build.load(path),
newCompressed = COPYRIGHT + build.uglify(content),
delta = build.getSizeDelta(newCompressed, oldCompressed);
2012-02-13 22:25:57 +08:00
2011-12-13 06:41:56 +08:00
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);
}
});
2012-02-13 22:25:57 +08:00
task('default', ['build']);