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/07/11 03:28:06 UTC

git commit: [CB-4148] Changing application name for ios needs to update all references to app name in native ios projects.

Updated Branches:
  refs/heads/master 6773ecd77 -> 062849f94


[CB-4148] Changing application name for ios needs to update all references to app name in native ios projects.


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

Branch: refs/heads/master
Commit: 062849f94bd5f52a28da543d6b845970c4345431
Parents: 6773ecd
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jul 10 18:27:55 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jul 10 18:27:55 2013 -0700

----------------------------------------------------------------------
 spec/metadata/ios_parser.spec.js | 13 +++++++---
 src/metadata/ios_parser.js       | 49 +++++++++++++++++++++++------------
 src/platform.js                  |  2 +-
 3 files changed, 44 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/062849f9/spec/metadata/ios_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/ios_parser.spec.js b/spec/metadata/ios_parser.spec.js
index cafe6e2..546568e 100644
--- a/spec/metadata/ios_parser.spec.js
+++ b/spec/metadata/ios_parser.spec.js
@@ -94,15 +94,16 @@ describe('ios project parser', function () {
             rm = spyOn(shell, 'rm');
             is_cordova = spyOn(util, 'isCordova').andReturn(proj);
             write = spyOn(fs, 'writeFileSync');
-            read = spyOn(fs, 'readFileSync');
+            read = spyOn(fs, 'readFileSync').andReturn('');
         });
 
         describe('update_from_config method', function() {
-            var et, xml, find, write_xml, root;
+            var et, xml, find, write_xml, root, mv;
             var cfg, find_obj, root_obj, cfg_access_add, cfg_access_rm, cfg_pref_add, cfg_pref_rm;
             var plist_parse, plist_build, xc;
             var update_name, xc_write;
             beforeEach(function() {
+                mv = spyOn(shell, 'mv');
                 find_obj = {
                     text:'hi'
                 };
@@ -155,9 +156,15 @@ describe('ios project parser', function () {
                 p = new platforms.ios.parser(ios_proj);
             });
 
-            it('should write out the app name to pbxproj by calling xcode.updateProductName', function(done) {
+            it('should update the app name in pbxproj by calling xcode.updateProductName, and move the ios native files to match the new name', function(done) {
+                var test_path = path.join(proj, 'platforms', 'ios', 'test');
+                var testname_path = path.join(proj, 'platforms', 'ios', 'testname');
                 p.update_from_config(cfg, function() {
                     expect(update_name).toHaveBeenCalledWith('testname');
+                    expect(mv).toHaveBeenCalledWith(path.join(test_path, 'test-Info.plist'), path.join(test_path, 'testname-Info.plist'));
+                    expect(mv).toHaveBeenCalledWith(path.join(test_path, 'test-Prefix.pch'), path.join(test_path, 'testname-Prefix.pch'));
+                    expect(mv).toHaveBeenCalledWith(test_path + '.xcodeproj', testname_path + '.xcodeproj');
+                    expect(mv).toHaveBeenCalledWith(test_path, testname_path);
                     done();
                 });
             });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/062849f9/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index fb79f5f..4766a64 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -50,7 +50,7 @@ module.exports = function ios_parser(project) {
         var xcodeproj_dir = fs.readdirSync(project).filter(function(e) { return e.match(/\.xcodeproj$/i); })[0];
         if (!xcodeproj_dir) throw new Error('The provided path "' + project + '" is not a Cordova iOS project.');
         this.xcodeproj = path.join(project, xcodeproj_dir);
-        this.originalName = this.xcodeproj.substring(this.xcodeproj.lastIndexOf(path.sep), this.xcodeproj.indexOf('.xcodeproj'));
+        this.originalName = this.xcodeproj.substring(this.xcodeproj.lastIndexOf(path.sep)+1, this.xcodeproj.indexOf('.xcodeproj'));
         this.cordovaproj = path.join(project, this.originalName);
     } catch(e) {
         throw new Error('The provided path is not a Cordova iOS project.');
@@ -139,21 +139,38 @@ module.exports.prototype = {
             });
         });
         
-        // Update product name
-        var proj = new xcode.project(this.pbxproj);
-        var parser = this;
-        proj.parse(function(err,hash) {
-            if (err) {
-                var err = new Error('An error occured during parsing of project.pbxproj. Start weeping. Output: ' + err);
-                if (callback) callback(err);
-                else throw err;
-            } else {
-                proj.updateProductName(name);
-                fs.writeFileSync(parser.pbxproj, proj.writeSync(), 'utf-8');
-                events.emit('log', 'Wrote out iOS Product Name to "' + name + '"');
-                if (callback) callback();
-            }
-        });
+        if (name != this.originalName) {
+            // Update product name inside pbxproj file
+            var proj = new xcode.project(this.pbxproj);
+            var parser = this;
+            proj.parse(function(err,hash) {
+                if (err) {
+                    var err = new Error('An error occured during parsing of project.pbxproj. Start weeping. Output: ' + err);
+                    if (callback) callback(err);
+                    else throw err;
+                } else {
+                    proj.updateProductName(name);
+                    fs.writeFileSync(parser.pbxproj, proj.writeSync(), 'utf-8');
+                    // Move the xcodeproj and other name-based dirs over.
+                    shell.mv(path.join(parser.cordovaproj, parser.originalName + '-Info.plist'), path.join(parser.cordovaproj, name + '-Info.plist'));
+                    shell.mv(path.join(parser.cordovaproj, parser.originalName + '-Prefix.pch'), path.join(parser.cordovaproj, name + '-Prefix.pch'));
+                    shell.mv(parser.xcodeproj, path.join(parser.path, name + '.xcodeproj'));
+                    shell.mv(parser.cordovaproj, path.join(parser.path, name));
+                    // Update self object with new paths
+                    var old_name = parser.originalName;
+                    parser = new module.exports(parser.path);
+                    // Hack this shi*t
+                    var pbx_contents = fs.readFileSync(parser.pbxproj, 'utf-8');
+                    pbx_contents = pbx_contents.split(old_name).join(name);
+                    fs.writeFileSync(parser.pbxproj, pbx_contents, 'utf-8');
+                    events.emit('log', 'Wrote out iOS Product Name and updated XCode project file names from "'+old_name+'" to "' + name + '".');
+                    if (callback) callback();
+                }
+            });
+        } else {
+            events.emit('log', 'iOS Product Name has not changed (still "' + this.originalName + '")');
+            if (callback) callback();
+        }
     },
 
     // Returns the platform-specific www directory.

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/062849f9/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 39b3df6..a49cc12 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -221,7 +221,7 @@ function call_into_create(target, projectRoot, cfg, id, version, callback, end)
                 if(target == 'wp8') bin = path.join(cordova_util.libDirectory, target, id, version, 'wp8', 'bin', 'create');
                 var args = (target=='ios') ? '--arc' : '';
                 var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
-                var name = cfg.name().replace(/\W/g,'_');
+                var name = cfg.name();
                 var command = util.format('"%s" %s "%s" "%s" "%s"', bin, args, output, pkg, name);
                 events.emit('log', 'Running bin/create for platform "' + target + '" with command: "' + command + '" (output to follow)');