[Pkg-javascript-commits] [leaflet] 211/301: improve and clean up build system, jshint specs in tests, close #2151

Jonas Smedegaard js at moszumanska.debian.org
Mon Jan 27 22:22:52 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet.

commit 244f9f39ceee9f9b218cda7701a60a8af2ad58df
Author: Vladimir Agafonkin <agafonkin at gmail.com>
Date:   Fri Nov 8 17:55:58 2013 +0200

    improve and clean up build system, jshint specs in tests, close #2151
---
 Jakefile.js     | 28 ++++++++++++++++++++----
 build/build.js  | 66 +++++++++++++++------------------------------------------
 build/hintrc.js | 10 +++++----
 package.json    |  2 +-
 4 files changed, 48 insertions(+), 58 deletions(-)

diff --git a/Jakefile.js b/Jakefile.js
index a4a64ea..698d8e4 100644
--- a/Jakefile.js
+++ b/Jakefile.js
@@ -14,13 +14,33 @@ For a custom build, open build/build.html in the browser and follow the instruct
 
 var build = require('./build/build.js');
 
+function hint(msg, paths) {
+	return function () {
+		console.log(msg);
+		jake.exec('./node_modules/jshint/bin/jshint -c ' + paths,
+				{printStdout: true}, function () {
+			console.log('\tCheck passed.\n');
+			complete();
+		});
+	}
+}
+
 desc('Check Leaflet source for errors with JSHint');
-task('lint', build.lint);
+task('lint', {async: true}, hint('Checking for JS errors...', 'build/hintrc.js src'));
+
+desc('Check Leaflet 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 source files');
-task('build', ['lint'], build.build);
+task('build', build.build);
 
 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();
+});
diff --git a/build/build.js b/build/build.js
index 33c81b2..f931b8a 100644
--- a/build/build.js
+++ b/build/build.js
@@ -2,29 +2,7 @@ var fs = require('fs'),
     jshint = require('jshint'),
     UglifyJS = require('uglify-js'),
 
-    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, i ? {L: true} : null);
-		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 = {},
@@ -65,23 +43,6 @@ 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';
@@ -129,10 +90,10 @@ exports.build = function (compsBase32, buildName) {
 	console.log('\tUncompressed size: ' + newSrc.length + ' bytes (' + srcDelta + ')');
 
 	if (newSrc === oldSrc) {
-		console.log('\tNo changes');
+		console.log('\tNo changes\n');
 	} else {
 		fs.writeFileSync(srcPath, newSrc);
-		console.log('\tSaved to ' + srcPath);
+		console.log('\tSaved to ' + srcPath + '\n');
 	}
 
 	console.log('Compressing...');
@@ -148,19 +109,23 @@ exports.build = function (compsBase32, buildName) {
 	console.log('\tCompressed size: ' + newCompressed.length + ' bytes (' + delta + ')');
 
 	if (newCompressed === oldCompressed) {
-		console.log('\tNo changes');
+		console.log('\tNo changes\n');
 	} else {
 		fs.writeFileSync(path, newCompressed);
-		console.log('\tSaved to ' + path);
+		console.log('\tSaved to ' + path + '\n');
 	}
 };
 
-exports.test = function() {
+exports.test = function(callback) {
 	var karma = require('karma'),
 	    testConfig = {configFile : __dirname + '/../spec/karma.conf.js'};
 
 	testConfig.browsers = ['PhantomJS'];
 
+	function isArgv(optName) {
+		return process.argv.indexOf(optName) !== -1;
+	}
+
 	if (isArgv('--chrome')) {
 		testConfig.browsers.push('Chrome');
 	}
@@ -185,9 +150,12 @@ exports.test = function() {
 		testConfig.reporters = ['coverage'];
 	}
 
-	karma.server.start(testConfig);
+	console.log('Running tests...');
 
-	function isArgv(optName) {
-		return process.argv.indexOf(optName) !== -1;
-	}
+	karma.server.start(testConfig, function(exitCode) {
+		if (!exitCode) {
+			console.log('\tTests ran successfully.\n');
+		}
+		callback();
+	});
 };
diff --git a/build/hintrc.js b/build/hintrc.js
index 5185bad..851591a 100644
--- a/build/hintrc.js
+++ b/build/hintrc.js
@@ -1,9 +1,11 @@
-exports.config = {
-
+{
 	// environment
 	"browser": true,
 	"node": true,
-	"predef": ['define'],
+	"globals": {
+		"L": true,
+		"define": true
+	},
 	"strict": false,
 
 	// code style
@@ -34,4 +36,4 @@ exports.config = {
 	// "maxcomplexity": 5
 	// "maxparams": 4,
 	// "maxdepth": 4
-};
+}
diff --git a/package.json b/package.json
index a75b480..fee7e4c 100644
--- a/package.json
+++ b/package.json
@@ -14,7 +14,7 @@
   "main": "dist/leaflet-src.js",
   "scripts": {
     "test": "jake test",
-    "prepublish": "jake"
+    "prepublish": "jake build"
   },
   "repository": {
     "type": "git",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git



More information about the Pkg-javascript-commits mailing list