integrate jshint into Jakefile, minor cleanup

refactorvectors
mourner 13 years ago
parent 0e329c7b1b
commit f68a227680

@ -1,31 +1,44 @@
var build = require('./build/build.js');
var build = require('./build/build.js'),
lint = require('./build/hint.js');
var COPYRIGHT = "/*\n Copyright (c) 2010-2011, CloudMade, Vladimir Agafonkin\n" +
" Leaflet is a modern open source JavaScript library for interactive maps.\n" +
" http://leaflet.cloudmade.com\n*/\n";
task('build', function (compsBase32, buildName) {
task('lint', function () {
var files = build.getFiles();
console.log('Checking for JS errors...');
var errorsFound = lint.jshint(files);
if (errorsFound > 0) {
console.log(errorsFound + ' error(s) found.\n');
fail();
} else {
console.log('\tCheck passed');
}
});
task('build', ['lint'], function (compsBase32, buildName) {
var name = buildName || 'custom',
savePath = 'dist/leaflet' + (compsBase32 ? '-' + name : '') + '.js';
path = 'dist/leaflet' + (compsBase32 ? '-' + name : '');
var files = build.getFiles(compsBase32);
console.log('Concatenating ' + files.length + ' files...');
var content = build.combineFiles(files);
console.log('Uncompressed size: ' + content.length);
console.log('\tUncompressed size: ' + content.length);
build.save(path + '-src.js', COPYRIGHT + content);
console.log('\tSaved to ' + path);
console.log('Compressing...');
var compressed = COPYRIGHT + build.uglify(content);
console.log('\tCompressed size: ' + compressed.length);
console.log('Compressed size: ' + compressed.length);
build.save(savePath, compressed);
console.log('Saved to ' + savePath);
build.save(path + '.js', compressed);
console.log('\tSaved to ' + path);
});
task('default', ['build']);
// TODO task('lint')
task('default', ['build']);

@ -0,0 +1,30 @@
var jshint = require('jshint').JSHINT,
fs = require('fs'),
config = require('./hintrc.js').config;
function jshintSrc(path, src) {
jshint(src, config);
var errors = jshint.errors,
i, len, e, line;
for (i = 0, len = errors.length; i < len; i++) {
e = errors[i];
//console.log(e.evidence);
console.log(path + '\tline ' + e.line + '\tcol ' + e.character + '\t ' + e.reason);
}
return len;
}
exports.jshint = function (files) {
var errorsFound = 0;
for (var i = 0, len = files.length; i < len; i++) {
var src = fs.readFileSync(files[i], 'utf8');
errorsFound += jshintSrc(files[i], src);
}
return errorsFound;
};

@ -1,4 +1,4 @@
{
exports.config = {
"browser": true,
"predef": ["L"],
@ -41,4 +41,4 @@
"eqeqeq": true,
"trailing": true,
"white": true
}
};

5511
dist/leaflet-src.js vendored

File diff suppressed because it is too large Load Diff

2
dist/leaflet.js vendored

File diff suppressed because one or more lines are too long

@ -5,7 +5,7 @@
ROOT_URL: root.L_ROOT_URL || (function () {
var scripts = document.getElementsByTagName('script'),
leafletRe = /\/?leaflet\-?([\w\-]*)\.js\??/;
leafletRe = /\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/;
var i, len, src, matches;

Loading…
Cancel
Save