Resolve issue with pbxFile extension (#31)
authorChris Brody <chris.brody@gmail.com>
Tue, 11 Dec 2018 21:13:50 +0000 (16:13 -0500)
committerGitHub <noreply@github.com>
Tue, 11 Dec 2018 21:13:50 +0000 (16:13 -0500)
where pbxFile extension was being set to 'undefined'

and add new test case to verify the bug fix

with a quick test fix by @brodybits (Christopher J. Brody)
for the sake of consistency with the other test cases

NOTE: These changes were originally part of
apache/cordova-node-xcode#12 (cordova-node-xcode PR #12),
extracted here by @brodybits.

Co-authored-by: Kyle Spearrin <kspearrin@users.noreply.github.com>
Co-authored-by: Christopher J. Brody <brodybits@litehelpers.net>
lib/pbxFile.js
test/pbxFile.js

index 4d593f0..9553bfb 100644 (file)
@@ -83,7 +83,7 @@ var FILETYPE_BY_EXTENSION = {
 
 
 function unquoted(text){
-    return text.replace (/(^")|("$)/g, '')
+    return text == null ? '' : text.replace (/(^")|("$)/g, '')
 }
 
 function detectType(filePath) {
@@ -98,11 +98,12 @@ function detectType(filePath) {
 }
 
 function defaultExtension(fileRef) {
-    var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType;
+    var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != DEFAULT_FILETYPE ?
+        fileRef.lastKnownFileType : fileRef.explicitFileType;
 
     for(var extension in FILETYPE_BY_EXTENSION) {
         if(FILETYPE_BY_EXTENSION.hasOwnProperty(unquoted(extension)) ) {
-             if(FILETYPE_BY_EXTENSION[unquoted(extension)] === filetype )
+             if(FILETYPE_BY_EXTENSION[unquoted(extension)] === unquoted(filetype) )
                  return extension;
         }
     }
index 5a7b317..4f0d1a2 100644 (file)
@@ -278,5 +278,13 @@ exports['settings'] = {
 
         test.deepEqual({COMPILER_FLAGS:'"-std=c++11 -fno-objc-arc"'}, sourceFile.settings);
         test.done();
+    },
+
+    'should be .appex if {explicitFileType:\'"wrapper.app-extension"\'} specified': function (test) {
+        var sourceFile = new pbxFile('AppExtension',
+            { explicitFileType: '"wrapper.app-extension"'});
+
+        test.equal('AppExtension.appex', sourceFile.basename);
+        test.done();
     }
 }