@@ -435,8 +435,8 @@ pbxProject.prototype.pbxCopyfilesBuildPhaseObj = function(target) {
435
435
return this . buildPhaseObject ( 'PBXCopyFilesBuildPhase' , 'Copy Files' , target ) ;
436
436
}
437
437
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 ) ;
440
440
sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
441
441
}
442
442
@@ -508,6 +508,17 @@ pbxProject.prototype.removeFromPbxBuildFileSection = function(file) {
508
508
}
509
509
}
510
510
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
+
511
522
pbxProject . prototype . removeFromPbxBuildFileSectionByUuid = function ( itemUuid ) {
512
523
var buildSection = this . pbxBuildFileSection ( ) ;
513
524
removeItemAndCommentFromSectionByUuid ( buildSection , itemUuid ) ;
@@ -539,10 +550,11 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
539
550
var groups = this . hash . project . objects [ 'PBXGroup' ] ,
540
551
pbxGroupUuid = opt . uuid || this . generateUuid ( ) ,
541
552
commentKey = f ( "%s_comment" , pbxGroupUuid ) ,
553
+ groupName = name . indexOf ( " " ) >= 0 && name [ 0 ] !== `"` ? `"${ name } "` : name ,
542
554
pbxGroup = {
543
555
isa : 'PBXGroup' ,
544
556
children : [ ] ,
545
- name : name ,
557
+ name : groupName ,
546
558
sourceTree : sourceTree ? sourceTree : '"<group>"'
547
559
} ,
548
560
fileReferenceSection = this . pbxFileReferenceSection ( ) ,
@@ -700,7 +712,7 @@ pbxProject.prototype.removePbxGroupByKey = function(groupKey, path) {
700
712
file . uuid = file . fileRef ;
701
713
this . removePbxGroupByKey ( children [ i ] . value , $path . join ( path , children [ i ] . comment ) ) ;
702
714
this . removeFromPbxFileReferenceSectionByUuid ( children [ i ] . value ) ;
703
- this . removeFromPbxBuildFileSection ( file ) ;
715
+ this . removeFromPbxBuildFileSectionByFileRef ( file ) ;
704
716
this . removeFromPbxSourcesBuildPhase ( file ) ;
705
717
}
706
718
@@ -1616,7 +1628,7 @@ pbxProject.prototype.getFileKey = function(filePath) {
1616
1628
return false ;
1617
1629
}
1618
1630
1619
- pbxProject . prototype . addTarget = function ( name , type , subfolder ) {
1631
+ pbxProject . prototype . addTarget = function ( name , type , subfolder , parentTarget ) {
1620
1632
1621
1633
// Setup uuid and name of new target
1622
1634
var targetUuid = this . generateUuid ( ) ,
@@ -1695,26 +1707,30 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) {
1695
1707
} ;
1696
1708
1697
1709
// 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 ) ;
1702
1711
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 ;
1705
1717
1706
- // Add product to CopyFiles phase
1707
- this . addToPbxCopyfilesBuildPhase ( productFile )
1718
+ if ( isWatchApp ) {
1719
+ destination = '"$(CONTENTS_FOLDER_PATH)/Watch"' ;
1720
+ }
1708
1721
1709
- // this.addBuildPhaseToTarget(newPhase.buildPhase, this.getFirstTarget().uuid)
1722
+ // Create CopyFiles phase in parent target
1723
+ this . addBuildPhase ( [ ] , 'PBXCopyFilesBuildPhase' , phaseComment , copyTargetUuid , targetType , destination ) ;
1710
1724
1725
+ // Add product to CopyFiles phase
1726
+ this . addToPbxCopyfilesBuildPhase ( productFile , phaseComment , copyTargetUuid ) ;
1711
1727
}
1712
1728
1713
1729
// Target: Add uuid to root project
1714
1730
this . addToPbxProjectSection ( target ) ;
1715
1731
1716
1732
// 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 ] ) ;
1718
1734
1719
1735
1720
1736
// Return target on success
@@ -2005,7 +2021,7 @@ function pbxCopyFilesBuildPhaseObj(obj, folderType, subfolderPath, phaseName) {
2005
2021
frameworks : 'frameworks' ,
2006
2022
static_library : 'products_directory' ,
2007
2023
unit_test_bundle : 'wrapper' ,
2008
- watch_app : 'wrapper ' ,
2024
+ watch_app : 'products_directory ' ,
2009
2025
watch_extension : 'plugins'
2010
2026
}
2011
2027
var SUBFOLDERSPEC_BY_DESTINATION = {
@@ -2161,8 +2177,8 @@ function producttypeForTargettype (targetType) {
2161
2177
framework : 'com.apple.product-type.framework' ,
2162
2178
static_library : 'com.apple.product-type.library.static' ,
2163
2179
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'
2166
2182
} ;
2167
2183
2168
2184
return PRODUCTTYPE_BY_TARGETTYPE [ targetType ]
@@ -2179,8 +2195,8 @@ function filetypeForProducttype (productType) {
2179
2195
'com.apple.product-type.framework' : '"wrapper.framework"' ,
2180
2196
'com.apple.product-type.library.static' : '"archive.ar"' ,
2181
2197
'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"'
2184
2200
} ;
2185
2201
2186
2202
return FILETYPE_BY_PRODUCTTYPE [ productType ]
@@ -2336,7 +2352,7 @@ pbxProject.prototype.findPBXGroupKeyAndType = function(criteria, groupType) {
2336
2352
2337
2353
var group = groups [ key ] ;
2338
2354
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 ) ) {
2340
2356
target = key ;
2341
2357
break
2342
2358
}
@@ -2348,7 +2364,7 @@ pbxProject.prototype.findPBXGroupKeyAndType = function(criteria, groupType) {
2348
2364
}
2349
2365
}
2350
2366
else if ( criteria && criteria . name ) {
2351
- if ( criteria . name === group . name ) {
2367
+ if ( criteria . name === group . name || `" ${ criteria . name } "` === group . name ) {
2352
2368
target = key ;
2353
2369
break
2354
2370
}
0 commit comments