@@ -517,6 +517,7 @@ pbxProject.prototype.findMainPbxGroup = function () {
517
517
518
518
pbxProject . prototype . addPbxGroup = function ( filePathsArray , name , path , sourceTree , opt ) {
519
519
opt = opt || { } ;
520
+ var srcRootPath = $path . dirname ( $path . dirname ( this . filepath ) ) ;
520
521
var oldGroup = this . pbxGroupByName ( name ) ;
521
522
if ( oldGroup ) {
522
523
this . removePbxGroup ( name , path ) ;
@@ -560,7 +561,6 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
560
561
continue ;
561
562
}
562
563
563
- var srcRootPath = $path . dirname ( $path . dirname ( this . filepath ) ) ;
564
564
var relativePath = $path . relative ( srcRootPath , filePath ) ;
565
565
var file = new pbxFile ( opt . filesRelativeToProject ? relativePath : filePath ) ;
566
566
file . uuid = this . generateUuid ( ) ;
@@ -569,22 +569,21 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
569
569
file . target = opt . target ;
570
570
}
571
571
if ( fs . existsSync ( filePath ) && fs . lstatSync ( filePath ) . isDirectory ( ) && ! isAssetFileType ( file . lastKnownFileType ) ) {
572
- file . fileRef = file . uuid ;
573
- var files = fs . readdirSync ( filePath ) . map ( p => $path . join ( filePath , p ) ) ;
574
572
if ( $path . extname ( filePath ) === ".lproj" ) {
575
- addLocalizationGroup . call ( this , pbxGroup , file , files , srcRootPath , opt ) ;
576
- } else {
577
- this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
578
- this . addToPbxBuildFileSection ( file ) ;
579
- pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
580
- this . addPbxGroup ( files , $path . basename ( filePath ) , filePath , null , { uuid : file . uuid , filesRelativeToProject : opt . filesRelativeToProject , target : opt . target } ) ;
573
+ continue ;
581
574
}
575
+ file . fileRef = file . uuid ;
576
+ var files = fs . readdirSync ( filePath ) . map ( p => $path . join ( filePath , p ) ) ;
577
+ this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
578
+ this . addToPbxBuildFileSection ( file ) ;
579
+ pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
580
+ this . addPbxGroup ( files , $path . basename ( filePath ) , filePath , null , { uuid : file . uuid , filesRelativeToProject : opt . filesRelativeToProject , target : opt . target } ) ;
582
581
} else {
583
582
this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
584
583
pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
585
584
if ( isHeaderFileType ( file . lastKnownFileType ) || isPlist ( file . lastKnownFileType ) ) {
586
585
continue ;
587
- }
586
+ }
588
587
589
588
if ( isEntitlement ( file . lastKnownFileType ) ) {
590
589
this . addToBuildSettings ( 'CODE_SIGN_ENTITLEMENTS' , file . path , opt . target ) ;
@@ -601,6 +600,8 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
601
600
}
602
601
}
603
602
603
+ handleLocalization . call ( this , filePathsArray , pbxGroup , srcRootPath , opt ) ;
604
+
604
605
if ( groups ) {
605
606
groups [ pbxGroupUuid ] = pbxGroup ;
606
607
groups [ commentKey ] = name ;
@@ -618,26 +619,55 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
618
619
return { uuid : pbxGroupUuid , pbxGroup : pbxGroup } ;
619
620
}
620
621
621
- function addLocalizationGroup ( pbxGroup , variantFile , files , srcRootPath , opt ) {
622
- for ( var i = 0 ; i < files . length ; i ++ ) {
623
- var variantGroupName = $path . parse ( $path . basename ( files [ i ] ) ) . name + ".storyboard" ;
624
- var variantGroup = this . findPBXVariantGroupKey ( { name : variantGroupName } ) ;
625
- if ( ! variantGroup ) {
626
- variantGroup = this . addLocalizationVariantGroup ( variantGroupName , { target : opt . target , skipAddToResourcesGroup : true } ) ;
627
- pbxGroup . children . push ( pbxGroupChild ( variantGroup ) ) ;
622
+ function handleLocalization ( files , pbxGroup , srcRootPath , opt ) {
623
+ var storyboardNames = { } ;
624
+ var allNames = { } ;
625
+ var regions = { } ;
626
+
627
+ for ( let i = 0 ; i < files . length ; i ++ ) {
628
+ const filePath = files [ i ] ;
629
+ const parsedPath = $path . parse ( filePath ) ;
630
+ if ( $path . extname ( filePath ) === ".lproj" ) {
631
+ var regionName = parsedPath . name ;
632
+ var region = regions [ regionName ] = { } ;
633
+ var regionFiles = fs . readdirSync ( filePath ) ;
634
+ this . addKnownRegion ( regionName ) ;
635
+ for ( let j = 0 ; j < regionFiles . length ; j ++ ) {
636
+ var regionFilePath = regionFiles [ j ] ;
637
+ var parsedRegionFilePath = $path . parse ( regionFilePath ) ;
638
+ var regionFileName = parsedRegionFilePath . name ;
639
+ if ( parsedRegionFilePath . ext === ".storyboard" ) {
640
+ storyboardNames [ parsedRegionFilePath . name ] = true ;
641
+ }
642
+ fileRegions = allNames [ parsedRegionFilePath . name ] = allNames [ parsedRegionFilePath . name ] || [ ] ;
643
+ fileRegions . push ( regionName ) ;
644
+ region [ regionFileName ] = $path . join ( filePath , regionFilePath ) ;
645
+ }
628
646
}
629
- var refFile = new pbxFile ( $path . relative ( srcRootPath , files [ i ] ) , { basename : $path . parse ( variantFile . basename ) . name } ) ;
630
- refFile . fileRef = this . generateUuid ( ) ;
631
- this . addToPbxFileReferenceSection ( refFile ) ;
632
- this . addToPbxVariantGroup ( refFile , variantGroup . fileRef ) ;
633
647
}
634
- }
648
+
649
+ for ( var name in allNames ) {
650
+ fileRegions = allNames [ name ]
651
+ var variantGroupName = storyboardNames [ name ] ? name + ".storyboard" : name + ".strings" ;
652
+
653
+ var variantGroup = this . addLocalizationVariantGroup ( variantGroupName , { target : opt . target , skipAddToResourcesGroup : true } ) ;
654
+ pbxGroup . children . push ( pbxGroupChild ( variantGroup ) ) ;
655
+ for ( let k = 0 ; k < fileRegions . length ; k ++ ) {
656
+ var file = regions [ fileRegions [ k ] ] [ name ] ;
657
+ var refFile = new pbxFile ( $path . relative ( srcRootPath , file ) , { basename : fileRegions [ k ] } ) ;
658
+ refFile . fileRef = this . generateUuid ( ) ;
659
+ this . addToPbxFileReferenceSection ( refFile ) ;
660
+ this . addToPbxVariantGroup ( refFile , variantGroup . fileRef ) ;
661
+ }
662
+ }
663
+ } ;
635
664
636
665
pbxProject . prototype . removePbxGroup = function ( groupName , path ) {
637
- var group = this . pbxGroupByName ( groupName ) ;
638
- if ( ! group ) {
666
+ var groupKey = this . findPBXGroupKey ( { name : groupName } ) || this . findPBXVariantGroupKey ( { name : groupName } ) ;
667
+ if ( ! groupKey ) {
639
668
return ;
640
669
}
670
+ var group = this . getPBXGroupByKey ( groupKey ) || this . getPBXVariantGroupByKey ( groupKey )
641
671
642
672
path = path || "" ;
643
673
@@ -663,8 +693,12 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
663
693
}
664
694
}
665
695
666
- var section = this . hash . project . objects [ 'PBXGroup' ] ,
667
- key , itemKey ;
696
+ var section , key , itemKey ;
697
+ if ( unquote ( group . isa ) === "PBXVariantGroup" ) {
698
+ section = this . hash . project . objects [ 'PBXVariantGroup' ] ;
699
+ } else {
700
+ section = this . hash . project . objects [ 'PBXGroup' ] ;
701
+ }
668
702
669
703
for ( key in section ) {
670
704
// only look for comments
0 commit comments