@@ -510,7 +510,7 @@ pbxProject.prototype.findMainPbxGroup = function () {
510510}
511511
512512pbxProject . prototype . addPbxGroup = function ( filePathsArray , name , path , sourceTree , opt ) {
513-
513+ opt = opt || { } ;
514514 var oldGroup = this . pbxGroupByName ( name ) ;
515515 if ( oldGroup ) {
516516 this . removePbxGroup ( name , path ) ;
@@ -523,6 +523,7 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
523523 isa : 'PBXGroup' ,
524524 children : [ ] ,
525525 name : name ,
526+ path : path ,
526527 sourceTree : sourceTree ? sourceTree : '"<group>"'
527528 } , //path is mandatory only for the main group
528529 fileReferenceSection = this . pbxFileReferenceSection ( ) ,
@@ -551,23 +552,29 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
551552
552553 var srcRootPath = $path . dirname ( $path . dirname ( this . filepath ) ) ;
553554 var file = new pbxFile ( $path . relative ( srcRootPath , filePath ) ) ;
554- if ( fs . lstatSync ( filePath ) . isDirectory ( ) ) {
555+ if ( fs . existsSync ( filePath ) && fs . lstatSync ( filePath ) . isDirectory ( ) ) {
555556 file . uuid = this . generateUuid ( ) ;
556557 file . fileRef = file . uuid ;
557558 this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
558559 this . addToPbxBuildFileSection ( file ) ;
559560 pbxGroup . children . push ( pbxGroupChild ( file ) ) ;
560561 var files = fs . readdirSync ( filePath ) . map ( p => $path . join ( filePath , p ) ) ;
561562 this . addPbxGroup ( files , $path . basename ( filePath ) , filePath , null , { uuid : file . uuid } ) ;
562- } else if ( isSourceOrHeaderFileType ( file . lastType ) ) {
563+ } else if ( isSourceOrHeaderFileType ( file . lastKnownFileType ) ) {
563564 file . uuid = this . generateUuid ( ) ;
564565 file . fileRef = this . generateUuid ( ) ;
565566 this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
566567 this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
567- if ( ! isHeaderFileType ( file . lastType ) ) {
568+ if ( ! isHeaderFileType ( file . lastKnownFileType ) ) {
568569 this . addToPbxSourcesBuildPhase ( file ) ;
569570 }
570571 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 ) ) ;
571578 }
572579
573580 }
@@ -594,6 +601,8 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
594601 if ( ! group ) {
595602 return ;
596603 }
604+
605+ path = path || $path . dirname ( this . filepath ) ;
597606
598607 var children = group . children ;
599608
@@ -607,10 +616,13 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
607616 this . removeFromPbxSourcesBuildPhase ( file ) ;
608617 }
609618
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+ }
614626 }
615627 }
616628
@@ -1592,12 +1604,12 @@ function pbxFileReferenceObj(file) {
15921604 includeInIndex : file . includeInIndex
15931605 } ;
15941606
1595- if ( fileObject . name . indexOf ( "\"" ) !== - 1 ) {
1607+ if ( fileObject . name && fileObject . name . indexOf ( "\"" ) !== - 1 ) {
15961608 fileObject . name = fileObject . name . replace ( / \" / g, "\\\"" ) ;
15971609 fileObject . path = fileObject . path . replace ( / \" / g, "\\\"" ) ;
15981610 }
15991611
1600- if ( ! file . basename . match ( NO_SPECIAL_SYMBOLS ) ) {
1612+ if ( file . basename && ! file . basename . match ( NO_SPECIAL_SYMBOLS ) ) {
16011613 fileObject . name = "\"" + fileObject . name + "\"" ;
16021614 }
16031615
0 commit comments