Merge branch 'master' of https://github.com/mcgrews3/node-xcode into mcgrews3-master
diff --git a/lib/pbxProject.js b/lib/pbxProject.js
index b9cf4fd..9a2f5ed 100644
--- a/lib/pbxProject.js
+++ b/lib/pbxProject.js
@@ -214,7 +214,14 @@
}
}
-pbxProject.prototype.addResourceFile = function(path, opt) {
+/**
+ *
+ * @param path {String}
+ * @param opt {Object} see pbxFile for avail options
+ * @param group {String} group key
+ * @returns {Object} file; see pbxFile
+ */
+pbxProject.prototype.addResourceFile = function(path, opt, group) {
opt = opt || {};
var file;
@@ -223,7 +230,7 @@
file = this.addPluginFile(path, opt);
if (!file) return false;
} else {
- file = new pbxFile(path, opt);
+ file = new pbxFile(path, opt);
if (this.hasFile(file.path)) return false;
}
@@ -234,19 +241,32 @@
correctForResourcesPath(file, this);
file.fileRef = this.generateUuid();
}
-
+
this.addToPbxBuildFileSection(file); // PBXBuildFile
this.addToPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
-
+
if (!opt.plugin) {
this.addToPbxFileReferenceSection(file); // PBXFileReference
- this.addToResourcesPbxGroup(file); // PBXGroup
+ if (group) {
+ this.addToPbxGroup(file, group); //Group other than Resources (i.e. 'splash')
+ }
+ else {
+ this.addToResourcesPbxGroup(file); // PBXGroup
+ }
+
}
-
+
return file;
}
-pbxProject.prototype.removeResourceFile = function(path, opt) {
+/**
+ *
+ * @param path {String}
+ * @param opt {Object} see pbxFile for avail options
+ * @param group {String} group key
+ * @returns {Object} file; see pbxFile
+ */
+pbxProject.prototype.removeResourceFile = function(path, opt, group) {
var file = new pbxFile(path, opt);
file.target = opt ? opt.target : undefined;
@@ -254,7 +274,12 @@
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
this.removeFromPbxFileReferenceSection(file); // PBXFileReference
- this.removeFromResourcesPbxGroup(file); // PBXGroup
+ if (group) {
+ this.removeFromPbxGroup(file, group); //Group other than Resources (i.e. 'splash')
+ }
+ else {
+ this.removeFromResourcesPbxGroup(file); // PBXGroup
+ }
this.removeFromPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
return file;
diff --git a/test/group.js b/test/group.js
index 8523b83..8eb5b00 100644
--- a/test/group.js
+++ b/test/group.js
@@ -185,7 +185,7 @@
}
exports.addHeaderFileToGroup = {
- 'should create group + add source file' : function(test) {
+ 'should create group + add header file' : function(test) {
var testKey = project.pbxCreateGroup('Test', 'Test');
var file = project.addHeaderFile('Notifications.h', {}, testKey);
@@ -197,7 +197,7 @@
}
exports.removeHeaderFileFromGroup = {
- 'should create group + add source file then remove source file' : function(test) {
+ 'should create group + add source file then remove header file' : function(test) {
var testKey = project.pbxCreateGroup('Test', 'Test');
var file = project.addHeaderFile('Notifications.h', {}, testKey);
@@ -213,6 +213,36 @@
}
}
+exports.addResourceFileToGroup = {
+ 'should add resource file (PNG) to the splash group' : function(test) {
+
+ var testKey = project.findPBXGroupKey({path:'splash'});
+ var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey);
+
+ var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
+ test.ok(foundInGroup);
+
+ test.done();
+ }
+}
+
+exports.removeResourceFileFromGroup = {
+ 'should add resource file (PNG) then remove resource file from splash group' : function(test) {
+ var testKey = project.findPBXGroupKey({path:'splash'});
+ var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey);
+
+ var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
+ test.ok(foundInGroup);
+
+ project.removeResourceFile('DefaultTest-667h.png', {}, testKey);
+
+ var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
+ test.ok(!foundInGroup);
+
+ test.done();
+ }
+}
+
exports.retrieveBuildPropertyForBuild = {
'should retrieve valid build property ':function(test) {
var releaseTargetedDeviceFamily = project.getBuildProperty('TARGETED_DEVICE_FAMILY', 'Release');
@@ -317,4 +347,4 @@
test.done();
}
-}
\ No newline at end of file
+}