@@ -510,7 +510,7 @@ pbxProject.prototype.findMainPbxGroup = function () {
510
510
}
511
511
512
512
pbxProject . prototype . addPbxGroup = function ( filePathsArray , name , path , sourceTree , opt ) {
513
-
513
+ opt = opt || { } ;
514
514
var oldGroup = this . pbxGroupByName ( name ) ;
515
515
if ( oldGroup ) {
516
516
this . removePbxGroup ( name , path ) ;
@@ -523,6 +523,7 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
523
523
isa : 'PBXGroup' ,
524
524
children : [ ] ,
525
525
name : name ,
526
+ path : path ,
526
527
sourceTree : sourceTree ? sourceTree : '"<group>"'
527
528
} , //path is mandatory only for the main group
528
529
fileReferenceSection = this . pbxFileReferenceSection ( ) ,
@@ -551,23 +552,29 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
551
552
552
553
var srcRootPath = $path . dirname ( $path . dirname ( this . filepath ) ) ;
553
554
var file = new pbxFile ( $path . relative ( srcRootPath , filePath ) ) ;
554
- if ( fs . lstatSync ( filePath ) . isDirectory ( ) ) {
555
+ if ( fs . existsSync ( filePath ) && fs . lstatSync ( filePath ) . isDirectory ( ) ) {
555
556
file . uuid = this . generateUuid ( ) ;
556
557
file . fileRef = file . uuid ;
557
558
this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
558
559
this . addToPbxBuildFileSection ( file ) ;
559
560
pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
560
561
var files = fs . readdirSync ( filePath ) . map ( p => $path . join ( filePath , p ) ) ;
561
562
this . addPbxGroup ( files , $path . basename ( filePath ) , filePath , null , { uuid : file . uuid } ) ;
562
- } else if ( isSourceOrHeaderFileType ( file . lastType ) ) {
563
+ } else if ( isSourceOrHeaderFileType ( file . lastKnownFileType ) ) {
563
564
file . uuid = this . generateUuid ( ) ;
564
565
file . fileRef = this . generateUuid ( ) ;
565
566
this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
566
567
this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
567
- if ( ! isHeaderFileType ( file . lastType ) ) {
568
+ if ( ! isHeaderFileType ( file . lastKnownFileType ) ) {
568
569
this . addToPbxSourcesBuildPhase ( file ) ;
569
570
}
570
571
pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
572
+ } else {
573
+ file . uuid = this . generateUuid ( ) ;
574
+ file . fileRef = this . generateUuid ( ) ;
575
+ this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
576
+ this . addToPbxBuildFileSection ( file ) ;
577
+ pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
571
578
}
572
579
573
580
}
@@ -594,6 +601,8 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
594
601
if ( ! group ) {
595
602
return ;
596
603
}
604
+
605
+ path = path || $path . dirname ( this . filepath ) ;
597
606
598
607
var children = group . children ;
599
608
@@ -607,10 +616,13 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
607
616
this . removeFromPbxSourcesBuildPhase ( file ) ;
608
617
}
609
618
610
- var mainGroupChildren = this . findMainPbxGroup ( ) . children , i ;
611
- for ( i in mainGroupChildren ) {
612
- if ( mainGroupChildren [ i ] . comment == name ) {
613
- mainGroupChildren . splice ( i , 1 ) ;
619
+ var mainGroup = this . findMainPbxGroup ( ) ;
620
+ if ( mainGroup ) {
621
+ var mainGroupChildren = this . findMainPbxGroup ( ) . children , i ;
622
+ for ( i in mainGroupChildren ) {
623
+ if ( mainGroupChildren [ i ] . comment == name ) {
624
+ mainGroupChildren . splice ( i , 1 ) ;
625
+ }
614
626
}
615
627
}
616
628
@@ -1592,12 +1604,12 @@ function pbxFileReferenceObj(file) {
1592
1604
includeInIndex : file . includeInIndex
1593
1605
} ;
1594
1606
1595
- if ( fileObject . name . indexOf ( "\"" ) !== - 1 ) {
1607
+ if ( fileObject . name && fileObject . name . indexOf ( "\"" ) !== - 1 ) {
1596
1608
fileObject . name = fileObject . name . replace ( / \" / g, "\\\"" ) ;
1597
1609
fileObject . path = fileObject . path . replace ( / \" / g, "\\\"" ) ;
1598
1610
}
1599
1611
1600
- if ( ! file . basename . match ( NO_SPECIAL_SYMBOLS ) ) {
1612
+ if ( file . basename && ! file . basename . match ( NO_SPECIAL_SYMBOLS ) ) {
1601
1613
fileObject . name = "\"" + fileObject . name + "\"" ;
1602
1614
}
1603
1615
0 commit comments