adding ios project parser module and related specs. hooked in config name extraction -> interpolation into native project for ios.
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/a8379e66 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/a8379e66 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/a8379e66 Branch: refs/heads/cordova-client Commit: a8379e667e680ff2441b967e120c0f77901910a9 Parents: 132a963 Author: Fil Maj <maj....@gmail.com> Authored: Fri Sep 21 13:43:21 2012 -0700 Committer: Fil Maj <maj....@gmail.com> Committed: Fri Sep 21 13:43:21 2012 -0700 ---------------------------------------------------------------------- spec/metadata/ios_parser.spec.js | 52 +++++++++++++++++++++++++++++++++ spec/platform.spec.js | 26 ++++++++++++++++- src/metadata/ios_parser.js | 12 ++++--- src/platform.js | 3 ++ 4 files changed, 87 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/a8379e66/spec/metadata/ios_parser.spec.js ---------------------------------------------------------------------- diff --git a/spec/metadata/ios_parser.spec.js b/spec/metadata/ios_parser.spec.js index e69de29..aeb95d0 100644 --- a/spec/metadata/ios_parser.spec.js +++ b/spec/metadata/ios_parser.spec.js @@ -0,0 +1,52 @@ +var ios_parser = require('../../src/metadata/ios_parser'), + config_parser = require('../../src/config_parser'), + path = require('path'), + fs = require('fs'), + cfg_path = path.join(__dirname, '..', 'fixtures', 'projects', 'test', 'www', 'config.xml'), + ios_path = path.join(__dirname, '..', 'fixtures', 'projects', 'native', 'ios'), + ios_pbx = path.join(ios_path, 'balls.xcodeproj', 'project.pbxproj'); + +var cwd = process.cwd(); + +var original_pbx = fs.readFileSync(ios_pbx, 'utf-8'); + +describe('ios project parser', function() { + it('should throw an exception with a path that is not a native ios project', function() { + expect(function() { + var project = new ios_parser(cwd); + }).toThrow(); + }); + it('should accept a proper native ios project path as construction parameter', function() { + var project; + expect(function() { + project = new ios_parser(ios_path); + }).not.toThrow(); + expect(project).toBeDefined(); + }); + + describe('update_from_config method', function() { + var project, config; + + beforeEach(function() { + project = new ios_parser(ios_path); + config = new config_parser(cfg_path); + }); + afterEach(function() { + fs.writeFileSync(ios_pbx, original_pbx, 'utf-8'); + }); + it('should throw an exception if a non config_parser object is passed into it', function() { + expect(function() { + project.update_from_config({}); + }).toThrow(); + }); + it('should update the application name properly', function() { + config.name('bond. james bond.'); + project.update_from_config(config); + + var pbx_contents = fs.readFileSync(ios_pbx, 'utf-8'); + + expect(pbx_contents.match(/PRODUCT_NAME\s*=\s*"bond. james bond."/)[0]).toBe('PRODUCT_NAME = "bond. james bond."'); + }); + it('should update the application package name properly'); + }); +}); http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/a8379e66/spec/platform.spec.js ---------------------------------------------------------------------- diff --git a/spec/platform.spec.js b/spec/platform.spec.js index 4e64731..a6980f5 100644 --- a/spec/platform.spec.js +++ b/spec/platform.spec.js @@ -105,7 +105,12 @@ describe('platform command', function() { }); }); it('should use the correct application name based on what is in config.xml', function() { - var cfg = new config_parser(path.join(tempDir, 'www', 'config.xml')); + var cfg_path = path.join(tempDir, 'www', 'config.xml'); + var orig_cfg_contents = fs.readFileSync(cfg_path, 'utf-8'); + this.after(function() { + fs.writeFileSync(cfg_path, orig_cfg_contents, 'utf-8'); + }); + var cfg = new config_parser(cfg_path); var cb = jasmine.createSpy(); runs(function() { @@ -132,6 +137,25 @@ describe('platform command', function() { expect(fs.existsSync(path.join(tempDir, 'platforms', 'ios', 'www'))).toBe(true); }); }); + it('should use the correct application name based on what is in config.xml', function() { + var cfg_path = path.join(tempDir, 'www', 'config.xml'); + var orig_cfg_contents = fs.readFileSync(cfg_path, 'utf-8'); + this.after(function() { + fs.writeFileSync(cfg_path, orig_cfg_contents, 'utf-8'); + }); + var cfg = new config_parser(cfg_path); + var cb = jasmine.createSpy(); + + runs(function() { + cfg.name('upon closer inspection they appear to be loafers'); + cordova.platform('add', 'ios', cb); + }); + waitsFor(function() { return cb.wasCalled; }, "platform add ios callback"); + runs(function() { + var pbxproj = fs.readFileSync(path.join(tempDir, 'platforms', 'ios', 'upon_closer_inspection_they_appear_to_be_loafers.xcodeproj', 'project.pbxproj'), 'utf-8'); + expect(pbxproj.match(/PRODUCT_NAME\s*=\s*"upon futher inspection they appear to be loafers"/)).toBe(true); + }); + }); }); }); describe('remove', function() { http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/a8379e66/src/metadata/ios_parser.js ---------------------------------------------------------------------- diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js index becf5fa..53a4dc6 100644 --- a/src/metadata/ios_parser.js +++ b/src/metadata/ios_parser.js @@ -1,19 +1,20 @@ var fs = require('fs'), path = require('path'), - xcode = require('node-xcode'), + xcode = require('xcode'), asyncblock = require('asyncblock'), config_parser = require('../config_parser'); module.exports = function ios_parser(project) { try { - this.xcodeproj = fs.readdirSync(project).filter(function(e) { return e.match(/\.xcodeproj$/i); })[0]; + var xcodeproj_dir = fs.readdirSync(project).filter(function(e) { return e.match(/\.xcodeproj$/i); })[0]; + if (!xcodeproj_dir) throw 'The provided path is not a Cordova iOS project.'; + this.xcodeproj = path.join(project, xcodeproj_dir); } catch(e) { throw 'The provided path is not a Cordova iOS project.'; } this.path = project; this.pbxproj = path.join(this.xcodeproj, 'project.pbxproj'); }; - module.exports.prototype = { update_from_config:function(config) { if (config instanceof config_parser) { @@ -21,7 +22,8 @@ module.exports.prototype = { var name = config.name(); - var proj = new xcode(this.pbxproj); + var proj = new xcode.project(this.pbxproj); + var parser = this; asyncblock(function(flow) { proj.parse(flow.set({ key:'parse', @@ -32,7 +34,7 @@ module.exports.prototype = { if (parse.err) throw 'An error occured during parsing of project.pbxproj. Start weeping.'; else { proj.updateProductName(name); - fs.writeFileSync(this.pbxproj, proj.writeSync(), 'utf-8'); + fs.writeFileSync(parser.pbxproj, proj.writeSync(), 'utf-8'); } }); } http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/a8379e66/src/platform.js ---------------------------------------------------------------------- diff --git a/src/platform.js b/src/platform.js index f9c06e3..e182f0b 100644 --- a/src/platform.js +++ b/src/platform.js @@ -7,6 +7,7 @@ var config_parser = require('./config_parser'), exec = require('child_process').exec, path = require('path'), android_parser= require('./metadata/android_parser'), + ios_parser = require('./metadata/ios_parser'), asyncblock = require('asyncblock'); var repos = { @@ -95,6 +96,8 @@ module.exports = function platform(command, target, callback) { android.update_from_config(cfg); break; case 'ios': + var ios = new ios_parser(output); + ios.update_from_config(cfg); break; } // Add the platform to config.xml