Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update node modules (jshint) and fix up issues, refs 228

  • Loading branch information...
commit f205bd792b603517ef5de42678734a31deb12a6f 1 parent da3ffc1
@jacobtoye jacobtoye authored
Showing with 140 additions and 142 deletions.
  1. +31 −9 Jakefile.js
  2. +79 −94 build/build.js
  3. +25 −33 build/hintrc.js
  4. +5 −6 package.json
View
40 Jakefile.js
@@ -4,23 +4,45 @@ Leaflet.draw building and linting scripts.
To use, install Node, then run the following commands in the project root:
npm install -g jake
- npm install uglify-js
- npm install jshint
+ npm install
-To check the code and build Leaflet from source, run "jake"
+To check the code for errors and build Leaflet from source, run "jake".
+To run the tests, run "jake test".
For a custom build, open build/build.html in the browser and follow the instructions.
*/
var build = require('./build/build.js');
-desc('Check Leaflet.Draw source for errors with JSHint');
-task('lint', build.lint);
+function hint(msg, paths) {
+ return function () {
+ console.log(msg);
+ jake.exec('node node_modules/jshint/bin/jshint -c ' + paths,
+ {printStdout: true}, function () {
+ console.log('\tCheck passed.\n');
+ complete();
+ });
+ };
+}
-desc('Combine and compress Leaflet.Draw source files');
-task('build', ['lint'], build.build);
+desc('Check Leaflet.draw source for errors with JSHint');
+task('lint', {async: true}, hint('Checking for JS errors...', 'build/hintrc.js src'));
+
+desc('Check Leaflet.draw specs source for errors with JSHint');
+task('lintspec', {async: true}, hint('Checking for specs JS errors...', 'spec/spec.hintrc.js spec/suites'));
+
+desc('Combine and compress Leaflet.draw source files');
+task('build', {async: true}, function () {
+ build.build(complete);
+});
desc('Run PhantomJS tests');
-task('test', ['lint'], build.test);
+task('test', ['lint', 'lintspec'], {async: true}, function () {
+ build.test(complete);
+});
+
+task('default', ['test', 'build']);
-task('default', ['build']);
+jake.addListener('complete', function () {
+ process.exit();
+});
View
173 build/build.js
@@ -1,35 +1,13 @@
var fs = require('fs'),
- jshint = require('jshint'),
- UglifyJS = require('uglify-js'),
+ jshint = require('jshint'),
+ UglifyJS = require('uglify-js'),
+ zlib = require('zlib'),
- deps = require('./deps.js').deps,
- hintrc = require('./hintrc.js').config;
-
-
-function lintFiles(files) {
-
- var errorsFound = 0,
- i, j, len, len2, src, errors, e;
-
- for (i = 0, len = files.length; i < len; i++) {
-
- jshint.JSHINT(fs.readFileSync(files[i], 'utf8'), hintrc);
- errors = jshint.JSHINT.errors;
-
- for (j = 0, len2 = errors.length; j < len2; j++) {
- e = errors[j];
- console.log(files[i] + '\tline ' + e.line + '\tcol ' + e.character + '\t ' + e.reason);
- }
-
- errorsFound += len2;
- }
-
- return errorsFound;
-}
+ deps = require('./deps.js').deps;
function getFiles(compsBase32) {
var memo = {},
- comps;
+ comps;
if (compsBase32) {
comps = parseInt(compsBase32, 32).toString(2).split('');
@@ -45,16 +23,18 @@ function getFiles(compsBase32) {
for (var i in deps) {
if (comps) {
if (parseInt(comps.pop(), 2) === 1) {
- console.log('\t* ' + i);
+ console.log(' * ' + i);
addFiles(deps[i].src);
} else {
- console.log('\t ' + i);
+ console.log(' ' + i);
}
} else {
addFiles(deps[i].src);
}
}
+ console.log('');
+
var files = [];
for (var src in memo) {
@@ -66,100 +46,105 @@ function getFiles(compsBase32) {
exports.getFiles = getFiles;
-exports.lint = function () {
-
- var files = getFiles();
-
- console.log('Checking for JS errors...');
-
- var errorsFound = lintFiles(files);
-
- if (errorsFound > 0) {
- console.log(errorsFound + ' error(s) found.\n');
- fail();
- } else {
- console.log('\tCheck passed');
- }
-};
-
-
-function getSizeDelta(newContent, oldContent) {
- if (!oldContent) {
- return 'new';
- }
- var newLen = newContent.replace(/\r\n?/g, '\n').length,
- oldLen = oldContent.replace(/\r\n?/g, '\n').length,
- delta = newLen - oldLen;
+function getSizeDelta(newContent, oldContent, fixCRLF) {
+ if (!oldContent) {
+ return ' (new)';
+ }
+ if (newContent === oldContent) {
+ return ' (unchanged)';
+ }
+ if (fixCRLF) {
+ newContent = newContent.replace(/\r\n?/g, '\n');
+ oldContent = oldContent.replace(/\r\n?/g, '\n');
+ }
+ var delta = newContent.length - oldContent.length;
- return (delta >= 0 ? '+' : '') + delta;
+ return delta === 0 ? '' : ' (' + (delta > 0 ? '+' : '') + delta + ' bytes)';
}
function loadSilently(path) {
- try {
- return fs.readFileSync(path, 'utf8');
- } catch (e) {
- return null;
- }
+ try {
+ return fs.readFileSync(path, 'utf8');
+ } catch (e) {
+ return null;
+ }
}
function combineFiles(files) {
- var content = '';
- for (var i = 0, len = files.length; i < len; i++) {
- content += fs.readFileSync(files[i], 'utf8') + '\n\n';
- }
- return content;
+ var content = '';
+ for (var i = 0, len = files.length; i < len; i++) {
+ content += fs.readFileSync(files[i], 'utf8') + '\n\n';
+ }
+ return content;
}
-exports.build = function (compsBase32, buildName) {
+function bytesToKB(bytes) {
+ return (bytes / 1024).toFixed(2) + ' KB';
+}
+exports.build = function (callback, compsBase32, buildName) {
var files = getFiles(compsBase32);
- console.log('Concatenating ' + files.length + ' files...');
+ console.log('Concatenating and compressing ' + files.length + ' files...');
var copy = fs.readFileSync('src/copyright.js', 'utf8'),
- intro = '(function (window, document, undefined) {\n',
- outro = '}(this, document));',
- newSrc = copy + intro + combineFiles(files) + outro,
+ intro = '(function (window, document, undefined) {',
+ outro = '}(window, document));',
+ newSrc = copy + intro + combineFiles(files) + outro,
- pathPart = 'dist/leaflet.draw' + (buildName ? '-' + buildName : ''),
- srcPath = pathPart + '-src.js',
+ pathPart = 'dist/leaflet.draw' + (buildName ? '-' + buildName : ''),
+ srcPath = pathPart + '-src.js',
- oldSrc = loadSilently(srcPath),
- srcDelta = getSizeDelta(newSrc, oldSrc);
+ oldSrc = loadSilently(srcPath),
+ srcDelta = getSizeDelta(newSrc, oldSrc, true);
- console.log('\tUncompressed size: ' + newSrc.length + ' bytes (' + srcDelta + ')');
+ console.log('\tUncompressed: ' + bytesToKB(newSrc.length) + srcDelta);
- if (newSrc === oldSrc) {
- console.log('\tNo changes');
- } else {
+ if (newSrc !== oldSrc) {
fs.writeFileSync(srcPath, newSrc);
console.log('\tSaved to ' + srcPath);
}
- console.log('Compressing...');
-
var path = pathPart + '.js',
- oldCompressed = loadSilently(path),
- newCompressed = copy + UglifyJS.minify(newSrc, {
- warnings: true,
- fromString: true
- }).code,
- delta = getSizeDelta(newCompressed, oldCompressed);
-
- console.log('\tCompressed size: ' + newCompressed.length + ' bytes (' + delta + ')');
-
- if (newCompressed === oldCompressed) {
- console.log('\tNo changes');
- } else {
- fs.writeFileSync(path, newCompressed);
- console.log('\tSaved to ' + path);
+ oldCompressed = loadSilently(path),
+ newCompressed = copy + UglifyJS.minify(newSrc, {
+ warnings: true,
+ fromString: true
+ }).code,
+ delta = getSizeDelta(newCompressed, oldCompressed);
+
+ console.log('\tCompressed: ' + bytesToKB(newCompressed.length) + delta);
+
+ var newGzipped,
+ gzippedDelta = '';
+
+ function done() {
+ if (newCompressed !== oldCompressed) {
+ fs.writeFileSync(path, newCompressed);
+ console.log('\tSaved to ' + path);
+ }
+ console.log('\tGzipped: ' + bytesToKB(newGzipped.length) + gzippedDelta);
+ callback();
}
+ zlib.gzip(newCompressed, function (err, gzipped) {
+ if (err) { return; }
+ newGzipped = gzipped;
+ if (oldCompressed && (oldCompressed !== newCompressed)) {
+ zlib.gzip(oldCompressed, function (err, oldGzipped) {
+ if (err) { return; }
+ gzippedDelta = getSizeDelta(gzipped, oldGzipped);
+ done();
+ });
+ } else {
+ done();
+ }
+ });
};
exports.test = function() {
var karma = require('karma'),
- testConfig = {configFile : __dirname + '/../spec/karma.conf.js'};
+ testConfig = {configFile : __dirname + '/../spec/karma.conf.js'};
testConfig.browsers = ['PhantomJS'];
View
58 build/hintrc.js
@@ -1,47 +1,39 @@
-exports.config = {
+{
+ // environment
"browser": true,
"node": true,
- "predef": ["L"],
-
- "debug": false,
- "devel": false,
-
- "es5": false,
+ "globals": {
+ "L": true,
+ "define": true
+ },
"strict": false,
- "globalstrict": false,
- "asi": false,
- "laxbreak": false,
+ // code style
"bitwise": true,
- "boss": false,
+ "camelcase": true,
"curly": true,
- "eqnull": false,
- "evil": false,
- "expr": false,
- "forin": true,
+ "eqeqeq": true,
+ "forin": false,
"immed": true,
"latedef": true,
- "loopfunc": false,
- "noarg": true,
- "regexp": true,
- "regexdash": false,
- "scripturl": false,
- "shadow": false,
- "supernew": false,
- "undef": true,
- "funcscope": false,
-
"newcap": true,
+ "noarg": true,
"noempty": true,
"nonew": true,
- "nomen": false,
- "onevar": false,
- "plusplus": false,
- "sub": false,
- "indent": 4,
+ "undef": true,
+ "unused": true,
+ "quotmark": "single",
- "eqeqeq": true,
+ // whitespace
+ "indent": 4,
"trailing": true,
"white": true,
- "smarttabs": true
-};
+ "smarttabs": true,
+ "maxlen": 150
+
+ // code simplicity - not enforced but nice to check from time to time
+ // "maxstatements": 20,
+ // "maxcomplexity": 5
+ // "maxparams": 4,
+ // "maxdepth": 4
+}
View
11 package.json
@@ -3,12 +3,11 @@
"version": "0.2.2",
"description": "Vector drawing plugin for Leaflet",
"devDependencies": {
- "leaflet": "git://github.com/Leaflet/Leaflet.git",
- "jshint": "~1.1.0",
- "uglify-js": "~2.2.5",
- "jake": "~0.5.10",
- "mocha": "~1.9.0",
- "karma": "~0.8.0"
+ "jshint": "~2.3.0",
+ "uglify-js": "~2.4.3",
+ "jake": "~0.7.4",
+ "mocha": "~1.14.0",
+ "karma": "~0.10.4"
},
"main": "dist/leaflet.draw.js",
"directories": {
Please sign in to comment.
Something went wrong with that request. Please try again.