You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/02/16 02:29:19 UTC

git commit: 2.4.9. Fixed an issue where .gitignore was treated as a platform, added a utility "listPlatforms" function as a result. Fixed emulate specs following making a callback mandatory for all project parser update_project methods.

Updated Branches:
  refs/heads/master 4304acb0c -> 64e06c551


2.4.9. Fixed an issue where .gitignore was treated as a platform, added a utility "listPlatforms" function as a result. Fixed emulate specs following making a callback mandatory for all project parser update_project methods.


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/64e06c55
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/64e06c55
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/64e06c55

Branch: refs/heads/master
Commit: 64e06c55179cdef3dbb249388df18d245a29f80b
Parents: 4304acb
Author: Fil Maj <ma...@gmail.com>
Authored: Fri Feb 15 17:29:12 2013 -0800
Committer: Fil Maj <ma...@gmail.com>
Committed: Fri Feb 15 17:29:12 2013 -0800

----------------------------------------------------------------------
 package.json         |    2 +-
 spec/compile.spec.js |   14 ++++++++-
 spec/emulate.spec.js |    4 ++-
 src/compile.js       |   35 +++++++++++-----------
 src/emulate.js       |   70 ++++++++++++++++----------------------------
 src/plugin.js        |    3 +-
 src/prepare.js       |    5 +--
 src/serve.js         |    3 +-
 src/util.js          |    6 ++++
 9 files changed, 71 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/64e06c55/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index f5b8e21..54b27a7 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "cordova",
-  "version": "2.4.8",
+  "version": "2.4.9",
   "preferGlobal": "true",
   "description": "Cordova command line interface tool",
   "main": "cordova",

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/64e06c55/spec/compile.spec.js
----------------------------------------------------------------------
diff --git a/spec/compile.spec.js b/spec/compile.spec.js
index bc131a0..f13792a 100644
--- a/spec/compile.spec.js
+++ b/spec/compile.spec.js
@@ -157,11 +157,23 @@ describe('compile command', function() {
         });
         describe('BlackBerry', function() {
             it('should shell out to ant command on blackberry', function() {
-                var s = spyOn(require('shelljs'), 'exec');
+                var s = spyOn(shell, 'exec');
                 cordova.compile('blackberry');
                 expect(s).toHaveBeenCalled();
                 expect(s.mostRecentCall.args[0]).toMatch(/ant -f .*build\.xml" qnx load-device/);
             });
         });
+        it('should not treat a .gitignore file as a platform', function() {
+            var gitignore = path.join(cordova_project, 'platforms', '.gitignore');
+            fs.writeFileSync(gitignore, 'somethinghere', 'utf-8');
+            this.after(function() {
+                shell.rm('-f', gitignore);
+            });
+            var s = spyOn(shell, 'exec');
+            cordova.compile();
+            expect(s.calls[0].args[0]).not.toMatch(/\.gitignore/);
+            expect(s.calls[1].args[0]).not.toMatch(/\.gitignore/);
+            expect(s.calls[1].args[0]).not.toMatch(/\.gitignore/);
+        });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/64e06c55/spec/emulate.spec.js
----------------------------------------------------------------------
diff --git a/spec/emulate.spec.js b/spec/emulate.spec.js
index ac6d115..3a4d1a4 100644
--- a/spec/emulate.spec.js
+++ b/spec/emulate.spec.js
@@ -63,9 +63,10 @@ describe('emulate command', function() {
         process.chdir(cordova_project);
 
         var s = spyOn(shell, 'exec');
-        spyOn(android_parser.prototype, 'update_project');
+        var a_spy = spyOn(android_parser.prototype, 'update_project');
         expect(function() {
             cordova.emulate();
+            a_spy.mostRecentCall.args[1](); // fake out android parser
             expect(s).toHaveBeenCalled();
         }).not.toThrow();
     });
@@ -163,6 +164,7 @@ describe('emulate command', function() {
             });
             it('should fire after hooks through the hooker module', function() {
                 cordova.emulate();
+                ap.mostRecentCall.args[1](); // fake parser call
                 sh.mostRecentCall.args[2](0); //fake shell call
                 expect(s).toHaveBeenCalledWith('after_emulate');
             });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/64e06c55/src/compile.js
----------------------------------------------------------------------
diff --git a/src/compile.js b/src/compile.js
index 1833dce..521451f 100644
--- a/src/compile.js
+++ b/src/compile.js
@@ -16,21 +16,20 @@
     specific language governing permissions and limitations
     under the License.
 */
-var cordova_util  = require('./util'),
-    path          = require('path'),
-    config_parser = require('./config_parser'),
-    platform      = require('./platform'),
-    fs            = require('fs'),
-    shell         = require('shelljs'),
-    ls            = fs.readdirSync,
-    et            = require('elementtree'),
-    android_parser= require('./metadata/android_parser'),
-    blackberry_parser= require('./metadata/blackberry_parser'),
-    ios_parser    = require('./metadata/ios_parser'),
-    hooker        = require('./hooker'),
-    n             = require('ncallbacks'),
-    prompt        = require('prompt'),
-    util          = require('util');
+var cordova_util      = require('./util'),
+    path              = require('path'),
+    config_parser     = require('./config_parser'),
+    platform          = require('./platform'),
+    fs                = require('fs'),
+    shell             = require('shelljs'),
+    et                = require('elementtree'),
+    android_parser    = require('./metadata/android_parser'),
+    blackberry_parser = require('./metadata/blackberry_parser'),
+    ios_parser        = require('./metadata/ios_parser'),
+    hooker            = require('./hooker'),
+    n                 = require('ncallbacks'),
+    prompt            = require('prompt'),
+    util              = require('util');
 
 
 function shell_out_to_debug(projectRoot, platform, callback) {
@@ -40,7 +39,7 @@ function shell_out_to_debug(projectRoot, platform, callback) {
     if (platform == 'blackberry') {
         cmd = 'ant -f "' + path.join(cmd, 'build.xml') + '" qnx load-device';
     } else {
-        cmd = '"' + cmd + '/cordova/build"';
+        cmd = '"' + path.join(cmd, 'cordova', 'build') + '"';
     }
     shell.exec(cmd, {silent:true, async:true}, function(code, output) {
         if (code > 0) {
@@ -64,11 +63,11 @@ module.exports = function compile(platforms, callback) {
     var cfg = new config_parser(xml);
 
     if (arguments.length === 0 || (platforms instanceof Array && platforms.length === 0)) {
-        platforms = ls(path.join(projectRoot, 'platforms'));
+        platforms = cordova_util.listPlatforms(projectRoot);
     } else if (typeof platforms == 'string') platforms = [platforms];
     else if (platforms instanceof Function && callback === undefined) {
         callback = platforms;
-        platforms = ls(path.join(projectRoot, 'platforms'));
+        platforms = cordova_util.listPlatforms(projectRoot);
     }
 
     if (platforms.length === 0) throw new Error('No platforms added to this project. Please use `cordova platform add <platform>`.');

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/64e06c55/src/emulate.js
----------------------------------------------------------------------
diff --git a/src/emulate.js b/src/emulate.js
index 39cbb22..d9fce07 100644
--- a/src/emulate.js
+++ b/src/emulate.js
@@ -16,19 +16,25 @@
     specific language governing permissions and limitations
     under the License.
 */
-var cordova_util = require('./util'),
-    path = require('path'),
-    shell = require('shelljs'),
-    config_parser = require('./config_parser'),
-    android_parser = require('./metadata/android_parser'),
-    ios_parser = require('./metadata/ios_parser'),
+var cordova_util      = require('./util'),
+    path              = require('path'),
+    shell             = require('shelljs'),
+    config_parser     = require('./config_parser'),
+    android_parser    = require('./metadata/android_parser'),
+    ios_parser        = require('./metadata/ios_parser'),
     blackberry_parser = require('./metadata/blackberry_parser'),
-    platform = require('./platform'),
-    fs = require('fs'),
-    ls = fs.readdirSync,
-    n = require('ncallbacks'),
-    hooker = require('../src/hooker'),
-    util = require('util');
+    platform          = require('./platform'),
+    fs                = require('fs'),
+    ls                = fs.readdirSync,
+    n                 = require('ncallbacks'),
+    hooker            = require('../src/hooker'),
+    util              = require('util');
+
+var parsers = {
+    "android":android_parser,
+    "ios":ios_parser,
+    "blackberry":blackberry_parser
+};
 
 function shell_out_to_emulate(root, platform, callback) {
     var cmd = path.join(root, 'platforms', platform, 'cordova', 'emulate');
@@ -51,18 +57,18 @@ module.exports = function emulate (platforms, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
     if (!projectRoot) {
-        throw 'Current working directory is not a Cordova-based project.';
+        throw new Error('Current working directory is not a Cordova-based project.');
     }
 
     var xml = path.join(projectRoot, 'www', 'config.xml');
     var cfg = new config_parser(xml);
 
     if (arguments.length === 0 || (platforms instanceof Array && platforms.length === 0)) {
-        platforms = ls(path.join(projectRoot, 'platforms'));
+        platforms = cordova_util.listPlatforms(projectRoot);
     } else if (typeof platforms == 'string') platforms = [platforms];
     else if (platforms instanceof Function && callback === undefined) {
         callback = platforms;
-        platforms = ls(path.join(projectRoot, 'platforms'));
+        platforms = cordova_util.listPlatforms(projectRoot);
     }
 
     if (platforms.length === 0) throw new Error('No platforms added to this project. Please use `cordova platform add <platform>`.');
@@ -81,35 +87,11 @@ module.exports = function emulate (platforms, callback) {
 
     // Iterate over each added platform and shell out to debug command
     platforms.forEach(function(platform) {
-        var parser, platformPath;
-        switch (platform) {
-            case 'android':
-                platformPath = path.join(projectRoot, 'platforms', 'android');
-                parser = new android_parser(platformPath);
-
-                // Update the related platform project from the config
-                parser.update_project(cfg);
-                shell_out_to_emulate(projectRoot, 'android', end);
-                break;
-            case 'blackberry':
-                platformPath = path.join(projectRoot, 'platforms', 'blackberry');
-                parser = new blackberry_parser(platformPath);
-                
-                // Update the related platform project from the config
-                parser.update_project(cfg, function() {
-                    // Shell it
-                    shell_out_to_emulate(projectRoot, 'blackberry', end);
-                });
-                break;
-            case 'ios':
-                platformPath = path.join(projectRoot, 'platforms', 'ios');
-                parser = new ios_parser(platformPath);
-                // Update the related platform project from the config
-                parser.update_project(cfg, function() {
-                    shell_out_to_emulate(projectRoot, 'ios', end);
-                });
-                break;
-        }
+        var platformPath = path.join(projectRoot, 'platforms', platform);
+        var parser = new parsers[platform](platformPath);
+        parser.update_project(cfg, function() {
+            shell_out_to_emulate(projectRoot, platform, end);
+        });
     });
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/64e06c55/src/plugin.js
----------------------------------------------------------------------
diff --git a/src/plugin.js b/src/plugin.js
index 3421b7b..d914df2 100644
--- a/src/plugin.js
+++ b/src/plugin.js
@@ -24,6 +24,7 @@ var cordova_util  = require('./util'),
     shell         = require('shelljs'),
     config_parser = require('./config_parser'),
     hooker        = require('./hooker'),
+    core_platforms= require('../platforms'),
     platform      = require('./platform'),
     plugin_parser = require('./plugin_parser'),
     ls            = fs.readdirSync;
@@ -43,7 +44,7 @@ module.exports = function plugin(command, targets, callback) {
     // Grab config info for the project
     var xml = path.join(projectWww, 'config.xml');
     var cfg = new config_parser(xml);
-    var platforms = ls(path.join(projectRoot, 'platforms'));
+    var platforms = cordova_util.listPlatforms(projectRoot);
 
     // Massage plugin name(s) / path(s)
     var pluginPath, plugins, names = [];

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/64e06c55/src/prepare.js
----------------------------------------------------------------------
diff --git a/src/prepare.js b/src/prepare.js
index fda8d5a..7bb84d7 100644
--- a/src/prepare.js
+++ b/src/prepare.js
@@ -22,7 +22,6 @@ var cordova_util      = require('./util'),
     platform          = require('./platform'),
     fs                = require('fs'),
     shell             = require('shelljs'),
-    ls                = fs.readdirSync,
     et                = require('elementtree'),
     android_parser    = require('./metadata/android_parser'),
     blackberry_parser = require('./metadata/blackberry_parser'),
@@ -50,11 +49,11 @@ module.exports = function prepare(platforms, callback) {
     var cfg = new config_parser(xml);
 
     if (arguments.length === 0 || (platforms instanceof Array && platforms.length === 0)) {
-        platforms = ls(path.join(projectRoot, 'platforms'));
+        platforms = cordova_util.listPlatforms(projectRoot);
     } else if (typeof platforms == 'string') platforms = [platforms];
     else if (platforms instanceof Function && callback === undefined) {
         callback = platforms;
-        platforms = ls(path.join(projectRoot, 'platforms'));
+        platforms = cordova_util.listPlatforms(projectRoot);
     }
 
     if (platforms.length === 0) throw new Error('No platforms added to this project. Please use `cordova platform add <platform>`.');

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/64e06c55/src/serve.js
----------------------------------------------------------------------
diff --git a/src/serve.js b/src/serve.js
index 1b25cbb..b15f907 100644
--- a/src/serve.js
+++ b/src/serve.js
@@ -25,7 +25,6 @@ var cordova_util = require('./util'),
     ios_parser = require('./metadata/ios_parser'),
     blackberry_parser = require('./metadata/blackberry_parser'),
     fs = require('fs'),
-    ls = fs.readdirSync,
     util = require('util'),
     http = require("http"),
     url = require("url");
@@ -90,7 +89,7 @@ module.exports = function serve (platform, port) {
     var cfg = new config_parser(xml);
 
     // Retrieve the platforms.
-    var platforms = ls(path.join(projectRoot, 'platforms'));
+    var platforms = cordova_util.listPlatforms(projectRoot);
     if (!platform) {
         throw 'You need to specify a platform.';
     } else if (platforms.length == 0) {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/64e06c55/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index 98a8b8b..6bd78da 100644
--- a/src/util.js
+++ b/src/util.js
@@ -19,6 +19,7 @@
 */
 var fs         = require('fs'),
     path       = require('path'),
+    core_platforms = require('../platforms'),
     shell      = require('shelljs');
 
 var lib_path = path.join(__dirname, '..', 'lib')
@@ -56,5 +57,10 @@ module.exports = {
                 } else module.exports.deleteSvnFolders(fullpath);
             }
         });
+    },
+    listPlatforms:function(project_dir) {
+        return fs.readdirSync(path.join(project_dir, 'platforms')).filter(function(p) {
+            return core_platforms.indexOf(p) > -1;
+        });
     }
 };