You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2016/08/09 23:27:44 UTC

[12/19] cordova-lib git commit: CB-11652 Update run and emulate to skip build

CB-11652 Update run and emulate to skip build

We need to add this conditional logic to cordova's `run` and
`emulate` methods to skip build when `--nobuild` option is
specified. CLI previously has delegated this logic to platform's
`run` method but since introducing `before_deploy` hook we call
platform's `build` and `run` separately and so we need to handle
this option in CLI


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/3e1a5cdb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/3e1a5cdb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/3e1a5cdb

Branch: refs/heads/common-1.4.x
Commit: 3e1a5cdb3eb4331de81342aae47131d5a4ddc061
Parents: 68af465
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Tue Aug 2 15:08:24 2016 +0300
Committer: Vladimir Kotikov <v-...@microsoft.com>
Committed: Wed Aug 3 12:55:17 2016 +0300

----------------------------------------------------------------------
 cordova-lib/spec-cordova/emulate.spec.js | 24 ++++++++++++++++++++++
 cordova-lib/spec-cordova/run.spec.js     | 25 +++++++++++++++++++++++
 cordova-lib/src/cordova/emulate.js       | 29 ++++++++++++++-------------
 cordova-lib/src/cordova/run.js           | 29 ++++++++++++++-------------
 4 files changed, 79 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3e1a5cdb/cordova-lib/spec-cordova/emulate.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/emulate.spec.js b/cordova-lib/spec-cordova/emulate.spec.js
index c04c16d..94b2ab9 100644
--- a/cordova-lib/spec-cordova/emulate.spec.js
+++ b/cordova-lib/spec-cordova/emulate.spec.js
@@ -131,6 +131,30 @@ describe('emulate command', function() {
                 }).fin(done);
             });
         });
+
+        it('should call platform\'s build method', function (done) {
+            cordova.raw.emulate({platforms: ['blackberry10']})
+            .then(function() {
+                expect(prepare_spy).toHaveBeenCalled();
+                expect(platformApi.build).toHaveBeenCalledWith({device: false, emulator: true});
+                expect(platformApi.run).toHaveBeenCalledWith(jasmine.objectContaining({nobuild: true}));
+            }, function(err) {
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
+        });
+
+        it('should not call build if --nobuild option is passed', function (done) {
+            cordova.raw.emulate({platforms: ['blackberry10'], options: { nobuild: true }})
+            .then(function() {
+                expect(prepare_spy).toHaveBeenCalled();
+                expect(platformApi.build).not.toHaveBeenCalled();
+                expect(platformApi.run).toHaveBeenCalledWith(jasmine.objectContaining({nobuild: true}));
+            }, function(err) {
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
+        });
     });
 
     describe('hooks', function() {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3e1a5cdb/cordova-lib/spec-cordova/run.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/run.spec.js b/cordova-lib/spec-cordova/run.spec.js
index b1dedd3..2b09e04 100644
--- a/cordova-lib/spec-cordova/run.spec.js
+++ b/cordova-lib/spec-cordova/run.spec.js
@@ -107,6 +107,31 @@ describe('run command', function() {
                 done();
             });
         });
+
+        it('should call platform\'s build method', function (done) {
+            cordova.raw.run({platforms: ['blackberry10']})
+            .then(function() {
+                expect(prepare_spy).toHaveBeenCalled();
+                expect(platformApi.build).toHaveBeenCalledWith({});
+                expect(platformApi.run).toHaveBeenCalledWith(jasmine.objectContaining({nobuild: true}));
+            }, function(err) {
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
+        });
+
+        it('should not call build if --nobuild option is passed', function (done) {
+            cordova.raw.run({platforms: ['blackberry10'], options: { nobuild: true }})
+            .then(function() {
+                expect(prepare_spy).toHaveBeenCalled();
+                expect(platformApi.build).not.toHaveBeenCalled();
+                expect(platformApi.run).toHaveBeenCalledWith(jasmine.objectContaining({nobuild: true}));
+            }, function(err) {
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
+        });
+
         describe('run parameters should not be altered by intermediate build command', function() {
             var originalBuildSpy;
             beforeEach(function() {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3e1a5cdb/cordova-lib/src/cordova/emulate.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/emulate.js b/cordova-lib/src/cordova/emulate.js
index 642e55c..fdb0f13 100644
--- a/cordova-lib/src/cordova/emulate.js
+++ b/cordova-lib/src/cordova/emulate.js
@@ -32,6 +32,10 @@ module.exports = function emulate(options) {
         options.options.device = false;
         options.options.emulator = true;
 
+        var optsClone = _.clone(options.options);
+        // This is needed as .build modifies opts
+        optsClone.nobuild = true;
+
         var hooksRunner = new HooksRunner(projectRoot);
         return hooksRunner.fire('before_emulate', options)
         .then(function() {
@@ -42,20 +46,17 @@ module.exports = function emulate(options) {
         }).then(function() {
             // Deploy in parallel (output gets intermixed though...)
             return Q.all(options.platforms.map(function(platform) {
-                // This is needed as .build modifies opts
-                var optsClone = _.clone(options.options);
-                return platform_lib
-                    .getPlatformApi(platform)
-                    .build(options.options)
-                    .then(function() {
-                        return hooksRunner.fire('before_deploy', options);
-                    })
-                    .then(function() {
-                        optsClone.nobuild = true;
-                        return platform_lib
-                            .getPlatformApi(platform)
-                            .run(optsClone);
-                    });
+
+                var buildPromise = options.options.nobuild ? Q() :
+                    platform_lib.getPlatformApi(platform).build(options.options);
+
+                return buildPromise
+                .then(function() {
+                    return hooksRunner.fire('before_deploy', options);
+                })
+                .then(function() {
+                    return platform_lib.getPlatformApi(platform).run(optsClone);
+                });
             }));
         }).then(function() {
             return hooksRunner.fire('after_emulate', options);

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/3e1a5cdb/cordova-lib/src/cordova/run.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/run.js b/cordova-lib/src/cordova/run.js
index 74fe8f5..34a76da 100644
--- a/cordova-lib/src/cordova/run.js
+++ b/cordova-lib/src/cordova/run.js
@@ -30,6 +30,10 @@ module.exports = function run(options) {
         var projectRoot = cordova_util.cdProjectRoot();
         options = cordova_util.preProcessOptions(options);
 
+        // This is needed as .build modifies opts
+        var optsClone = _.clone(options.options);
+        optsClone.nobuild = true;
+
         var hooksRunner = new HooksRunner(projectRoot);
         return hooksRunner.fire('before_run', options)
         .then(function() {
@@ -40,20 +44,17 @@ module.exports = function run(options) {
         }).then(function() {
             // Deploy in parallel (output gets intermixed though...)
             return Q.all(options.platforms.map(function(platform) {
-                // This is needed as .build modifies opts
-                var optsClone = _.clone(options.options);
-                return platform_lib
-                    .getPlatformApi(platform)
-                    .build(options.options)
-                    .then(function() {
-                        return hooksRunner.fire('before_deploy', options);
-                    })
-                    .then(function() {
-                        optsClone.nobuild = true;
-                        return platform_lib
-                            .getPlatformApi(platform)
-                            .run(optsClone);
-                    });
+
+                var buildPromise = options.options.nobuild ? Q() :
+                    platform_lib.getPlatformApi(platform).build(options.options);
+
+                return buildPromise
+                .then(function() {
+                    return hooksRunner.fire('before_deploy', options);
+                })
+                .then(function() {
+                    return platform_lib.getPlatformApi(platform).run(optsClone);
+                });
             }));
         }).then(function() {
             return hooksRunner.fire('after_run', options);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org