@@ -641,22 +641,22 @@ function handleLocalization(files, pbxGroup, srcRootPath, opt) {
641
641
if ( parsedRegionFilePath . ext === ".storyboard" ) {
642
642
storyboardNames [ parsedRegionFilePath . name ] = true ;
643
643
}
644
- fileRegions = allNames [ parsedRegionFilePath . name ] = allNames [ parsedRegionFilePath . name ] || [ ] ;
644
+ var fileRegions = allNames [ parsedRegionFilePath . name ] = allNames [ parsedRegionFilePath . name ] || [ ] ;
645
645
fileRegions . push ( regionName ) ;
646
646
region [ regionFileName ] = $path . join ( filePath , regionFilePath ) ;
647
647
}
648
648
}
649
649
}
650
650
651
651
for ( var name in allNames ) {
652
- fileRegions = allNames [ name ]
652
+ var fileRegionsForName = allNames [ name ]
653
653
var variantGroupName = storyboardNames [ name ] ? name + ".storyboard" : name + ".strings" ;
654
654
655
655
var variantGroup = this . addLocalizationVariantGroup ( variantGroupName , { target : opt . target , skipAddToResourcesGroup : true } ) ;
656
656
pbxGroup . children . push ( pbxGroupChild ( variantGroup ) ) ;
657
- for ( let k = 0 ; k < fileRegions . length ; k ++ ) {
658
- var file = regions [ fileRegions [ k ] ] [ name ] ;
659
- var refFile = new pbxFile ( $path . relative ( srcRootPath , file ) , { basename : fileRegions [ k ] } ) ;
657
+ for ( let k = 0 ; k < fileRegionsForName . length ; k ++ ) {
658
+ var file = regions [ fileRegionsForName [ k ] ] [ name ] ;
659
+ var refFile = new pbxFile ( $path . relative ( srcRootPath , file ) , { basename : fileRegionsForName [ k ] } ) ;
660
660
refFile . fileRef = this . generateUuid ( ) ;
661
661
this . addToPbxFileReferenceSection ( refFile ) ;
662
662
this . addToPbxVariantGroup ( refFile , variantGroup . fileRef ) ;
@@ -669,27 +669,35 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
669
669
if ( ! groupKey ) {
670
670
return ;
671
671
}
672
+
673
+ this . removePbxGroupByKey ( groupKey , path ) ;
674
+ }
675
+
676
+ pbxProject . prototype . removePbxGroupByKey = function ( groupKey , path ) {
672
677
var group = this . getPBXGroupByKey ( groupKey ) || this . getPBXVariantGroupByKey ( groupKey )
678
+
679
+ if ( ! group ) {
680
+ return ;
681
+ }
673
682
674
683
path = path || "" ;
675
-
676
684
var children = group . children ;
677
685
678
686
for ( i in children ) {
679
687
var file = new pbxFile ( $path . join ( path , children [ i ] . comment ) ) ;
680
688
file . fileRef = children [ i ] . value ;
681
689
file . uuid = file . fileRef ;
682
- this . removePbxGroup ( children [ i ] . comment , $path . join ( path , children [ i ] . comment ) ) ;
683
- this . removeFromPbxFileReferenceSection ( file ) ;
690
+ this . removePbxGroupByKey ( children [ i ] . value , $path . join ( path , children [ i ] . comment ) ) ;
691
+ this . removeFromPbxFileReferenceSectionByUuid ( children [ i ] . value ) ;
684
692
this . removeFromPbxBuildFileSection ( file ) ;
685
693
this . removeFromPbxSourcesBuildPhase ( file ) ;
686
694
}
687
695
688
696
var mainGroup = this . findMainPbxGroup ( ) ;
689
697
if ( mainGroup ) {
690
- var mainGroupChildren = this . findMainPbxGroup ( ) . children , i ;
698
+ var mainGroupChildren = mainGroup . children , i ;
691
699
for ( i in mainGroupChildren ) {
692
- if ( mainGroupChildren [ i ] . comment == groupName ) {
700
+ if ( mainGroupChildren [ i ] . value == groupKey ) {
693
701
mainGroupChildren . splice ( i , 1 ) ;
694
702
}
695
703
}
@@ -702,15 +710,7 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
702
710
section = this . hash . project . objects [ 'PBXGroup' ] ;
703
711
}
704
712
705
- for ( key in section ) {
706
- // only look for comments
707
- if ( ! COMMENT_KEY . test ( key ) ) continue ;
708
-
709
- if ( section [ key ] == groupName ) {
710
- itemKey = key . split ( COMMENT_KEY ) [ 0 ] ;
711
- delete section [ itemKey ] ;
712
- }
713
- }
713
+ removeItemAndCommentFromSectionByUuid ( section , groupKey ) ;
714
714
}
715
715
716
716
pbxProject . prototype . addToPbxProjectSection = function ( target ) {
@@ -759,6 +759,12 @@ pbxProject.prototype.removeFromPbxFileReferenceSection = function(file) {
759
759
return file ;
760
760
}
761
761
762
+ pbxProject . prototype . removeFromPbxFileReferenceSectionByUuid = function ( fileUuid ) {
763
+ var section = this . pbxFileReferenceSection ( ) ;
764
+
765
+ removeItemAndCommentFromSectionByUuid ( section , fileUuid ) ;
766
+ }
767
+
762
768
pbxProject . prototype . addToXcVersionGroupSection = function ( file ) {
763
769
if ( ! file . models || ! file . currentModel ) {
764
770
throw new Error ( "Cannot create a XCVersionGroup section from not a data model document file" ) ;
@@ -1677,10 +1683,13 @@ pbxProject.prototype.removeTargetsByProductType = function(targetProductType) {
1677
1683
1678
1684
pbxProject . prototype . removeTarget = function ( target , targetKey ) {
1679
1685
let files = [ ] ;
1686
+ var pbxBuildFileSection = this . pbxBuildFileSection ( ) ;
1687
+ var fileReferenceSection = this . pbxFileReferenceSection ( ) ;
1680
1688
1681
1689
// iterate all buildPhases and collect all files that should be removed
1682
1690
// remove the phase from the appropriate section
1683
1691
var buildPhases = target [ "buildPhases" ] ;
1692
+
1684
1693
for ( let i = 0 ; i < buildPhases . length ; i ++ ) {
1685
1694
var buildPhase = buildPhases [ i ] ;
1686
1695
var sectionUuid = buildPhase . value ;
@@ -1693,7 +1702,27 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
1693
1702
files = files . concat ( section [ sectionUuid ] . files ) ;
1694
1703
} else if ( buildPhase . comment === buildPhaseNameForIsa ( "PBXFrameworksBuildPhase" ) ) {
1695
1704
section = this . hash . project . objects [ "PBXFrameworksBuildPhase" ] ;
1696
- files = files . concat ( section [ sectionUuid ] . files ) ;
1705
+ var frameworkFiles = section [ sectionUuid ] . files ;
1706
+ for ( let currentBuildFile of frameworkFiles ) {
1707
+ var currentBuildFileUuid = currentBuildFile . value ;
1708
+ var fileRef = pbxBuildFileSection [ currentBuildFileUuid ] . fileRef ;
1709
+ var stillReferenced = false ;
1710
+ for ( var buildFileUuid in nonComments ( pbxBuildFileSection ) ) {
1711
+ if ( pbxBuildFileSection [ buildFileUuid ] . fileRef === fileRef && buildFileUuid !== currentBuildFileUuid ) {
1712
+ stillReferenced = true ;
1713
+ break ;
1714
+ }
1715
+ }
1716
+
1717
+ if ( ! stillReferenced ) {
1718
+ var frameworkFileRef = fileReferenceSection [ fileRef ] ;
1719
+ var fileToRemove = new pbxFile ( unquote ( frameworkFileRef . path ) , { basename : frameworkFileRef . name } ) ;
1720
+ fileToRemove . fileRef = fileRef ;
1721
+ this . removeFromFrameworksPbxGroup ( fileToRemove ) ;
1722
+ removeItemAndCommentFromSectionByUuid ( fileReferenceSection , fileRef ) ;
1723
+ }
1724
+ }
1725
+ files = files . concat ( frameworkFiles ) ;
1697
1726
}
1698
1727
1699
1728
removeItemAndCommentFromSectionByUuid ( section , sectionUuid ) ;
@@ -1734,12 +1763,10 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
1734
1763
var productUuid = "" ;
1735
1764
1736
1765
var productReferenceUuid = target . productReference ;
1737
- var pbxBuildFileSection = this . pbxBuildFileSection ( ) ;
1738
- var pbxBuildFileSectionNoComments = nonComments ( pbxBuildFileSection ) ;
1739
1766
1740
1767
// the productReference is the uuid from the PBXFileReference Section, but we need the one in PBXBuildFile section
1741
1768
// check the fileRef of all records until we find the product
1742
- for ( var uuid in pbxBuildFileSectionNoComments ) {
1769
+ for ( var uuid in nonComments ( pbxBuildFileSection ) ) {
1743
1770
if ( this . pbxBuildFileSection ( ) [ uuid ] . fileRef == productReferenceUuid ) {
1744
1771
productUuid = uuid ;
1745
1772
}
@@ -1787,7 +1814,6 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
1787
1814
1788
1815
1789
1816
//remove the product from the Products PBXGroup
1790
- var fileReferenceSection = this . pbxFileReferenceSection ( ) ;
1791
1817
var productReference = fileReferenceSection [ productReferenceUuid ] ;
1792
1818
var productFile = new pbxFile ( productReference . path ) ;
1793
1819
productFile . fileRef = productReferenceUuid ;
0 commit comments