cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject js commit: [all] CB-3960 Convert Jakefile -> Gruntfile.js
Date Fri, 21 Jun 2013 19:12:20 GMT
Updated Branches:
  refs/heads/2.9.x 002f33ded -> 273e0a3a8


[all] CB-3960 Convert Jakefile -> Gruntfile.js

Moves over all tasks except jshint. Our jshint options need updating to
work well with grunt.


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/273e0a3a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/273e0a3a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/273e0a3a

Branch: refs/heads/2.9.x
Commit: 273e0a3a8b11071f9eaa4a8d60c131bc214f389a
Parents: 002f33d
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Jun 21 12:58:50 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Jun 21 15:11:05 2013 -0400

----------------------------------------------------------------------
 Gruntfile.js   | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 Jakefile       | 184 +----------------------------------------------
 README.md      |  20 ++----
 build/dalek    |  14 ----
 grunt.js       |  75 -------------------
 package.json   |  54 +++++++-------
 test/runner.js |  10 +--
 7 files changed, 244 insertions(+), 315 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/273e0a3a/Gruntfile.js
----------------------------------------------------------------------
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..f7c3b3d
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+module.exports = function(grunt) {
+    var childProcess = require('child_process');
+    var fs = require('fs');
+    var path = require('path');
+
+    // Project configuration.
+    grunt.initConfig({
+        pkg: grunt.file.readJSON('package.json'),
+        cordovajs: {
+          "android": {},
+          "bada": {},
+          "blackberry": {},
+          "blackberry10": {},
+          "errgen": {},
+          "firefoxos": {},
+          "ios": {},
+          "osx":  {},
+          "test": {},
+          "tizen": {},
+          "webos":  {},
+          "windows8": { useWindowsLineEndings: true },
+          "windowsphone": { useWindowsLineEndings: true },
+        },
+        clean: ['pkg'],
+        jshint: {
+            options: {
+                jshintrc: '.jshintrc',
+            },
+            src: [ 'lib/**/*.js' ]
+        },
+    });
+
+    // Iterates over a directory
+    function forEachFile(root, cbFile, cbDone) {
+        var count = 0;
+
+        function scan(name) {
+            ++count;
+
+            fs.stat(name, function (err, stats) {
+                if (err) cbFile(err);
+
+                if (stats.isDirectory()) {
+                    fs.readdir(name, function (err, files) {
+                        if (err) cbFile(err);
+
+                        files.forEach(function (file) {
+                            scan(path.join(name, file));
+                        });
+                        done();
+                    });
+                } else if (stats.isFile()) {
+                    cbFile(null, name, stats, done);
+                } else {
+                    done();
+                }
+            });
+        }
+
+        function done() {
+            --count;
+            if (count === 0 && cbDone) cbDone();
+        }
+
+        scan(root);
+    }
+
+    var cachedGitVersion = null;
+    function computeGitVersion(callback) {
+        if (cachedGitVersion) {
+            callback(cachedGitVersion);
+            return;
+        }
+        var gitPath = 'git';
+        var args = 'describe --tags --long';
+        childProcess.exec(gitPath + ' ' + args, function(err, stdout, stderr) {
+            var isWindows = process.platform.slice(0, 3) == 'win';
+            if (err && isWindows) {
+                gitPath = '"' + path.join(process.env['ProgramFiles'], 'Git', 'bin', 'git.exe')
+ '"';
+                childProcess.exec(gitPath + ' ' + args, function(err, stdout, stderr) {
+                    if (err) {
+                        error(err);
+                    } else {
+                        done(stdout);
+                    }
+                });
+            } else if (err) {
+                error(err);
+            } else {
+                done(stdout);
+            }
+        });
+
+        function error(err) {
+            throw new Error(err);
+        }
+
+        function done(stdout) {
+            var version = stdout.trim().replace(/^2.5.0-.*?-/, 'dev-');
+            cachedGitVersion = version;
+            callback(version);
+        };
+    }
+
+    function processWhiteSpace(processor, callback) {
+        var rexp_minified = new RegExp("\\.min\\.js$");
+        var rexp_src = new RegExp('\\.js$');
+        forEachFile('lib', function(err, file, stats, cbDone) {
+            //if (err) throw err;
+            if (rexp_minified.test(file) || !rexp_src.test(file)) {
+                cbDone();
+            } else {
+                var origsrc = src = fs.readFileSync(file, 'utf8');
+
+                // tabs -> four spaces
+                if (src.indexOf('\t') >= 0) {
+                    src = src.split('\t').join('    ');
+                }
+
+                // eliminate trailing white space
+                src = src.replace(/ +\n/g, '\n');
+
+                if (origsrc !== src) {
+                    // write it out yo
+                    processor(file, src);
+                }
+                cbDone();
+            }
+        }, callback);
+    }
+
+    grunt.registerMultiTask('cordovajs', 'Packages cordova.js', function() {
+        var packager = require("./build/packager");
+        var done = this.async();
+        var platformName = this.target;
+        var useWindowsLineEndings = this.data.useWindowsLineEndings;
+        computeGitVersion(function(version) {
+            grunt.log.writeln('Build label: ' + version);
+            packager.generate(platformName, version, useWindowsLineEndings);
+            done();
+        });
+    });
+
+    grunt.registerTask('test', 'Runs test in node', function() {
+        var done = this.async();
+        require('./test/runner').node();
+    });
+
+    grunt.registerTask('btest', 'Runs tests in the browser', function() {
+        require('./test/runner').browser();
+        this.async(); // never finish.
+    });
+
+    grunt.registerTask('complainwhitespace', 'Complain about what fixwhitespace would fix',
function() {
+        var done = this.async();
+        var complainedAboutWhitespace = false;
+        processWhiteSpace(function(file, newSource) {
+            if (!complainedAboutWhitespace) {
+                grunt.log.writeln("files with whitespace issues: (to fix: `grunt fixwhitespace`)");
+                complainedAboutWhitespace = true;
+            }
+            grunt.log.writeln("   " + file);
+        }, done);
+    });
+
+    grunt.registerTask('fixwhitespace', 'Converts tabs to four spaces, eliminates trailing
white space, converts newlines to proper form - enforcing style guide ftw!', function() {
+        var done = this.async();
+        var complainedAboutWhitespace = false;
+        processWhiteSpace(function(file, newSource) {
+            if (!complainedAboutWhitespace) {
+                grunt.log.writeln("Fixed whitespace issues in:");
+                complainedAboutWhitespace = true;
+            }
+            fs.writeFileSync(file, newSource, 'utf8');
+            grunt.log.writeln("   " + file);
+        }, done);
+    });
+
+    grunt.loadNpmTasks('grunt-contrib-clean');
+    grunt.loadNpmTasks('grunt-contrib-jshint');
+
+    // Default task(s).
+    grunt.registerTask('default', ['cordovajs', 'complainwhitespace', 'test']);
+};

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/273e0a3a/Jakefile
----------------------------------------------------------------------
diff --git a/Jakefile b/Jakefile
index c6bb633..089b9b0 100644
--- a/Jakefile
+++ b/Jakefile
@@ -17,139 +17,12 @@
  * under the License.
  */
 
-var util         = require('util'),
-    fs           = require('fs'),
-    childProcess = require('child_process'),
-    path         = require("path"),
-    rexp_minified = new RegExp("\\.min\\.js$"),
-    rexp_src = new RegExp('\\.js$');
+var childProcess = require('child_process');
 
-// HELPERS
-// Iterates over a directory
-function forEachFile(root, cbFile, cbDone) {
-    var count = 0;
-
-    function scan(name) {
-        ++count;
-
-        fs.stat(name, function (err, stats) {
-            if (err) cbFile(err);
-
-            if (stats.isDirectory()) {
-                fs.readdir(name, function (err, files) {
-                    if (err) cbFile(err);
-
-                    files.forEach(function (file) {
-                        scan(path.join(name, file));
-                    });
-                    done();
-                });
-            } else if (stats.isFile()) {
-                cbFile(null, name, stats, done);
-            } else {
-                done();
-            }
-        });
-    }
-
-    function done() {
-        --count;
-        if (count === 0 && cbDone) cbDone();
-    }
-
-    scan(root);
-}
-
-function computeGitVersion(callback) {
-    var gitPath = 'git';
-    var args = 'describe --tags --long';
-    childProcess.exec(gitPath + ' ' + args, function(err, stdout, stderr) {
-        var isWindows = process.platform.slice(0, 3) == 'win';
-        if (err && isWindows) {
-            gitPath = '"' + path.join(process.env['ProgramFiles'], 'Git', 'bin', 'git.exe')
+ '"';
-            childProcess.exec(gitPath + ' ' + args, function(err, stdout, stderr) {
-                if (err) {
-                    error(err);
-                } else {
-                    done(stdout);
-                }
-            });
-        } else if (err) {
-            error(err);
-        } else {
-            done(stdout);
-        }
-    });
-
-    function error(err) {
-        console.error('Git command failed: git ' + args);
-        console.error('Error: ' + err);
-        process.exit(1);
-    }
-
-    function done(stdout) {
-        var version = stdout.trim().replace(/^2.5.0-.*?-/, 'dev-');
-        callback(version);
-    };
-}
-
-desc("runs build");
-task('default', ['build','test'], function () {});
-
-desc("clean");
-task('clean', ['set-cwd'], function () {
-    
-    var DEPLOY = path.join(__dirname,"pkg");
-    var cmd = 'rm -rf ' + DEPLOY + ' && ' +
-              'mkdir ' + DEPLOY + ' && ' +
-              'mkdir ' + path.join(DEPLOY ,'debug');
-
-    childProcess.exec(cmd,complete);
-}, true);
-
-desc("compiles the source files for all extensions");
-task('build', ['clean', 'hint'], function () {
-    var packager = require("./build/packager");
-    computeGitVersion(function(version) {
-        console.log("building " + version);
-
-        packager.generate("windows8", version,true);
-        packager.generate("blackberry", version);
-        packager.generate("blackberry10", version);
-        packager.generate("firefoxos", version);
-        packager.generate("ios", version);
-        packager.generate("windowsphone", version,true);
-        packager.generate("android", version);
-        packager.generate("bada", version);
-        packager.generate("tizen", version);
-        packager.generate("webos",  version);
-        packager.generate("osx",  version);
-        packager.generate("errgen", version);
-        packager.generate("test", version);
-        complete();
-    });
-}, true);
-
-desc("prints a dalek");
-task('dalek', ['set-cwd'], function () {
-    util.puts(fs.readFileSync("build/dalek", "utf-8"));
-});
-
-desc("runs the unit tests in node");
-task('test', ['set-cwd'], require('./test/runner').node);
-
-desc("starts a webserver to point at to run the unit tests");
-task('btest', ['set-cwd'], require('./test/runner').browser);
-
-desc("make sure we're in the right directory");
-task('set-cwd', [], function() {
-    if (__dirname != process.cwd()) {
-        process.chdir(__dirname);
-    }
-});
+task('default', ['hint'], function () {});
 
 desc('check sources with JSHint');
-task('hint', ['complainwhitespace'], function () {
+task('hint', [], function () {
     var knownWarnings = [
         "Redefinition of 'FileReader'", 
         "Redefinition of 'require'", 
@@ -173,54 +46,3 @@ task('hint', ['complainwhitespace'], function () {
     });
 }, true);
 
-var complainedAboutWhitespace = false
-
-desc('complain about what fixwhitespace would fix');
-task('complainwhitespace', function() {
-    processWhiteSpace(function(file, newSource) {
-        if (!complainedAboutWhitespace) {
-            console.log("files with whitespace issues: (to fix: `jake fixwhitespace`)")
-            complainedAboutWhitespace = true
-        }
-        
-        console.log("   " + file)
-    })
-}, true);
-
-desc('converts tabs to four spaces, eliminates trailing white space, converts newlines to
proper form - enforcing style guide ftw!');
-task('fixwhitespace', function() {
-    processWhiteSpace(function(file, newSource) {
-        if (!complainedAboutWhitespace) {
-            console.log("fixed whitespace issues in:")
-            complainedAboutWhitespace = true
-        }
-        
-        fs.writeFileSync(file, newSource, 'utf8');
-        console.log("   " + file)
-    })
-}, true);
-
-function processWhiteSpace(processor) {
-    forEachFile('lib', function(err, file, stats, cbDone) {
-        //if (err) throw err;
-        if (rexp_minified.test(file) || !rexp_src.test(file)) {
-            cbDone();
-        } else {
-            var origsrc = src = fs.readFileSync(file, 'utf8');
-
-            // tabs -> four spaces
-            if (src.indexOf('\t') >= 0) {
-                src = src.split('\t').join('    ');
-            }
-
-            // eliminate trailing white space
-            src = src.replace(/ +\n/g, '\n');
-
-            if (origsrc !== src) {
-                // write it out yo
-                processor(file, src);
-            }
-            cbDone();
-        }
-    }, complete);
-}

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/273e0a3a/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 994f05c..1d035b1 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@
 # under the License.
 #
 -->
-A unified JavaScript layer for [Apache Cordova](http://incubator.apache.org/projects/callback.html)
projects.
+A unified JavaScript layer for [Apache Cordova](http://cordova.apache.org/) projects.
 
 # Project Structure
 
@@ -83,19 +83,13 @@ Make sure you have [node.js](http://nodejs.org) installed. It should come
pre-in
 
     npm install
 
-All of the build tasks can be run via the `jake` node module. Install it globally first by
running:
+All of the build tasks can be run via the `grunt` node module. Install it globally first
by running:
 
-    sudo npm install -g jake
-
-Every build also runs the scripts through [JSHint](http://jshint.com). It is best
-installed globally, but it is _not_ necessary for building cordova-js
-(you just won't get syntax and style hints when you build):
-
-    sudo npm install -g jshint
+    sudo npm install -g grunt-cli
 
 Then from the repository root run:
 
-    jake
+    grunt
 
 This will run the `build`, `hint` and `test` tasks by default. All of the available tasks
are:
 
@@ -134,13 +128,13 @@ The `boot` method does all the work.  First, it grabs the common platform
defini
 
 Tests run in node or the browser. To run the tests in node:
     
-    jake test
+    grunt test
 
 To run them in the browser:
 
-    jake btest
+    grunt btest
 
-Final testing should always be done with the [Mobile Spec test application](https://github.com/apache/incubator-cordova-mobile-spec).
+Final testing should always be done with the [Mobile Spec test application](https://github.com/apache/cordova-mobile-spec).
 
 # Integration
 

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/273e0a3a/build/dalek
----------------------------------------------------------------------
diff --git a/build/dalek b/build/dalek
deleted file mode 100644
index fcd5258..0000000
--- a/build/dalek
+++ /dev/null
@@ -1,14 +0,0 @@
-      OBEY! OBEY THE DALEKS! 
-    YOU WILL BE EXTERMINATED!!!
-                   /           
-              ___              
-      D>=G==='   '.            
-            |======|           
-            |======|           
-        )--/]IIIIII]           
-           |_______|           
-           C O O O D           
-          C O  O  O D          
-         C  O  O  O  D         
-         C__O__O__O__D         
-snd     [_____________]        

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/273e0a3a/grunt.js
----------------------------------------------------------------------
diff --git a/grunt.js b/grunt.js
deleted file mode 100644
index 7617f2b..0000000
--- a/grunt.js
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
- 
-// open "http://search.npmjs.org/#/grunt" ; sudo npm -g install grunt
-
-var child_process = require("child_process")
-
-//------------------------------------------------------------------------------
-// list of source files to watch
-//------------------------------------------------------------------------------
-var sourceFiles = [
-    "build/**/*.js", 
-    "grunt.js",
-    "Jakefile",
-    "lib/**/*.js",
-    "test/**/*.js"
-]
-
-//------------------------------------------------------------------------------
-var gruntConfig = {
-    watch: {
-        jake: {
-            files: sourceFiles,
-            tasks: ["jake"]
-        }
-    }
-}
-
-//------------------------------------------------------------------------------
-// run "jake"
-//------------------------------------------------------------------------------
-function jakeTask(grunt) {
-    var done = this.async()
-    var make = child_process.spawn('jake')
-    
-    make.stdout.on("data", function(data) {
-        grunt.log.write("" + data)
-    })
-    
-    make.stderr.on("data", function(data) {
-        grunt.log.error("" + data)
-    })
-    
-    make.on("exit", function(code) {
-        if (code === 0) return done(true)
-        
-        grunt.log.writeln("error running jake", code)
-        return done(false)
-    })
-}
-
-//------------------------------------------------------------------------------
-module.exports = function(grunt) {
-    grunt.initConfig(gruntConfig)
-    
-    grunt.registerTask("default", "watch")
-    grunt.registerTask("jake", "run jake", function(){jakeTask.call(this,grunt)}
-    )
-}

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/273e0a3a/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 2565cf9..f0a82de 100644
--- a/package.json
+++ b/package.json
@@ -5,57 +5,61 @@
   "version": "1.8.1",
   "homepage": "http://incubator.apache.org/cordova/",
   "repository": {
-    "type":"git",
+    "type": "git",
     "url": "http://git-wip-us.apache.org/repos/asf/incubator-cordova-js.git"
   },
   "engines": {
     "node": "~0.6.15"
   },
-  "contributors":[
+  "contributors": [
     {
-      "name":"Fil Maj",
-      "email":"filmaj@apache.org"
+      "name": "Fil Maj",
+      "email": "filmaj@apache.org"
     },
     {
-      "name":"Jesse MacFadyen",
-      "email":"purplecabbage@apache.org"
+      "name": "Jesse MacFadyen",
+      "email": "purplecabbage@apache.org"
     },
     {
-      "name":"Bryce Curtis",
-      "email":""
+      "name": "Bryce Curtis",
+      "email": ""
     },
     {
-      "name":"Drew Walters",
-      "email":""
+      "name": "Drew Walters",
+      "email": ""
     },
     {
-      "name":"Patrick Mueller",
-      "email":""
+      "name": "Patrick Mueller",
+      "email": ""
     },
     {
-      "name":"Simon MacDonald",
-      "email":""
+      "name": "Simon MacDonald",
+      "email": ""
     },
     {
-      "name":"Becky Gibson",
-      "email":""
+      "name": "Becky Gibson",
+      "email": ""
     },
     {
-      "name":"Anis Kadri",
-      "email":""
+      "name": "Anis Kadri",
+      "email": ""
     },
     {
-      "name":"Dan Silivestru",
-      "email":"dansilivestru@apache.org"
+      "name": "Dan Silivestru",
+      "email": "dansilivestru@apache.org"
     },
     {
-      "name":"Shazron Abdullah",
-      "email":"shazron@apache.org"
+      "name": "Shazron Abdullah",
+      "email": "shazron@apache.org"
     }
   ],
   "dependencies": {
-    "jsdom":"0.2.14",
-    "connect":"1.8.5"
+    "jsdom": "0.2.14",
+    "connect": "1.8.5"
   },
-  "devDependencies": {}
+  "devDependencies": {
+    "grunt": "~0.4.1",
+    "grunt-contrib-clean": "~0.4.1",
+    "grunt-contrib-jshint": "~0.6.0"
+  }
 }

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/273e0a3a/test/runner.js
----------------------------------------------------------------------
diff --git a/test/runner.js b/test/runner.js
index c908cf3..51846ba 100644
--- a/test/runner.js
+++ b/test/runner.js
@@ -41,7 +41,7 @@ function collect(path, files, matches) {
 }
 
 module.exports = {
-    node: function () {
+    node: function(callback) {
         console.log('starting node-based tests')
         var jas = require("../thirdparty/jasmine/jasmine"),
             TerminalReporter = require('./reporter').TerminalReporter,
@@ -53,8 +53,7 @@ module.exports = {
             window = document.createWindow();
         } catch (e) {
             //no jsDom (some people don't have compilers)
-            console.log("can't run tests in node: run jake btest instead, or install jsdom
via: npm install");
-            return;
+            throw new Error("can't run tests in node: run jake btest instead, or install
jsdom via: npm install");
         }
 
         //Put jasmine in scope
@@ -62,9 +61,6 @@ module.exports = {
             this[key] = window[key] = global[key] = jas[key];
         });
 
-        //regenerate platform file
-        packager.generate('test');
-
         //load in our modules
         var testLibName = _path.join(__dirname, '..', 'pkg', 'cordova.test.js')
         var testLib     = fs.readFileSync(testLibName, 'utf8')
@@ -90,7 +86,7 @@ module.exports = {
         var env = jasmine.getEnv();
         env.addReporter(new TerminalReporter({
             color: true,
-            onComplete: process.exit
+            onComplete: function() { callback(true); }
         }));
 
         console.log("------------");


Mime
View raw message