Skip to content

Commit 8ea09fb

Browse files
committed
feat: Add method for PbxGroup removal and remove group duplication
1 parent 733e10a commit 8ea09fb

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

lib/pbxProject.js

+40-1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ pbxProject.prototype.findMainPbxGroup = function () {
305305
}
306306

307307
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+
308314
var groups = this.hash.project.objects['PBXGroup'],
309315
pbxGroupUuid = opt.uuid || this.generateUuid(),
310316
commentKey = f("%s_comment", pbxGroupUuid),
@@ -378,6 +384,39 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
378384
return {uuid: pbxGroupUuid, pbxGroup: pbxGroup};
379385
}
380386

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+
381420
pbxProject.prototype.addToPbxFileReferenceSection = function (file) {
382421
var commentKey = f("%s_comment", file.fileRef);
383422

@@ -893,7 +932,7 @@ pbxProject.prototype.removeFromHeaderSearchPaths = function (file) {
893932
INHERITED = '"$(inherited)"',
894933
SEARCH_PATHS = 'HEADER_SEARCH_PATHS',
895934
config, buildSettings, searchPaths;
896-
var new_path = searchPathForFile(file, this);
935+
var new_path = typeof file === 'string' ? file : searchPathForFile(file, this);
897936

898937
for (config in configurations) {
899938
buildSettings = configurations[config].buildSettings;

0 commit comments

Comments
 (0)