You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ripple.apache.org by ti...@apache.org on 2015/06/18 23:15:19 UTC
incubator-ripple git commit: Improve jake lint.
Repository: incubator-ripple
Updated Branches:
refs/heads/master c8978cdff -> c4f688b06
Improve jake lint.
- Fail the task when the process returns error code.
- Run linters in parallel.
- Remove excessive arguments.
This closes #59
Project: http://git-wip-us.apache.org/repos/asf/incubator-ripple/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ripple/commit/c4f688b0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ripple/tree/c4f688b0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ripple/diff/c4f688b0
Branch: refs/heads/master
Commit: c4f688b0694cfbd870c3f0bd6dea8933669ad1b4
Parents: c8978cd
Author: Arzhan Kinzhalin <ar...@intel.com>
Authored: Tue May 19 19:21:53 2015 -0300
Committer: Tim Barham <ti...@microsoft.com>
Committed: Thu Jun 18 14:07:54 2015 -0700
----------------------------------------------------------------------
Jakefile | 7 +++--
build/deploy.js | 4 +--
build/lint.js | 84 ++++++++++++++++++++++++++++++++--------------------
3 files changed, 58 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/c4f688b0/Jakefile
----------------------------------------------------------------------
diff --git a/Jakefile b/Jakefile
index 0bb58f6..0815d86 100644
--- a/Jakefile
+++ b/Jakefile
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+/*global desc: false, task: false, complete: false, namespace: false */
var fs = require('fs');
desc("runs jake build");
@@ -27,7 +28,7 @@ task('build', [], require('./build/build'), true);
desc("test and lint before building (with js compression)");
task('deploy', [], require('./build/deploy'), true);
-desc("run all tests in node with an emulated dom - jake test [path1,path2]");
+desc("run all tests in node with an emulated dom - jake test [path]...");
task('test', [], function () {
require('./build/test')(arguments.length > 0 ?
Array.prototype.slice.apply(arguments) : null);
@@ -43,9 +44,9 @@ namespace('test', function () {
desc("boot test server for running all tests in the browser");
task('btest', [], require('./build/btest'));
-desc("runs jshint + csslint - jake lint [path1] [path2]");
+desc("runs jshint + csslint - jake lint [path]...");
task('lint', [], function () {
- require('./build/lint')(complete, Array.prototype.slice.call(arguments));
+ require('./build/lint')(Array.prototype.slice.call(arguments));
}, true);
desc("show various codebase stats");
http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/c4f688b0/build/deploy.js
----------------------------------------------------------------------
diff --git a/build/deploy.js b/build/deploy.js
index 9874b0d..2be441c 100644
--- a/build/deploy.js
+++ b/build/deploy.js
@@ -26,9 +26,9 @@ var lint = require('./lint'),
fail = fs.readFileSync(_c.THIRDPARTY + "fail.txt", "utf-8");
function ok(code) {
- if (code || code === 1) {
+ if (code !== 0) {
process.stdout.write(fail);
- process.exit(1);
+ process.exit(code);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/c4f688b0/build/lint.js
----------------------------------------------------------------------
diff --git a/build/lint.js b/build/lint.js
index 338f364..c07e2cf 100644
--- a/build/lint.js
+++ b/build/lint.js
@@ -18,44 +18,64 @@
* under the License.
*
*/
-var childProcess = require('child_process'),
- _c = require('./conf'),
+/*global jake: false, fail: false, complete: false */
+var _c = require('./conf'),
fs = require('fs');
-function _spawn(proc, args, done) {
- function log(data) {
- process.stdout.write(new Buffer(data).toString("utf-8"));
- }
-
- var cmd = childProcess.spawn(proc, args);
-
- cmd.stdout.on('data', log);
- cmd.stderr.on('data', log);
-
- if (done) {
- cmd.on('exit', done);
- }
-}
-
-function _lintJS(files, done) {
- _spawn('jshint', files, done);
+function _lintJSCommand(files) {
+ files = files.length ? files : ".";
+ return ["jshint"].concat(files).join(" ");
}
-function _lintCSS(files, done) {
- var rules = JSON.parse(fs.readFileSync(_c.ROOT + ".csslintrc", "utf-8")),
+function _lintCSSCommand(files) {
+ var cssDirs = ["assets/client/ripple.css", "lib/client", "assets/server", "test"],
+ rules = JSON.parse(fs.readFileSync(_c.ROOT + ".csslintrc", "utf-8")),
options = ["--errors=" + rules, "--format=compact", "--quiet"];
- _spawn('csslint', files.concat(options), function (/*code*/) {
- // TODO: There is a lingering CSS error that can not be turned off.
- // Once fix, pass code back into this callback.
- done(0);
- });
+
+ files = files.length ? files : cssDirs;
+ return ["csslint"].concat(options).concat(files).join(" ");
}
-module.exports = function (done, files) {
- var cssDirs = ["assets/client/ripple.css", "lib/client", "assets/server", "test"];
- _lintJS(files && files.length > 0 ? files : ["."], function (jscode) {
- _lintCSS(files && files.length > 0 ? files : cssDirs, function (csscode) {
- done((jscode === 0 && csscode === 0) ? 0 : 1);
+module.exports = function (files, done) {
+ if (typeof files === "function") {
+ done = files;
+ files = [];
+ }
+ if (typeof done === "undefined") {
+ // if we given no callback, use stub
+ done = function () {};
+ }
+ var job,
+ opts = {
+ printStdout: true,
+ printStderr: true,
+ breakOnError: false
+ },
+ doneCount = 0,
+ lintCode = 0,
+ lintErrorMessage = "";
+
+ function bindEvents(job, command) {
+ job.addListener('error', function (msg, code) {
+ lintCode++;
+ lintErrorMessage += " " + command + " failed.";
});
- });
+ job.addListener('end', function () {
+ doneCount++;
+ /* both jshint and csslint are completed */
+ if (doneCount === 2) {
+ done(lintCode);
+ if (lintCode) {
+ fail(lintErrorMessage.substring(1), lintCode);
+ } else {
+ complete();
+ }
+ }
+ });
+ }
+
+ job = jake.exec(_lintJSCommand(files), opts);
+ bindEvents(job, "jshint");
+ job = jake.exec(_lintCSSCommand(files), opts);
+ bindEvents(job, "csslint");
};