Skip to content

Commit 35a6fb3

Browse files
author
Anis Kadri
committed
Merge branch 'master' of https://github.com/mcgrews3/node-xcode into mcgrews3-master
2 parents 1f21ce1 + 38e1965 commit 35a6fb3

File tree

2 files changed

+66
-11
lines changed

2 files changed

+66
-11
lines changed

lib/pbxProject.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,14 @@ pbxProject.prototype.removeHeaderFile = function (path, opt, group) {
214214
}
215215
}
216216

217-
pbxProject.prototype.addResourceFile = function(path, opt) {
217+
/**
218+
*
219+
* @param path {String}
220+
* @param opt {Object} see pbxFile for avail options
221+
* @param group {String} group key
222+
* @returns {Object} file; see pbxFile
223+
*/
224+
pbxProject.prototype.addResourceFile = function(path, opt, group) {
218225
opt = opt || {};
219226

220227
var file;
@@ -223,7 +230,7 @@ pbxProject.prototype.addResourceFile = function(path, opt) {
223230
file = this.addPluginFile(path, opt);
224231
if (!file) return false;
225232
} else {
226-
file = new pbxFile(path, opt);
233+
file = new pbxFile(path, opt);
227234
if (this.hasFile(file.path)) return false;
228235
}
229236

@@ -234,27 +241,45 @@ pbxProject.prototype.addResourceFile = function(path, opt) {
234241
correctForResourcesPath(file, this);
235242
file.fileRef = this.generateUuid();
236243
}
237-
244+
238245
this.addToPbxBuildFileSection(file); // PBXBuildFile
239246
this.addToPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
240-
247+
241248
if (!opt.plugin) {
242249
this.addToPbxFileReferenceSection(file); // PBXFileReference
243-
this.addToResourcesPbxGroup(file); // PBXGroup
250+
if (group) {
251+
this.addToPbxGroup(file, group); //Group other than Resources (i.e. 'splash')
252+
}
253+
else {
254+
this.addToResourcesPbxGroup(file); // PBXGroup
255+
}
256+
244257
}
245-
258+
246259
return file;
247260
}
248261

249-
pbxProject.prototype.removeResourceFile = function(path, opt) {
262+
/**
263+
*
264+
* @param path {String}
265+
* @param opt {Object} see pbxFile for avail options
266+
* @param group {String} group key
267+
* @returns {Object} file; see pbxFile
268+
*/
269+
pbxProject.prototype.removeResourceFile = function(path, opt, group) {
250270
var file = new pbxFile(path, opt);
251271
file.target = opt ? opt.target : undefined;
252272

253273
correctForResourcesPath(file, this);
254274

255275
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
256276
this.removeFromPbxFileReferenceSection(file); // PBXFileReference
257-
this.removeFromResourcesPbxGroup(file); // PBXGroup
277+
if (group) {
278+
this.removeFromPbxGroup(file, group); //Group other than Resources (i.e. 'splash')
279+
}
280+
else {
281+
this.removeFromResourcesPbxGroup(file); // PBXGroup
282+
}
258283
this.removeFromPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
259284

260285
return file;

test/group.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ exports.removeSourceFileFromGroup = {
185185
}
186186

187187
exports.addHeaderFileToGroup = {
188-
'should create group + add source file' : function(test) {
188+
'should create group + add header file' : function(test) {
189189
var testKey = project.pbxCreateGroup('Test', 'Test');
190190
var file = project.addHeaderFile('Notifications.h', {}, testKey);
191191

@@ -197,7 +197,7 @@ exports.addHeaderFileToGroup = {
197197
}
198198

199199
exports.removeHeaderFileFromGroup = {
200-
'should create group + add source file then remove source file' : function(test) {
200+
'should create group + add source file then remove header file' : function(test) {
201201
var testKey = project.pbxCreateGroup('Test', 'Test');
202202
var file = project.addHeaderFile('Notifications.h', {}, testKey);
203203

@@ -213,6 +213,36 @@ exports.removeHeaderFileFromGroup = {
213213
}
214214
}
215215

216+
exports.addResourceFileToGroup = {
217+
'should add resource file (PNG) to the splash group' : function(test) {
218+
219+
var testKey = project.findPBXGroupKey({path:'splash'});
220+
var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey);
221+
222+
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
223+
test.ok(foundInGroup);
224+
225+
test.done();
226+
}
227+
}
228+
229+
exports.removeResourceFileFromGroup = {
230+
'should add resource file (PNG) then remove resource file from splash group' : function(test) {
231+
var testKey = project.findPBXGroupKey({path:'splash'});
232+
var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey);
233+
234+
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
235+
test.ok(foundInGroup);
236+
237+
project.removeResourceFile('DefaultTest-667h.png', {}, testKey);
238+
239+
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
240+
test.ok(!foundInGroup);
241+
242+
test.done();
243+
}
244+
}
245+
216246
exports.retrieveBuildPropertyForBuild = {
217247
'should retrieve valid build property ':function(test) {
218248
var releaseTargetedDeviceFamily = project.getBuildProperty('TARGETED_DEVICE_FAMILY', 'Release');
@@ -317,4 +347,4 @@ exports.testWritingPBXProject = {
317347

318348
test.done();
319349
}
320-
}
350+
}

0 commit comments

Comments
 (0)