Updated Branches:
  refs/heads/cordova-client 01324a772 -> 4d7699699

Allow specifying one or more platforms to build/emulate. Fixes #32. Closes #38.


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/4d769969
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/4d769969
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/4d769969

Branch: refs/heads/cordova-client
Commit: 4d7699699f63c9a8c3f9cac0e0c28cd9456a554e
Parents: e8fdc25
Author: Fil Maj <maj....@gmail.com>
Authored: Wed Oct 3 11:35:45 2012 -0700
Committer: Fil Maj <maj....@gmail.com>
Committed: Wed Oct 3 11:35:45 2012 -0700

----------------------------------------------------------------------
 spec/build.spec.js   |   71 +++++++++++++++++++++++++++++++++++++++++++++
 spec/emulate.spec.js |   70 ++++++++++++++++++++++++++++++++++++++++++++
 src/build.js         |   15 ++++++++-
 src/emulate.js       |   20 +++++++++++-
 4 files changed, 172 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/4d769969/spec/build.spec.js
----------------------------------------------------------------------
diff --git a/spec/build.spec.js b/spec/build.spec.js
index 9aaabec..db360cd 100644
--- a/spec/build.spec.js
+++ b/spec/build.spec.js
@@ -164,4 +164,75 @@ describe('build command', function() {
             });
         });
     });
+
+    describe('specifying platforms to build', function() {
+        beforeEach(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+            cordova.platform('add', 'android');
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+            shell.rm('-rf', tempDir);
+        });
+        it('should only build the specified platform (array notation)', 
function() {
+            var cb = jasmine.createSpy();
+            var buildcb = jasmine.createSpy();
+            var s;
+            runs(function() {
+                cordova.platform('add', 'ios', cb);
+            });
+            waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
+            runs(function() {
+                s = spyOn(shell, 'exec').andReturn({code:0});
+                cordova.build(['android'], buildcb);
+            });
+            waitsFor(function() { return buildcb.wasCalled; }, 'build 
android');
+            runs(function() {
+                expect(s.callCount).toEqual(1);
+            });
+        });
+        it('should only build the specified platform (string notation)', 
function() {
+            var cb = jasmine.createSpy();
+            var buildcb = jasmine.createSpy();
+            var s;
+            runs(function() {
+                cordova.platform('add', 'ios', cb);
+            });
+            waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
+            runs(function() {
+                s = spyOn(shell, 'exec').andReturn({code:0});
+                cordova.build('android', buildcb);
+            });
+            waitsFor(function() { return buildcb.wasCalled; }, 'build 
android');
+            runs(function() {
+                expect(s.callCount).toEqual(1);
+            });
+        });
+        it('should handle multiple platforms to be built', function() {
+            var cb = jasmine.createSpy();
+            var bbcb = jasmine.createSpy();
+            var buildcb = jasmine.createSpy();
+            var s;
+            runs(function() {
+                cordova.platform('add', 'ios', cb);
+            });
+            waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
+            runs(function() {
+                var g = spyOn(require('prompt'), 'get');
+                cordova.platform('add', 'blackberry-10', bbcb);
+                g.mostRecentCall.args[1](null, {}); // fake out prompt io
+            });
+            waitsFor(function() { return bbcb.wasCalled; }, 'platform add bb');
+            runs(function() {
+                s = spyOn(shell, 'exec').andReturn({code:0});
+                cordova.build(['android','ios'], buildcb);
+            });
+            waitsFor(function() { return buildcb.wasCalled; }, 'build 
android+ios');
+            runs(function() {
+                expect(s.callCount).toEqual(2);
+            });
+        });
+    });
 });

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/4d769969/spec/emulate.spec.js
----------------------------------------------------------------------
diff --git a/spec/emulate.spec.js b/spec/emulate.spec.js
index f953500..189a0c2 100644
--- a/spec/emulate.spec.js
+++ b/spec/emulate.spec.js
@@ -169,4 +169,74 @@ describe('emulate command', function() {
             });
         });
     });
+    describe('specifying platforms to emulate', function() {
+        beforeEach(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+            cordova.platform('add', 'android');
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+            shell.rm('-rf', tempDir);
+        });
+        it('should only emulate the specified platform (array notation)', 
function() {
+            var cb = jasmine.createSpy();
+            var buildcb = jasmine.createSpy();
+            var s;
+            runs(function() {
+                cordova.platform('add', 'ios', cb);
+            });
+            waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
+            runs(function() {
+                s = spyOn(shell, 'exec').andReturn({code:0});
+                cordova.build(['android'], buildcb);
+            });
+            waitsFor(function() { return buildcb.wasCalled; }, 'emulate 
android');
+            runs(function() {
+                expect(s.callCount).toEqual(1);
+            });
+        });
+        it('should only emulate the specified platform (string notation)', 
function() {
+            var cb = jasmine.createSpy();
+            var buildcb = jasmine.createSpy();
+            var s;
+            runs(function() {
+                cordova.platform('add', 'ios', cb);
+            });
+            waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
+            runs(function() {
+                s = spyOn(shell, 'exec').andReturn({code:0});
+                cordova.build('android', buildcb);
+            });
+            waitsFor(function() { return buildcb.wasCalled; }, 'emulate 
android');
+            runs(function() {
+                expect(s.callCount).toEqual(1);
+            });
+        });
+        it('should handle multiple platforms to be emulated', function() {
+            var cb = jasmine.createSpy();
+            var bbcb = jasmine.createSpy();
+            var buildcb = jasmine.createSpy();
+            var s;
+            runs(function() {
+                cordova.platform('add', 'ios', cb);
+            });
+            waitsFor(function() { return cb.wasCalled; }, 'platform add ios');
+            runs(function() {
+                var g = spyOn(require('prompt'), 'get');
+                cordova.platform('add', 'blackberry-10', bbcb);
+                g.mostRecentCall.args[1](null, {}); // fake out prompt io
+            });
+            waitsFor(function() { return bbcb.wasCalled; }, 'platform add bb');
+            runs(function() {
+                s = spyOn(shell, 'exec').andReturn({code:0});
+                cordova.build(['android','ios'], buildcb);
+            });
+            waitsFor(function() { return buildcb.wasCalled; }, 'emulate 
android+ios');
+            runs(function() {
+                expect(s.callCount).toEqual(2);
+            });
+        });
+    });
 });

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/4d769969/src/build.js
----------------------------------------------------------------------
diff --git a/src/build.js b/src/build.js
index 88dc00a..1af02ec 100644
--- a/src/build.js
+++ b/src/build.js
@@ -36,8 +36,19 @@ module.exports = function build (platforms, callback) {
 
     if (arguments.length === 0) {
         platforms = platform('ls');
-    } else if (!(platforms instanceof Array)) {
-        platforms = [platforms];
+    } else {
+        if (arguments[arguments.length-1] instanceof Function) {
+            // Called through JS, check platforms param
+            if (platforms instanceof Function) {
+                callback = platforms;
+                platforms = platform('ls');
+            } else if (!(platforms instanceof Array)) platforms = [platforms];
+        } else {
+            // Called through CLI; no callback 
+            if (arguments[0] instanceof Array) platforms = arguments[0];
+            else platforms = Array.prototype.slice.call(arguments, 0);
+            callback = undefined;
+        }
     }
 
     if (platforms.length === 0) throw 'No platforms added to this project. 
Please use `cordova platform add <platform>`.';

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/4d769969/src/emulate.js
----------------------------------------------------------------------
diff --git a/src/emulate.js b/src/emulate.js
index 8b39693..5e59ec0 100644
--- a/src/emulate.js
+++ b/src/emulate.js
@@ -20,7 +20,7 @@ function shell_out_to_emulate(root, platform) {
     if (em.code > 0) throw 'An error occurred while emulating/deploying the ' 
+ platform + ' project.' + em.output;
 }
 
-module.exports = function emulate (callback) {
+module.exports = function emulate (platforms, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
     if (!projectRoot) {
@@ -29,7 +29,23 @@ module.exports = function emulate (callback) {
 
     var xml = path.join(projectRoot, 'www', 'config.xml');
     var cfg = new config_parser(xml);
-    var platforms = platform('ls');
+
+    if (arguments.length === 0) {
+        platforms = platform('ls');
+    } else {
+        if (arguments[arguments.length-1] instanceof Function) {
+            // Called through JS, check platforms param
+            if (platforms instanceof Function) {
+                callback = platforms;
+                platforms = platform('ls');
+            } else if (!(platforms instanceof Array)) platforms = [platforms];
+        } else {
+            // Called through CLI; no callback 
+            if (arguments[0] instanceof Array) platforms = arguments[0];
+            else platforms = Array.prototype.slice.call(arguments, 0);
+            callback = undefined;
+        }
+    }
 
     if (platforms.length === 0) throw 'No platforms added to this project. 
Please use `cordova platform add <platform>`.';
 

Reply via email to