Merge branch 'master' of https://github.com/kelvinhokk/node-xcode into kelvinhokk-master
diff --git a/lib/pbxProject.js b/lib/pbxProject.js
index 14abeac..b86fff4 100644
--- a/lib/pbxProject.js
+++ b/lib/pbxProject.js
@@ -230,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;
}
@@ -260,9 +260,9 @@
else {
this.addToResourcesPbxGroup(file); // PBXGroup
}
-
+
}
-
+
return file;
}
@@ -291,7 +291,7 @@
}
else {
this.removeFromResourcesPbxGroup(file); // PBXGroup
- }
+ }
this.removeFromPbxResourcesBuildPhase(file); // PBXResourcesBuildPhase
return file;
@@ -2002,5 +2002,25 @@
return file;
}
+pbxProject.prototype.addTargetAttribute = function(prop, value, target) {
+ var attributes = this.getFirstProject()['firstProject']['attributes'];
+ if (attributes['TargetAttributes'] === undefined) {
+ attributes['TargetAttributes'] = {};
+ }
+ target = target || this.getFirstTarget();
+ if (attributes['TargetAttributes'][target.uuid] === undefined) {
+ attributes['TargetAttributes'][target.uuid] = {};
+ }
+ attributes['TargetAttributes'][target.uuid][prop] = value;
+}
+
+pbxProject.prototype.removeTargetAttribute = function(prop, target) {
+ var attributes = this.getFirstProject()['firstProject']['attributes'];
+ target = target || this.getFirstTarget();
+ if (attributes['TargetAttributes'] &&
+ attributes['TargetAttributes'][target.uuid]) {
+ delete attributes['TargetAttributes'][target.uuid][prop];
+ }
+}
module.exports = pbxProject;
diff --git a/test/group.js b/test/group.js
index 8eb5b00..b907c7e 100644
--- a/test/group.js
+++ b/test/group.js
@@ -215,7 +215,7 @@
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);
@@ -311,7 +311,6 @@
}
exports.testWritingPBXProject = {
-
'should successfully write to PBXProject TargetAttributes': function(test) {
var pbxProjectObj = project.getPBXObject('PBXProject');
var pbxProject;
@@ -346,5 +345,35 @@
var output = project.writeSync();
test.done();
+ },
+ 'should add target attribute to PBXProject TargetAttributes': function(test) {
+ project.addTargetAttribute('ProvisioningStyle', 'Manual');
+ var output = project.writeSync();
+ test.equal(output.match(/ProvisioningStyle\s*=\s*Manual/g).length, 1);
+
+ test.done();
+ },
+ 'should change target attribute at PBXProject TargetAttributes': function(test) {
+ project.addTargetAttribute('ProvisioningStyle', 'Manual');
+ var output = project.writeSync();
+ test.equal(output.match(/ProvisioningStyle\s*=\s*Manual/g).length, 1);
+
+ project.addTargetAttribute('ProvisioningStyle', 'Automatic');
+ output = project.writeSync();
+ test.equal(output.match(/ProvisioningStyle\s*=\s*Manual/g), null);
+ test.equal(output.match(/ProvisioningStyle\s*=\s*Automatic/g).length, 1);
+
+ test.done();
+ },
+ 'should remove target attribute from PBXProject TargetAttributes': function(test) {
+ project.addTargetAttribute('ProvisioningStyle', 'Manual');
+ var output = project.writeSync();
+ test.equal(output.match(/ProvisioningStyle\s*=\s*Manual/g).length, 1);
+
+ project.removeTargetAttribute('ProvisioningStyle');
+ output = project.writeSync();
+ test.equal(output.match(/ProvisioningStyle\s*=\s*Manual/g), null);
+
+ test.done();
}
}