Updated Branches:
  refs/heads/cordova-client 1c0d98f70 -> d6bae9027

tests should not test native project specifics, only that lower-level modules 
(project parsers) are invoked to do their tasks. emulate specs added!


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

Branch: refs/heads/cordova-client
Commit: d6bae90272fcc86900f793f5eec8d93aac3b8c35
Parents: 0987dbb
Author: Fil Maj <maj....@gmail.com>
Authored: Sun Sep 30 23:46:00 2012 -0700
Committer: Fil Maj <maj....@gmail.com>
Committed: Sun Sep 30 23:46:00 2012 -0700

----------------------------------------------------------------------
 spec/build.spec.js   |  189 +++++++++++++++------------------------------
 spec/emulate.spec.js |  172 +++++++++++++++++++++++++++++++++++++++++
 src/build.js         |  124 +++--------------------------
 src/emulate.js       |   63 ++++++++++++++--
 src/plugin.js        |    5 +-
 src/util.js          |    2 +-
 6 files changed, 308 insertions(+), 247 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d6bae902/spec/build.spec.js
----------------------------------------------------------------------
diff --git a/spec/build.spec.js b/spec/build.spec.js
index 5a8b90b..9aaabec 100644
--- a/spec/build.spec.js
+++ b/spec/build.spec.js
@@ -4,6 +4,9 @@ var cordova = require('../cordova'),
     path = require('path'),
     fs = require('fs'),
     config_parser = require('../src/config_parser'),
+    android_parser = require('../src/metadata/android_parser'),
+    ios_parser = require('../src/metadata/ios_parser'),
+    blackberry_parser = require('../src/metadata/blackberry_parser'),
     tempDir = path.join(__dirname, '..', 'temp');
 
 var cwd = process.cwd();
@@ -35,21 +38,15 @@ describe('build command', function() {
         var buildcb = jasmine.createSpy();
         var cb = jasmine.createSpy();
 
-        runs(function() {
-            cordova.create(tempDir);
-            process.chdir(tempDir);
-            cordova.platform('add', 'android', cb);
-        });
-        waitsFor(function() { return cb.wasCalled; }, 'platform add android 
callback');
+        cordova.create(tempDir);
+        process.chdir(tempDir);
+        cordova.platform('add', 'android', cb);
 
-        runs(function() {
-            var s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
-            expect(function() {
-                cordova.build(buildcb);
-            }).not.toThrow();
-            expect(s).toHaveBeenCalled();
-        });
-        waitsFor(function() { return buildcb.wasCalled; }, 'build call', 
20000);
+        var s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
+        expect(function() {
+            cordova.build(buildcb);
+        }).not.toThrow();
+        expect(s).toHaveBeenCalled();
     });
     
     it('should not run outside of a Cordova-based project', function() {
@@ -63,7 +60,7 @@ describe('build command', function() {
             cordova.build();
         }).toThrow();
     });
-    describe('binary creation', function() {
+    describe('per platform', function() {
         beforeEach(function() {
             cordova.create(tempDir);
             process.chdir(tempDir);
@@ -71,160 +68,100 @@ describe('build command', function() {
 
         afterEach(function() {
             process.chdir(cwd);
+            shell.rm('-rf', tempDir);
         });
-        it('should shell out to debug command on Android', function() {
-            var buildcb = jasmine.createSpy();
-            var cb = jasmine.createSpy();
-
-            runs(function() {
-                cordova.platform('add', 'android', cb);
+       
+        describe('Android', function() {
+            beforeEach(function() {
+                cordova.platform('add', 'android');
             });
-            waitsFor(function() { return cb.wasCalled; }, 'platform add 
android callback');
 
-            runs(function() {
+            it('should shell out to debug command on Android', function() {
                 var s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
-                cordova.build(buildcb);
+                cordova.build();
                 expect(s.mostRecentCall.args[0].match(/android\/cordova\/debug 
> \/dev\/null$/)).not.toBeNull();
             });
-        });
-        it('should shell out to debug command on iOS', function() {
-            var buildcb = jasmine.createSpy();
-            var cb = jasmine.createSpy();
-            var s;
-
-            runs(function() {
-                cordova.platform('add', 'ios', cb);
-            });
-            waitsFor(function() { return cb.wasCalled; }, 'platform add ios 
callback');
-            runs(function() {
-                s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
-                cordova.build(buildcb);
-            });
-            waitsFor(function() { return buildcb.wasCalled; }, 'build call', 
20000);
-            runs(function() {
+            it('should call android_parser\'s update_project', function() {
+                spyOn(require('shelljs'), 'exec').andReturn({code:0});
+                var s = spyOn(android_parser.prototype, 'update_project');
+                cordova.build();
                 expect(s).toHaveBeenCalled();
-                expect(s.mostRecentCall.args[0].match(/ios\/cordova\/debug > 
\/dev\/null$/)).not.toBeNull();
             });
         });
-        it('should shell out to ant command on blackberry-10', function() {
-            var buildcb = jasmine.createSpy();
-            var cb = jasmine.createSpy();
-            var s, t;
-
-            runs(function() {
-                cordova.platform('add', 'blackberry-10', cb);
-            });
-            waitsFor(function() { return cb.wasCalled; }, 'platform add 
blackberry callback');
-            runs(function() {
-                s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
-                t = spyOn(require('prompt'), 'get').andReturn(true);
-                cordova.build(buildcb);
-                // Fake prompt invoking its callback
-                t.mostRecentCall.args[1](null, {});
-            });
-            waitsFor(function() { return buildcb.wasCalled; }, 'build call', 
20000);
-            runs(function() {
-                expect(s).toHaveBeenCalled();
-                expect(s.mostRecentCall.args[0].match(/ant -f .*build\.xml qnx 
load-device/)).not.toBeNull();
-            });
-        });
-    });
-
-    describe('before each run it should interpolate config.xml app metadata', 
function() {
-        var cfg;
-        beforeEach(function() {
-            cordova.create(tempDir);
-            process.chdir(tempDir);
-        });
-
-        afterEach(function() {
-            process.chdir(cwd);
-        });
-
-        describe('into Android builds', function() {
-            it('should interpolate app name', function () {
-                var buildcb = jasmine.createSpy();
+        describe('iOS', function() {
+            it('should shell out to debug command on iOS', function() {
                 var cb = jasmine.createSpy();
-                var newName = "devil ether", s;
+                var buildcb = jasmine.createSpy();
+                var s;
 
                 runs(function() {
-                    cordova.platform('add', 'android', cb);
+                    cordova.platform('add', 'ios', cb);
                 });
-                waitsFor(function() { return cb.wasCalled; }, 'platform add 
android callback');
-
+                waitsFor(function() { return cb.wasCalled; }, 'platform add 
ios callback');
                 runs(function() {
-                    // intercept call to ./cordova/debug to speed things up
                     s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
-                    cfg = new config_parser(path.join(tempDir, 'www', 
'config.xml'));
-                    cfg.name(newName); // set a new name in the config.xml
                     cordova.build(buildcb);
                 });
-                waitsFor(function() { return buildcb.wasCalled; }, 'build 
call', 20000);
-
+                waitsFor(function() { return buildcb.wasCalled; }, 'ios 
build');
                 runs(function() {
-                    var strings = path.join(tempDir, 'platforms', 'android', 
'res', 'values', 'strings.xml');
-                    var doc = new 
et.ElementTree(et.XML(fs.readFileSync(strings, 'utf-8')));
-                    
expect(doc.find('string[@name="app_name"]').text).toBe('devil ether');
+                    expect(s).toHaveBeenCalled();
+                    expect(s.mostRecentCall.args[0].match(/ios\/cordova\/debug 
> \/dev\/null$/)).not.toBeNull();
                 });
             });
-            it('should interpolate package name');
-        });
-        describe('into iOS builds', function() {
-            it('should interpolate app name', function() {
-                var buildcb = jasmine.createSpy();
+            it('should call ios_parser\'s update_project', function() {
+                var s;
                 var cb = jasmine.createSpy();
-                var newName = "i keep getting older, they stay the same age", 
s;
-
                 runs(function() {
                     cordova.platform('add', 'ios', cb);
                 });
-                waitsFor(function() { return cb.wasCalled; }, 'platform add 
ios callback');
-
+                waitsFor(function() { return cb.wasCalled; }, 'ios add 
platform');
                 runs(function() {
-                    // intercept call to ./cordova/debug to speed things up
-                    s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
-                    cfg = new config_parser(path.join(tempDir, 'www', 
'config.xml'));
-                    cfg.name(newName); // set a new name in the config.xml
-                    cordova.build(buildcb);
-                });
-                waitsFor(function() { return buildcb.wasCalled; }, 'build 
call', 20000);
-
-                runs(function() {
-                    var pbxproj = path.join(tempDir, 'platforms', 'ios', 
'Hello_Cordova.xcodeproj', 'project.pbxproj');
-                    expect(fs.readFileSync(pbxproj, 
'utf-8').match(/PRODUCT_NAME\s*=\s*"i keep getting older, they stay the same 
age"/)).not.toBeNull();
+                    s = spyOn(ios_parser.prototype, 'update_project');
+                    cordova.build();
+                    expect(s).toHaveBeenCalled();
                 });
             });
-            it('should interpolate package name');
         });
-        describe('into BB10 builds', function() {
-            it('should interpolate app name', function() {
+        describe('BlackBerry', function() {
+            it('should shell out to ant command on blackberry-10', function() {
                 var buildcb = jasmine.createSpy();
                 var cb = jasmine.createSpy();
-                var newName = "fuck it dude. let's go bowling.", s, t;
+                var s;
 
                 runs(function() {
+                    var t = spyOn(require('prompt'), 'get').andReturn(true);
                     cordova.platform('add', 'blackberry-10', cb);
+                    // Fake prompt invoking its callback
+                    t.mostRecentCall.args[1](null, {});
                 });
                 waitsFor(function() { return cb.wasCalled; }, 'platform add 
blackberry callback');
-
                 runs(function() {
-                    // intercept call to ./cordova/debug to speed things up
                     s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
-                    cfg = new config_parser(path.join(tempDir, 'www', 
'config.xml'));
-                    cfg.name(newName); // set a new name in the config.xml
-                    t = spyOn(require('prompt'), 'get').andReturn(true);
                     cordova.build(buildcb);
-                    t.mostRecentCall.args[1](null, {});
                 });
                 waitsFor(function() { return buildcb.wasCalled; }, 'build 
call', 20000);
-
                 runs(function() {
-                    var bbcfg = path.join(tempDir, 'platforms', 
'blackberry-10', 'www', 'config.xml');
-                    var doc = new et.ElementTree(et.XML(fs.readFileSync(bbcfg, 
'utf-8')));
-                    expect(doc.find('name').text).toBe(newName);
+                    expect(s).toHaveBeenCalled();
+                    expect(s.mostRecentCall.args[0].match(/ant -f .*build\.xml 
qnx load-device/)).not.toBeNull();
+                });
+            });
+            it('should call blackberry_parser\'s update_project', function() {
+                var cb = jasmine.createSpy();
+                fs.writeFileSync(path.join(tempDir, '.cordova'), 
JSON.stringify({
+                    blackberry:{
+                        qnx:{}
+                    }
+                }), 'utf-8');
+                runs(function() {
+                    cordova.platform('add', 'blackberry-10', cb);
+                });
+                waitsFor(function() { return cb.wasCalled; }, 'bb add 
platform');
+                runs(function() {
+                    var s = spyOn(blackberry_parser.prototype, 
'update_project');
+                    cordova.build();
+                    expect(s).toHaveBeenCalled();
                 });
             });
-            it('should interpolate package name');
         });
     });
 });

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d6bae902/spec/emulate.spec.js
----------------------------------------------------------------------
diff --git a/spec/emulate.spec.js b/spec/emulate.spec.js
index e69de29..f953500 100644
--- a/spec/emulate.spec.js
+++ b/spec/emulate.spec.js
@@ -0,0 +1,172 @@
+var cordova = require('../cordova'),
+    et = require('elementtree'),
+    shell = require('shelljs'),
+    path = require('path'),
+    fs = require('fs'),
+    config_parser = require('../src/config_parser'),
+    android_parser = require('../src/metadata/android_parser'),
+    ios_parser = require('../src/metadata/ios_parser'),
+    blackberry_parser = require('../src/metadata/blackberry_parser'),
+    tempDir = path.join(__dirname, '..', 'temp');
+
+var cwd = process.cwd();
+
+describe('emulate command', function() {
+    beforeEach(function() {
+        // Make a temp directory
+        shell.rm('-rf', tempDir);
+        shell.mkdir('-p', tempDir);
+    });
+
+    it('should not run inside a Cordova-based project with no added 
platforms', function() {
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        cordova.create(tempDir);
+        process.chdir(tempDir);
+        expect(function() {
+            cordova.emulate();
+        }).toThrow();
+    });
+    
+    it('should run inside a Cordova-based project with at least one added 
platform', function() {
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        var cb = jasmine.createSpy();
+
+        runs(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+            cordova.platform('add', 'android', cb);
+        });
+        waitsFor(function() { return cb.wasCalled; }, 'platform add android 
callback');
+
+        runs(function() {
+            var s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
+            expect(function() {
+                cordova.emulate();
+            }).not.toThrow();
+            expect(s).toHaveBeenCalled();
+        });
+    });
+    
+    it('should not run outside of a Cordova-based project', function() {
+        this.after(function() {
+            process.chdir(cwd);
+        });
+
+        process.chdir(tempDir);
+
+        expect(function() {
+            cordova.emulate();
+        }).toThrow();
+    });
+    
+    describe('per platform', function() {
+        beforeEach(function() {
+            cordova.create(tempDir);
+            process.chdir(tempDir);
+        });
+
+        afterEach(function() {
+            process.chdir(cwd);
+        });
+        
+        describe('Android', function() {
+            beforeEach(function() {
+                cordova.platform('add', 'android');
+            });
+
+            it('should shell out to emulate command on Android', function() {
+                var s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
+                cordova.emulate();
+                
expect(s.mostRecentCall.args[0].match(/android\/cordova\/emulate/)).not.toBeNull();
+            });
+            it('should call android_parser\'s update_project', function() {
+                spyOn(require('shelljs'), 'exec').andReturn({code:0});
+                var s = spyOn(android_parser.prototype, 'update_project');
+                cordova.emulate();
+                expect(s).toHaveBeenCalled();
+            });
+        });
+        describe('iOS', function() {
+            it('should shell out to emulate command on iOS', 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 callback');
+                runs(function() {
+                    s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
+                    cordova.emulate(buildcb);
+                });
+                waitsFor(function() { return buildcb.wasCalled; }, 'emulate 
ios');
+                runs(function() {
+                    expect(s).toHaveBeenCalled();
+                    
expect(s.mostRecentCall.args[0].match(/ios\/cordova\/emulate/)).not.toBeNull();
+                });
+            });
+            it('should call ios_parser\'s update_project', 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 callback');
+                runs(function() {
+                    s = spyOn(ios_parser.prototype, 'update_project');
+                    cordova.emulate(buildcb);
+                    expect(s).toHaveBeenCalled();
+                });
+            });
+        });
+        describe('BlackBerry', function() {
+            it('should shell out to ant command on blackberry-10', function() {
+                var buildcb = jasmine.createSpy();
+                var cb = jasmine.createSpy();
+                var s, t = spyOn(require('prompt'), 'get').andReturn(true);
+
+                runs(function() {
+                    cordova.platform('add', 'blackberry-10', cb);
+                    // Fake prompt invoking its callback
+                    t.mostRecentCall.args[1](null, {});
+                });
+                waitsFor(function() { return cb.wasCalled; }, 'platform add 
blackberry callback');
+                runs(function() {
+                    s = spyOn(require('shelljs'), 'exec').andReturn({code:0});
+                    cordova.emulate(buildcb);
+                });
+                waitsFor(function() { return buildcb.wasCalled; }, 'build 
call', 20000);
+                runs(function() {
+                    expect(s).toHaveBeenCalled();
+                    expect(s.mostRecentCall.args[0].match(/ant -f .*build\.xml 
qnx load-simulator/)).not.toBeNull();
+                });
+            });
+            it('should call blackberry_parser\'s update_project', function() {
+                var cb = jasmine.createSpy();
+                var buildcb = jasmine.createSpy();
+                var s;
+
+                runs(function() {
+                    var p = spyOn(require('prompt'), 'get');
+                    cordova.platform('add', 'blackberry-10', cb);
+                    p.mostRecentCall.args[1](null, {});
+                });
+                waitsFor(function() { return cb.wasCalled; }, 'platform add bb 
callback');
+                runs(function() {
+                    s = spyOn(blackberry_parser.prototype, 'update_project');
+                    cordova.emulate(buildcb);
+                    expect(s).toHaveBeenCalled();
+                });
+            });
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d6bae902/src/build.js
----------------------------------------------------------------------
diff --git a/src/build.js b/src/build.js
index 8df0798..3339427 100644
--- a/src/build.js
+++ b/src/build.js
@@ -1,6 +1,7 @@
 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'),
@@ -15,7 +16,6 @@ function shell_out_to_debug(projectRoot, platform) {
     var cmd = path.join(projectRoot, 'platforms', platform, 'cordova', 'debug 
> /dev/null');
     // TODO: wait for https://issues.apache.org/jira/browse/CB-1548 to be 
fixed before we axe this
     // TODO: this is bb10 only for now
-    // TODO: this hsould be in emualte, we should use the load-device command
     if (platform.indexOf('blackberry') > -1) {
         cmd = 'ant -f ' + path.join(projectRoot, 'platforms', platform, 
'build.xml') + ' qnx load-device';
     }
@@ -23,31 +23,6 @@ function shell_out_to_debug(projectRoot, platform) {
     if (response.code > 0) throw 'An error occurred while building the ' + 
platform + ' project. ' + response.output;
 }
 
-function copy_www(projectRoot, platformRoot) {
-    // Clean out the existing www.
-    var target = path.join(platformRoot, 'www');
-    shell.rm('-rf', target);
-
-    // Copy app assets into native package
-    shell.cp('-r', path.join(projectRoot, 'www'), platformRoot);
-}
-
-function copy_js(jsPath, platformPath) {
-    fs.writeFileSync(path.join(platformPath, 'www', 'cordova.js'), 
fs.readFileSync(jsPath, 'utf-8'), 'utf-8');
-}
-
-function write_project_properties(cordovaConfig, projFile) {
-    // TODO: eventually support all blackberry sub-platforms
-    var props = fs.readFileSync(projFile, 'utf-8');
-    props = props.replace(/qnx\.bbwp\.dir=.*\n/, 'qnx.bbwp.dir=' + 
cordovaConfig.blackberry.qnx.bbwp + '\n');
-    props = props.replace(/qnx\.sigtool\.password=.*\n/, 
'qnx.sigtool.password=' + cordovaConfig.blackberry.qnx.signing_password + '\n');
-    props = props.replace(/qnx\.device\.ip=.*\n/, 'qnx.device.ip=' + 
cordovaConfig.blackberry.qnx.device_ip + '\n');
-    props = props.replace(/qnx\.device\.password=.*\n/, 'qnx.device.password=' 
+ cordovaConfig.blackberry.qnx.device_password + '\n');
-    props = props.replace(/qnx\.sim\.ip=.*\n/, 'qnx.sim.ip=' + 
cordovaConfig.blackberry.qnx.sim_ip + '\n');
-    props = props.replace(/qnx\.sim\.password=.*\n/, 'qnx.sim.password=' + 
cordovaConfig.blackberry.qnx.sim_password + '\n');
-    fs.writeFileSync(projFile, props, 'utf-8');
-}
-
 module.exports = function build (callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
@@ -58,7 +33,7 @@ module.exports = function build (callback) {
     var xml = path.join(projectRoot, 'www', 'config.xml');
     var assets = path.join(projectRoot, 'www');
     var cfg = new config_parser(xml);
-    var platforms = cfg.ls_platforms();
+    var platforms = platform('ls');
 
     if (platforms.length === 0) throw 'No platforms added to this project. 
Please use `cordova platform add <platform>`.';
 
@@ -69,109 +44,34 @@ module.exports = function build (callback) {
     // Iterate over each added platform 
     platforms.forEach(function(platform) {
         // Figure out paths based on platform
-        // TODO this is fugly, lots of repetition.
-        var assetsPath, js, parser, platformPath;
+        var parser, platformPath;
         switch (platform) {
             case 'android':
                 platformPath = path.join(projectRoot, 'platforms', 'android');
-                assetsPath = path.join(platformPath, 'assets');
                 parser = new android_parser(platformPath);
+
                 // Update the related platform project from the config
-                parser.update_from_config(cfg);
-                copy_www(projectRoot, assetsPath);
-                js = path.join(__dirname, '..', 'lib', 'android', 'framework', 
'assets', 'js', 'cordova.android.js');
-                copy_js(js, assetsPath);
+                parser.update_project(cfg);
                 shell_out_to_debug(projectRoot, 'android');
                 end();
                 break;
             case 'blackberry-10':
                 platformPath = path.join(projectRoot, 'platforms', 
'blackberry-10');
-                js = path.join(__dirname, '..', 'lib', 'android', 'framework', 
'assets', 'js', 'cordova.android.js');
                 parser = new blackberry_parser(platformPath);
                 
                 // Update the related platform project from the config
-                parser.update_from_config(cfg);
-
-                // Copy everything over except config.xml
-                var cfg_www = path.join(projectRoot, 'www', 'config.xml');
-                var temp_cfg = path.join(projectRoot, 'config.xml');
-                shell.mv(cfg_www, temp_cfg);
-                shell.cp('-rf', path.join(projectRoot, 'www', '*'), 
path.join(platformPath, 'www'));
-                shell.mv(temp_cfg, cfg_www);
-
-                // Move the js to just cordova.js
-                shell.mv('-f', path.join(platformPath, 'www', 'qnx', 
'cordova-*.js'), path.join(platformPath, 'www', 'cordova.js'));
-
-                // Add the webworks.js script file
-                var index = path.join(platformPath, 'www', 'index.html');
-                var contents = fs.readFileSync(index, 'utf-8');
-                contents = contents.replace(/<script type="text\/javascript" 
src="cordova\.js"><\/script>/, '<script type="text/javascript" 
src="js/webworks.js"></script><script type="text/javascript" 
src="cordova.js"></script>');
-                fs.writeFileSync(index, contents, 'utf-8');
-
-                // Do we have BB config?
-                var dotFile = path.join(projectRoot, '.cordova');
-                var dot = JSON.parse(fs.readFileSync(dotFile, 'utf-8'));
-                if (dot.blackberry === undefined || dot.blackberry.qnx === 
undefined) {
-                    // Let's save relevant BB SDK + signing info to .cordova
-                    console.log('Looks like we need some of your BlackBerry 
development environment information. We\'ll just ask you a few questions and 
we\'ll be on our way to building.');
-                    prompt.start();
-                    prompt.get([{
-                        name:'bbwp',
-                        required:true,
-                        description:'Enter the full path to your BB10 bbwp 
executable'
-                    },{
-                        name:'signing_password',
-                        required:true,
-                        description:'Enter your BlackBerry signing password',
-                        hidden:true
-                    },{
-                        name:'device_ip',
-                        description:'Enter the IP to your BB10 device'
-                    },{
-                        name:'device_password',
-                        description:'Enter the password for your BB10 device'
-                    },{
-                        name:'sim_ip',
-                        description:'Enter the IP to your BB10 simulator'
-                    },{
-                        name:'sim_password',
-                        description:'Enter the password for your BB10 
simulator'
-                    }
-                    ], function(err, results) {
-                        if (err) throw 'Error during BlackBerry configuration 
retrieval';
-                        // Write out .cordova file
-                        if (dot.blackberry === undefined) dot.blackberry = {};
-                        if (dot.blackberry.qnx === undefined) 
dot.blackberry.qnx = {};
-                        dot.blackberry.qnx.bbwp = results.bbwp;
-                        dot.blackberry.qnx.signing_password = 
results.signing_password;
-                        dot.blackberry.qnx.device_ip = results.device_ip;
-                        dot.blackberry.qnx.device_password = 
results.device_password;
-                        dot.blackberry.qnx.sim_ip = results.sim_ip;
-                        dot.blackberry.qnx.sim_password = results.sim_password;
-                        fs.writeFileSync(dotFile, JSON.stringify(dot), 
'utf-8');
-                        console.log('Perfect! If you need to change any of 
these properties, just edit the .cordova file in the root of your cordova 
project (it\'s just JSON, you\'ll be OK).');
-                        // Update project.properties
-                        write_project_properties(dot, path.join(platformPath, 
'project.properties'));
-                        // shell it
-                        shell_out_to_debug(projectRoot, 'blackberry-10');
-                        end();
-                    });
-                    return;
-                }
-                // Write out config stuff to project.properties file
-                write_project_properties(dot, path.join(platformPath, 
'project.properties'));
-                // Shell it
-                shell_out_to_debug(projectRoot, 'blackberry-10');
-                end();
+                parser.update_project(cfg, function() {
+                    // Shell it
+                    shell_out_to_debug(projectRoot, 'blackberry-10');
+                    end();
+                });
                 break;
             case 'ios':
                 platformPath = path.join(projectRoot, 'platforms', 'ios');
-                js = path.join(__dirname, '..', 'lib', 'ios', 'CordovaLib', 
'javascript', 'cordova.ios.js');
                 parser = new ios_parser(platformPath);
+
                 // Update the related platform project from the config
-                parser.update_from_config(cfg, function() {
-                    copy_www(projectRoot, platformPath);
-                    copy_js(js, platformPath);
+                parser.update_project(cfg, function() {
                     shell_out_to_debug(projectRoot, 'ios');
                     end();
                 });

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d6bae902/src/emulate.js
----------------------------------------------------------------------
diff --git a/src/emulate.js b/src/emulate.js
index b227c1e..be5d663 100644
--- a/src/emulate.js
+++ b/src/emulate.js
@@ -2,10 +2,25 @@ 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'),
+    n = require('nCallbacks'),
     util = require('util');
 
-module.exports = function emulate () {
+function shell_out_to_emulate(root, platform) {
+    var cmd = path.join(root, 'platforms', platform, 'cordova', 'emulate');
+    // TODO: bad bad bad
+    if (platform.indexOf('blackberry') > -1) {
+        cmd = 'ant -f ' + path.join(root, 'platforms', platform, 'build.xml') 
+ ' qnx load-simulator';
+    }
+    var em = shell.exec(cmd, {silent:true});
+    if (em.code > 0) throw 'An error occurred while emulating/deploying the ' 
+ platform + ' project.' + em.output;
+}
+
+module.exports = function emulate (callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
     if (!projectRoot) {
@@ -14,13 +29,49 @@ module.exports = function emulate () {
 
     var xml = path.join(projectRoot, 'www', 'config.xml');
     var cfg = new config_parser(xml);
-    var platforms = cfg.ls_platforms();
+    var platforms = platform('ls');
+
+    if (platforms.length === 0) throw 'No platforms added to this project. 
Please use `cordova platform add <platform>`.';
+
+    var end = n(platforms.length, function() {
+        if (callback) callback();
+    });
 
     // Iterate over each added platform and shell out to debug command
-    platforms.map(function(platform) {
-        var cmd = path.join(projectRoot, 'platforms', platform, 'cordova', 
'emulate');
-        var em = shell.exec(cmd, {silent:true});
-        if (em.code > 0) throw 'An error occurred while emulating/deploying 
the ' + platform + ' project.' + em.output;
+    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-10':
+                platformPath = path.join(projectRoot, 'platforms', 
'blackberry-10');
+                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-10');
+                    end();
+                });
+                break;
+            case 'ios':
+                platformPath = path.join(projectRoot, 'platforms', 'ios');
+                js = path.join(__dirname, '..', 'lib', 'ios', 'CordovaLib', 
'javascript', 'cordova.ios.js');
+                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;
+        }
     });
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d6bae902/src/plugin.js
----------------------------------------------------------------------
diff --git a/src/plugin.js b/src/plugin.js
index 2352c68..d5a86b1 100644
--- a/src/plugin.js
+++ b/src/plugin.js
@@ -5,6 +5,7 @@ var cordova_util  = require('./util'),
     path          = require('path'),
     shell         = require('shelljs'),
     config_parser = require('./config_parser'),
+    platform      = require('./platform'),
     plugin_parser = require('./plugin_parser'),
     ls            = fs.readdirSync;
 
@@ -21,7 +22,7 @@ module.exports = function plugin(command, target, callback) {
     // Grab config info for the project
     var xml = path.join(projectWww, 'config.xml');
     var cfg = new config_parser(xml);
-    var platforms = cfg.ls_platforms();
+    var platforms = platform('ls');
 
     // Massage plugin name / path
     var pluginPath, plugins, targetName;
@@ -35,7 +36,7 @@ module.exports = function plugin(command, target, callback) {
     switch(command) {
         case 'ls':
             if (plugins.length) {
-                return plugins.join('\n');
+                return plugins;
             } else return 'No plugins added. Use `cordova plugin add 
<plugin>`.';
             break;
         case 'add':

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d6bae902/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index 008c17e..587a47e 100644
--- a/src/util.js
+++ b/src/util.js
@@ -53,7 +53,7 @@ module.exports = {
         // specify which project tag to check out. minimum tag is 2.1.0rc1
         var cordova_lib_tag = '2.1.0';
         if (target == 'android') {
-            // FIXME: android hack. 2.1.0 tag messed up the create script
+            // TODO: android hack. 2.1.0 tag messed up the create script
             cordova_lib_tag = '47daaaf';
         }
 

Reply via email to