You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2012/07/27 02:29:15 UTC

[16/78] [abbrv] git commit: help updates, sped up tests, routing certain calls to null so as to not overload exec buffer.

help updates, sped up tests, routing certain calls to null so as to not overload exec buffer.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/9f966c2d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/9f966c2d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/9f966c2d

Branch: refs/heads/cordova-client
Commit: 9f966c2d603a3e6dbf7a8fa00d92bd78e3ca62a9
Parents: 61782b8
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jul 18 23:05:05 2012 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jul 18 23:05:05 2012 -0700

----------------------------------------------------------------------
 bin/cordova            |   10 ++--
 cordova.js             |    7 ++-
 doc/help.txt           |    2 +-
 spec/_platform.spec.js |  135 +++++++++++++++++++++++++++++++++++++++++++
 spec/cli.spec.js       |    6 --
 spec/create.spec.js    |    5 +-
 spec/platform.spec.js  |  121 --------------------------------------
 src/build.js           |    2 +-
 8 files changed, 150 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/9f966c2d/bin/cordova
----------------------------------------------------------------------
diff --git a/bin/cordova b/bin/cordova
index 19624bd..439ea35 100755
--- a/bin/cordova
+++ b/bin/cordova
@@ -3,16 +3,16 @@ var cordova = require('./../cordova')
 ,   cmd     = process.argv[2]
 ,   opts    = process.argv.slice(3, process.argv.length)
 
-if (cordova.hasOwnProperty(cmd)) {
+if (cmd === undefined)  {
+    console.log(cordova.help());
+} else if (cordova.hasOwnProperty(cmd)) {
     try {
-        console.log(cordova[cmd].apply(this, opts));
+        var r = cordova[cmd].apply(this, opts);
+        if (r) console.log(r);
     } catch(e) {
         console.error(e);
     }
 }
-else if (cmd === undefined) {
-    console.log(cordova.help());
-}
 else {
     console.error('Cordova does not know ' + cmd + '; try help for a list of all the available commands.')
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/9f966c2d/cordova.js
----------------------------------------------------------------------
diff --git a/cordova.js b/cordova.js
index de3a499..e29bd53 100755
--- a/cordova.js
+++ b/cordova.js
@@ -11,7 +11,7 @@ var fs            = require('fs')
 module.exports = {
     help: function help () {
         var raw = fs.readFileSync(path.join(__dirname, 'doc', 'help.txt')).toString('utf8').split("\n");
-        raw.map(function(line) {
+        return raw.map(function(line) {
             if (line.match('    ')) {
                 var prompt = '    $ '
                 ,   isPromptLine = !!(line.indexOf(prompt) != -1);
@@ -55,6 +55,11 @@ module.exports = {
         server.listen(parseInt(port, 10));
     },
     create: function create (dir) {
+        if (dir === undefined) {
+            return module.exports.help();
+        }
+
+
         var mkdirp = wrench.mkdirSyncRecursive,
             cpr = wrench.copyDirSyncRecursive;
         if (dir && (dir[0] == '~' || dir[0] == '/')) {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/9f966c2d/doc/help.txt
----------------------------------------------------------------------
diff --git a/doc/help.txt b/doc/help.txt
index 4a7ea82..fdc2cba 100644
--- a/doc/help.txt
+++ b/doc/help.txt
@@ -5,7 +5,7 @@ Synopsis
 
 Global Commands
 
-    create ............................ creates a cordova project
+    create [path]...................... creates a cordova project in the specified directory
 
 Project-Level Commands
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/9f966c2d/spec/_platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/_platform.spec.js b/spec/_platform.spec.js
new file mode 100644
index 0000000..378d705
--- /dev/null
+++ b/spec/_platform.spec.js
@@ -0,0 +1,135 @@
+// Spy on exec so we can mock out certain CLI calls (and speed up
+// testing)
+var _exec = require('child_process').exec;
+require('child_process').exec = function(cmd, cb){
+    var space = cmd.indexOf(' ');
+    // Just invoke callback for create calls.
+    if (Array.prototype.slice.call(cmd, space-6, space).join('') == 'create') {
+        cb();
+    } else {
+        _exec(cmd, cb);
+    }
+};
+
+var cordova = require('../cordova'),
+    wrench = require('wrench'),
+    mkdirp = wrench.mkdirSyncRecursive,
+    path = require('path'),
+    rmrf = wrench.rmdirSyncRecursive,
+    fs = require('fs'),
+    tempDir = path.join(__dirname, '..', 'temp');
+
+
+describe('platform command', function() {
+    beforeEach(function() {
+        // Make a temp directory
+        try { rmrf(tempDir); } catch(e) {}
+        mkdirp(tempDir);
+    });
+
+    it('should run inside a Cordova-based project', function() {
+        var cwd = process.cwd();
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        cordova.create(tempDir);
+
+        process.chdir(tempDir);
+
+        expect(function() {
+            cordova.platform();
+        }).not.toThrow();
+    });
+    it('should not run outside of a Cordova-based project', function() {
+        var cwd = process.cwd();
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        process.chdir(tempDir);
+
+        expect(function() {
+            cordova.platform();
+        }).toThrow();
+    });
+
+    describe('ls', function() {
+        var cwd = process.cwd();
+
+        beforeEach(function() {
+            cordova.create(tempDir);
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+        });
+
+        it('should list out no platforms for a fresh project', function() {
+            process.chdir(tempDir);
+
+            expect(cordova.platform('ls')).toEqual('No platforms added. Use `cordova platform add <platform>`.');
+        });
+
+        it('should list out added platforms in a project', function() {
+            var cb = jasmine.createSpy().andCallFake(function() {
+                expect(cordova.platform('ls')).toEqual('android');
+            });
+
+            process.chdir(tempDir);
+            runs(function() {
+                cordova.platform('add', 'android', cb);
+            });
+            waitsFor(function() { return cb.wasCalled; }, "create callback", 17500);
+        });
+    });
+
+    describe('add', function() {
+        var cwd = process.cwd();
+
+        beforeEach(function() {
+            cordova.create(tempDir);
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+        });
+
+        it('should add a supported platform', function() {
+            var cb = jasmine.createSpy().andCallFake(function() {
+                expect(cordova.platform('ls')).toEqual('android');
+            });
+
+            process.chdir(tempDir);
+            runs(function() {
+                cordova.platform('add', 'android', cb);
+            });
+            waitsFor(function() { return cb.wasCalled; }, "create callback", 17500);
+        });
+    });
+
+    describe('remove', function() {
+        var cwd = process.cwd();
+
+        beforeEach(function() {
+            cordova.create(tempDir);
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+        });
+
+        it('should remove a supported and added platform', function() {
+            var cb = jasmine.createSpy().andCallFake(function() {
+                cordova.platform('remove', 'android');
+                expect(cordova.platform('ls')).toEqual('No platforms added. Use `cordova platform add <platform>`.');
+            });
+
+            process.chdir(tempDir);
+            runs(function() {
+                cordova.platform('add', 'android', cb);
+            });
+            waitsFor(function() { return cb.wasCalled; }, "create callback", 17500);
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/9f966c2d/spec/cli.spec.js
----------------------------------------------------------------------
diff --git a/spec/cli.spec.js b/spec/cli.spec.js
deleted file mode 100644
index 0a5e5e9..0000000
--- a/spec/cli.spec.js
+++ /dev/null
@@ -1,6 +0,0 @@
-var cordova = require('../cordova');
-
-describe("cordova", function() {
-    describe("'help' command", function() {
-    });
-});

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/9f966c2d/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/create.spec.js b/spec/create.spec.js
index 5af6277..bdd2ceb 100644
--- a/spec/create.spec.js
+++ b/spec/create.spec.js
@@ -13,14 +13,13 @@ describe('create command', function () {
         mkdirp(tempDir);
     });
 
-    it('should create a cordova project in the current directory if no parameter is provided', function() {
+    it('should print out help txt if no directory is provided', function() {
         var cwd = process.cwd();
         this.after(function() {
             process.chdir(cwd);
         });
         process.chdir(tempDir);
-        cordova.create();
-        expect(fs.lstatSync(path.join(tempDir, '.cordova')).isDirectory()).toBe(true);
+        expect(cordova.create()).toMatch(/synopsis/i);
     });
     it('should create a cordova project in the specified directory if parameter is provided', function() {
         cordova.create(tempDir);

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/9f966c2d/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
deleted file mode 100644
index b147e03..0000000
--- a/spec/platform.spec.js
+++ /dev/null
@@ -1,121 +0,0 @@
-var cordova = require('../cordova'),
-    wrench = require('wrench'),
-    mkdirp = wrench.mkdirSyncRecursive,
-    path = require('path'),
-    rmrf = wrench.rmdirSyncRecursive,
-    fs = require('fs'),
-    tempDir = path.join(__dirname, '..', 'temp');
-
-describe('platform command', function() {
-    beforeEach(function() {
-        // Make a temp directory
-        try { rmrf(tempDir); } catch(e) {}
-        mkdirp(tempDir);
-    });
-
-    it('should run inside a Cordova-based project', function() {
-        var cwd = process.cwd();
-        this.after(function() {
-            process.chdir(cwd);
-        });
-
-        cordova.create(tempDir);
-
-        process.chdir(tempDir);
-
-        expect(function() {
-            cordova.platform();
-        }).not.toThrow();
-    });
-    it('should not run outside of a Cordova-based project', function() {
-        var cwd = process.cwd();
-        this.after(function() {
-            process.chdir(cwd);
-        });
-
-        process.chdir(tempDir);
-
-        expect(function() {
-            cordova.platform();
-        }).toThrow();
-    });
-
-    describe('ls', function() {
-        var cwd = process.cwd();
-
-        beforeEach(function() {
-            cordova.create(tempDir);
-        });
-
-        afterEach(function() {
-            process.chdir(cwd);
-        });
-
-        it('should list out no platforms for a fresh project', function() {
-            process.chdir(tempDir);
-
-            expect(cordova.platform('ls')).toEqual('No platforms added. Use `cordova platform add <platform>`.');
-        });
-
-        it('should list out added platforms in a project', function() {
-            var cb = jasmine.createSpy().andCallFake(function() {
-                expect(cordova.platform('ls')).toEqual('android');
-            });
-
-            process.chdir(tempDir);
-            runs(function() {
-                cordova.platform('add', 'android', cb);
-            });
-            waitsFor(function() { return cb.wasCalled; }, "create callback", 17500);
-        });
-    });
-
-    describe('add', function() {
-        var cwd = process.cwd();
-
-        beforeEach(function() {
-            cordova.create(tempDir);
-        });
-
-        afterEach(function() {
-            process.chdir(cwd);
-        });
-
-        it('should add a supported platform', function() {
-            var cb = jasmine.createSpy().andCallFake(function() {
-                expect(cordova.platform('ls')).toEqual('android');
-            });
-
-            process.chdir(tempDir);
-            runs(function() {
-                cordova.platform('add', 'android', cb);
-            });
-            waitsFor(function() { return cb.wasCalled; }, "create callback", 17500);
-        });
-    });
-
-    describe('remove', function() {
-        var cwd = process.cwd();
-
-        beforeEach(function() {
-            cordova.create(tempDir);
-        });
-
-        afterEach(function() {
-            process.chdir(cwd);
-        });
-
-        it('should remove a supported and added platform', function() {
-            var cb = jasmine.createSpy().andCallFake(function() {
-                cordova.platform('remove', 'android');
-                expect(cordova.platform('ls')).toEqual('No platforms added. Use `cordova platform add <platform>`.');
-            });
-
-            process.chdir(tempDir);
-            runs(function() {
-                cordova.platform('add', 'android', cb);
-            });
-            waitsFor(function() { return cb.wasCalled; }, "create callback", 17500);
-        });
-    });
-});

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/9f966c2d/src/build.js
----------------------------------------------------------------------
diff --git a/src/build.js b/src/build.js
index 1efa1ff..fc9453e 100644
--- a/src/build.js
+++ b/src/build.js
@@ -49,7 +49,7 @@ module.exports = function build () {
         fs.writeFileSync(jsPath, fs.readFileSync(js));
 
         // shell out to debug command
-        var cmd = path.join(projectRoot, 'platforms', platform, 'cordova', 'debug');
+        var cmd = path.join(projectRoot, 'platforms', platform, 'cordova', 'debug > /dev/null');
         exec(cmd, function(err, stderr, stdout) {
             if (err) throw 'An error occurred while building the ' + platform + ' project. ' + err;
         });