@@ -435,8 +435,8 @@ pbxProject.prototype.pbxCopyfilesBuildPhaseObj = function(target) {
435435 return this . buildPhaseObject ( 'PBXCopyFilesBuildPhase' , 'Copy Files' , target ) ;
436436}
437437
438- pbxProject . prototype . addToPbxCopyfilesBuildPhase = function ( file ) {
439- var sources = this . buildPhaseObject ( 'PBXCopyFilesBuildPhase' , 'Copy Files' , file . target ) ;
438+ pbxProject . prototype . addToPbxCopyfilesBuildPhase = function ( file , comment , target ) {
439+ var sources = this . buildPhaseObject ( 'PBXCopyFilesBuildPhase' , comment || 'Copy Files' , target || file . target ) ;
440440 sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
441441}
442442
@@ -508,6 +508,17 @@ pbxProject.prototype.removeFromPbxBuildFileSection = function(file) {
508508 }
509509}
510510
511+ pbxProject . prototype . removeFromPbxBuildFileSectionByFileRef = function ( file ) {
512+ var fileUuid ;
513+ var pbxBuildFileSection = this . pbxBuildFileSection ( ) ;
514+
515+ for ( fileUuid in pbxBuildFileSection ) {
516+ if ( pbxBuildFileSection [ fileUuid ] . fileRef == file . uuid ) {
517+ this . removeFromPbxBuildFileSectionByUuid ( fileUuid ) ;
518+ }
519+ }
520+ }
521+
511522pbxProject . prototype . removeFromPbxBuildFileSectionByUuid = function ( itemUuid ) {
512523 var buildSection = this . pbxBuildFileSection ( ) ;
513524 removeItemAndCommentFromSectionByUuid ( buildSection , itemUuid ) ;
@@ -539,10 +550,11 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
539550 var groups = this . hash . project . objects [ 'PBXGroup' ] ,
540551 pbxGroupUuid = opt . uuid || this . generateUuid ( ) ,
541552 commentKey = f ( "%s_comment" , pbxGroupUuid ) ,
553+ groupName = name . indexOf ( " " ) >= 0 && name [ 0 ] !== `"` ? `"${ name } "` : name ,
542554 pbxGroup = {
543555 isa : 'PBXGroup' ,
544556 children : [ ] ,
545- name : name ,
557+ name : groupName ,
546558 sourceTree : sourceTree ? sourceTree : '"<group>"'
547559 } ,
548560 fileReferenceSection = this . pbxFileReferenceSection ( ) ,
@@ -700,7 +712,7 @@ pbxProject.prototype.removePbxGroupByKey = function(groupKey, path) {
700712 file . uuid = file . fileRef ;
701713 this . removePbxGroupByKey ( children [ i ] . value , $path . join ( path , children [ i ] . comment ) ) ;
702714 this . removeFromPbxFileReferenceSectionByUuid ( children [ i ] . value ) ;
703- this . removeFromPbxBuildFileSection ( file ) ;
715+ this . removeFromPbxBuildFileSectionByFileRef ( file ) ;
704716 this . removeFromPbxSourcesBuildPhase ( file ) ;
705717 }
706718
@@ -1616,7 +1628,7 @@ pbxProject.prototype.getFileKey = function(filePath) {
16161628 return false ;
16171629}
16181630
1619- pbxProject . prototype . addTarget = function ( name , type , subfolder ) {
1631+ pbxProject . prototype . addTarget = function ( name , type , subfolder , parentTarget ) {
16201632
16211633 // Setup uuid and name of new target
16221634 var targetUuid = this . generateUuid ( ) ,
@@ -1695,26 +1707,30 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) {
16951707 } ;
16961708
16971709 // Target: Add to PBXNativeTarget section
1698- this . addToPbxNativeTargetSection ( target )
1699-
1700- // Product: Embed (only for "extension"-type targets)
1701- if ( targetType === 'app_extension' ) {
1710+ this . addToPbxNativeTargetSection ( target ) ;
17021711
1703- // Create CopyFiles phase in first target
1704- this . addBuildPhase ( [ ] , 'PBXCopyFilesBuildPhase' , 'Copy Files' , this . getFirstTarget ( ) . uuid , targetType )
1712+ if ( targetType === 'app_extension' || targetType === 'watch_extension' || targetType === 'watch_app' ) {
1713+ const isWatchApp = targetType === 'watch_app' ;
1714+ const copyTargetUuid = parentTarget || this . getFirstTarget ( ) . uuid ;
1715+ const phaseComment = targetType === 'watch_app' ? 'Embed Watch Content' : 'Copy Files' ;
1716+ let destination ;
17051717
1706- // Add product to CopyFiles phase
1707- this . addToPbxCopyfilesBuildPhase ( productFile )
1718+ if ( isWatchApp ) {
1719+ destination = '"$(CONTENTS_FOLDER_PATH)/Watch"' ;
1720+ }
17081721
1709- // this.addBuildPhaseToTarget(newPhase.buildPhase, this.getFirstTarget().uuid)
1722+ // Create CopyFiles phase in parent target
1723+ this . addBuildPhase ( [ ] , 'PBXCopyFilesBuildPhase' , phaseComment , copyTargetUuid , targetType , destination ) ;
17101724
1725+ // Add product to CopyFiles phase
1726+ this . addToPbxCopyfilesBuildPhase ( productFile , phaseComment , copyTargetUuid ) ;
17111727 }
17121728
17131729 // Target: Add uuid to root project
17141730 this . addToPbxProjectSection ( target ) ;
17151731
17161732 // Target: Add dependency for this target to first (main) target
1717- this . addTargetDependency ( this . getFirstTarget ( ) . uuid , [ target . uuid ] ) ;
1733+ this . addTargetDependency ( parentTarget || this . getFirstTarget ( ) . uuid , [ target . uuid ] ) ;
17181734
17191735
17201736 // Return target on success
@@ -2005,7 +2021,7 @@ function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName) {
20052021 frameworks : 'frameworks' ,
20062022 static_library : 'products_directory' ,
20072023 unit_test_bundle : 'wrapper' ,
2008- watch_app : 'wrapper ' ,
2024+ watch_app : 'products_directory ' ,
20092025 watch_extension : 'plugins'
20102026 }
20112027 var SUBFOLDERSPEC_BY_DESTINATION = {
@@ -2161,8 +2177,8 @@ function producttypeForTargettype (targetType) {
21612177 framework : 'com.apple.product-type.framework' ,
21622178 static_library : 'com.apple.product-type.library.static' ,
21632179 unit_test_bundle : 'com.apple.product-type.bundle.unit-test' ,
2164- watch_app : 'com.apple.product-type.application.watchapp ' ,
2165- watch_extension : 'com.apple.product-type.watchkit -extension'
2180+ watch_app : 'com.apple.product-type.application.watchapp2 ' ,
2181+ watch_extension : 'com.apple.product-type.watchkit2 -extension'
21662182 } ;
21672183
21682184 return PRODUCTTYPE_BY_TARGETTYPE [ targetType ]
@@ -2179,8 +2195,8 @@ function filetypeForProducttype (productType) {
21792195 'com.apple.product-type.framework' : '"wrapper.framework"' ,
21802196 'com.apple.product-type.library.static' : '"archive.ar"' ,
21812197 'com.apple.product-type.bundle.unit-test' : '"wrapper.cfbundle"' ,
2182- 'com.apple.product-type.application.watchapp ' : '"wrapper.application"' ,
2183- 'com.apple.product-type.watchkit -extension' : '"wrapper.app-extension"'
2198+ 'com.apple.product-type.application.watchapp2 ' : '"wrapper.application"' ,
2199+ 'com.apple.product-type.watchkit2 -extension' : '"wrapper.app-extension"'
21842200 } ;
21852201
21862202 return FILETYPE_BY_PRODUCTTYPE [ productType ]
@@ -2336,7 +2352,7 @@ pbxProject.prototype.findPBXGroupKeyAndType = function(criteria, groupType) {
23362352
23372353 var group = groups [ key ] ;
23382354 if ( criteria && criteria . path && criteria . name ) {
2339- if ( criteria . path === group . path && criteria . name === group . name ) {
2355+ if ( criteria . path === group . path && ( criteria . name === group . name || `" ${ criteria . name } "` === group . name ) ) {
23402356 target = key ;
23412357 break
23422358 }
@@ -2348,7 +2364,7 @@ pbxProject.prototype.findPBXGroupKeyAndType = function(criteria, groupType) {
23482364 }
23492365 }
23502366 else if ( criteria && criteria . name ) {
2351- if ( criteria . name === group . name ) {
2367+ if ( criteria . name === group . name || `" ${ criteria . name } "` === group . name ) {
23522368 target = key ;
23532369 break
23542370 }
0 commit comments