Skip to content

Commit 6c8604c

Browse files
committed
adding remove functions for most file types
1 parent 3fb1aab commit 6c8604c

File tree

1 file changed

+106
-1
lines changed

1 file changed

+106
-1
lines changed

lib/pbxProject.js

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ pbxProject.prototype.addPluginFile = function (path, opt) {
8484
return file;
8585
}
8686

87+
pbxProject.prototype.removePluginFile = function (path, opt) {
88+
var file = new pbxFile(path, opt);
89+
//correctForPluginsPath(file, this);
90+
91+
this.removeFromPbxFileReferenceSection(file); // PBXFileReference
92+
this.removeFromPluginsPbxGroup(file); // PBXGroup
93+
94+
return file;
95+
}
96+
8797
pbxProject.prototype.addSourceFile = function (path, opt) {
8898
var file = this.addPluginFile(path, opt)
8999

@@ -95,21 +105,42 @@ pbxProject.prototype.addSourceFile = function (path, opt) {
95105
return file;
96106
}
97107

108+
pbxProject.prototype.removeSourceFile = function (path, opt) {
109+
var file = this.removePluginFile(path, opt)
110+
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
111+
this.removeFromPbxSourcesBuildPhase(file); // PBXSourcesBuildPhase
112+
113+
return file;
114+
}
115+
98116
pbxProject.prototype.addHeaderFile = function (path, opt) {
99117
return this.addPluginFile(path, opt)
100118
}
101119

120+
pbxProject.prototype.removeHeaderFile = function (path, opt) {
121+
return this.removePluginFile(path, opt)
122+
}
123+
102124
pbxProject.prototype.addResourceFile = function (path, opt) {
103125
var file = this.addPluginFile(path, opt)
104126

105127
file.uuid = this.generateUuid();
106128

107-
this.addToPbxBuildFileSection(file); // PBXBuildFile
129+
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
108130
this.addToPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
109131

110132
return file;
111133
}
112134

135+
pbxProject.prototype.removeResourceFile = function (path, opt) {
136+
var file = this.removePluginFile(path, opt)
137+
138+
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
139+
this.removeFromPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
140+
141+
return file;
142+
}
143+
113144
pbxProject.prototype.addFramework = function (path, opt) {
114145
var file = new pbxFile(path, opt);
115146

@@ -132,18 +163,61 @@ pbxProject.prototype.addToPbxBuildFileSection = function (file) {
132163
this.pbxBuildFileSection()[commentKey] = pbxBuildFileComment(file);
133164
}
134165

166+
pbxProject.prototype.removeFromPbxBuildFileSection = function (file) {
167+
var uuid;
168+
169+
for(uuid in this.pbxBuildFileSection()) {
170+
if(this.pbxBuildFileSection()[uuid].fileRef_comment == file.basename) {
171+
file.uuid = uuid;
172+
delete this.pbxBuildFileSection()[uuid];
173+
}
174+
}
175+
var commentKey = f("%s_comment", file.uuid);
176+
delete this.pbxBuildFileSection()[commentKey];
177+
}
178+
135179
pbxProject.prototype.addToPbxFileReferenceSection = function (file) {
136180
var commentKey = f("%s_comment", file.fileRef);
137181

138182
this.pbxFileReferenceSection()[file.fileRef] = pbxFileReferenceObj(file);
139183
this.pbxFileReferenceSection()[commentKey] = pbxFileReferenceComment(file);
140184
}
141185

186+
pbxProject.prototype.removeFromPbxFileReferenceSection = function (file) {
187+
188+
var i;
189+
var refObj = pbxFileReferenceObj(file);
190+
for(i in this.pbxFileReferenceSection()) {
191+
if(this.pbxFileReferenceSection()[i].name == refObj.name &&
192+
this.pbxFileReferenceSection()[i].path == refObj.path) {
193+
file.fileRef = i;
194+
break;
195+
}
196+
}
197+
var commentKey = f("%s_comment", file.fileRef);
198+
if(this.pbxFileReferenceSection()[commentKey] != undefined) {
199+
delete this.pbxFileReferenceSection()[commentKey];
200+
}
201+
202+
return file;
203+
}
204+
142205
pbxProject.prototype.addToPluginsPbxGroup = function (file) {
143206
var pluginsGroup = this.pbxGroupByName('Plugins');
144207
pluginsGroup.children.push(pbxGroupChild(file));
145208
}
146209

210+
pbxProject.prototype.removeFromPluginsPbxGroup = function (file) {
211+
var pluginsGroupChildren = this.pbxGroupByName('Plugins').children, i;
212+
for(i in pluginsGroupChildren) {
213+
if(pbxGroupChild(file).value == pluginsGroupChildren[i].value &&
214+
pbxGroupChild(file).comment == pluginsGroupChildren[i].comment) {
215+
delete pluginsGroupChildren[i];
216+
break;
217+
}
218+
}
219+
}
220+
147221
pbxProject.prototype.addToFrameworksPbxGroup = function (file) {
148222
var pluginsGroup = this.pbxGroupByName('Frameworks');
149223
pluginsGroup.children.push(pbxGroupChild(file));
@@ -154,16 +228,47 @@ pbxProject.prototype.addToPbxSourcesBuildPhase = function (file) {
154228
sources.files.push(pbxBuildPhaseObj(file));
155229
}
156230

231+
pbxProject.prototype.removeFromPbxSourcesBuildPhase = function (file) {
232+
var sources = this.pbxSourcesBuildPhaseObj(), i;
233+
for(i in sources.files) {
234+
if(sources.files[i].comment = longComment(file)) {
235+
delete sources.files[i];
236+
break;
237+
}
238+
}
239+
}
240+
157241
pbxProject.prototype.addToPbxResourcesBuildPhase = function (file) {
158242
var sources = this.pbxResourcesBuildPhaseObj();
159243
sources.files.push(pbxBuildPhaseObj(file));
160244
}
161245

246+
pbxProject.prototype.removeFromPbxResourcesBuildPhase = function (file) {
247+
var sources = this.pbxResourcesBuildPhaseObj(), i;
248+
249+
for(i in sources.files) {
250+
if(sources.files[i].comment = longComment(file)) {
251+
delete sources.files[i];
252+
break;
253+
}
254+
}
255+
}
256+
162257
pbxProject.prototype.addToPbxFrameworksBuildPhase = function (file) {
163258
var sources = this.pbxFrameworksBuildPhaseObj();
164259
sources.files.push(pbxBuildPhaseObj(file));
165260
}
166261

262+
pbxProject.prototype.removeFromPbxFrameworksBuildPhase = function (file) {
263+
var sources = this.pbxFrameworksBuildPhaseObj();
264+
for(i in sources.files) {
265+
if(sources.files[i].comment = longComment(file)) {
266+
delete sources.files[i];
267+
break;
268+
}
269+
}
270+
}
271+
167272
// helper access functions
168273
pbxProject.prototype.pbxBuildFileSection = function () {
169274
return this.hash.project.objects['PBXBuildFile'];

0 commit comments

Comments
 (0)