@@ -305,6 +305,12 @@ pbxProject.prototype.findMainPbxGroup = function () {
305
305
}
306
306
307
307
pbxProject . prototype . addPbxGroup = function ( filePathsArray , name , path , sourceTree , opt ) {
308
+
309
+ var oldGroup = this . pbxGroupByName ( name ) ;
310
+ if ( oldGroup ) {
311
+ this . removePbxGroup ( name , path ) ;
312
+ }
313
+
308
314
var groups = this . hash . project . objects [ 'PBXGroup' ] ,
309
315
pbxGroupUuid = opt . uuid || this . generateUuid ( ) ,
310
316
commentKey = f ( "%s_comment" , pbxGroupUuid ) ,
@@ -378,6 +384,39 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
378
384
return { uuid : pbxGroupUuid , pbxGroup : pbxGroup } ;
379
385
}
380
386
387
+ pbxProject . prototype . removePbxGroup = function ( name , path ) {
388
+ var group = this . pbxGroupByName ( name ) ;
389
+ if ( ! group ) {
390
+ return ;
391
+ }
392
+
393
+ var children = group . children ;
394
+
395
+ for ( i in children ) {
396
+ var file = new pbxFile ( $path . join ( path , children [ i ] . comment ) ) ;
397
+ file . fileRef = children [ i ] . value ;
398
+ file . uuid = file . fileRef ;
399
+ this . removePbxGroup ( children [ i ] . comment , $path . join ( path , children [ i ] . comment ) ) ;
400
+ this . removeFromPbxFileReferenceSection ( file ) ;
401
+ this . removeFromPbxBuildFileSection ( file ) ;
402
+ this . removeFromPbxSourcesBuildPhase ( file ) ;
403
+ }
404
+
405
+ //copied from https://github.com/alunny/node-xcode/blob/master/lib/pbxProject.js#L527
406
+ var section = this . hash . project . objects [ 'PBXGroup' ] ,
407
+ key , itemKey ;
408
+
409
+ for ( key in section ) {
410
+ // only look for comments
411
+ if ( ! COMMENT_KEY . test ( key ) ) continue ;
412
+
413
+ if ( section [ key ] == name ) {
414
+ itemKey = key . split ( COMMENT_KEY ) [ 0 ] ;
415
+ delete section [ itemKey ] ;
416
+ }
417
+ }
418
+ }
419
+
381
420
pbxProject . prototype . addToPbxFileReferenceSection = function ( file ) {
382
421
var commentKey = f ( "%s_comment" , file . fileRef ) ;
383
422
@@ -893,7 +932,7 @@ pbxProject.prototype.removeFromHeaderSearchPaths = function (file) {
893
932
INHERITED = '"$(inherited)"' ,
894
933
SEARCH_PATHS = 'HEADER_SEARCH_PATHS' ,
895
934
config , buildSettings , searchPaths ;
896
- var new_path = searchPathForFile ( file , this ) ;
935
+ var new_path = typeof file === 'string' ? file : searchPathForFile ( file , this ) ;
897
936
898
937
for ( config in configurations ) {
899
938
buildSettings = configurations [ config ] . buildSettings ;
0 commit comments