Add addBuildProperty and removeBuildProperty
into pbxProject
diff --git a/lib/pbxProject.js b/lib/pbxProject.js
index 435bcd9..6de5dd4 100644
--- a/lib/pbxProject.js
+++ b/lib/pbxProject.js
@@ -823,6 +823,31 @@
return null;
}
+pbxProject.prototype.addBuildProperty = function(prop, value, build_name) {
+ var configurations = nonComments(this.pbxXCBuildConfigurationSection()),
+ key, configuration;
+
+ for (key in configurations){
+ configuration = configurations[key];
+ if (!build_name || configuration.name === build_name){
+ configuration.buildSettings[prop] = value;
+ }
+ }
+}
+
+pbxProject.prototype.removeBuildProperty = function(prop, build_name) {
+ var configurations = nonComments(this.pbxXCBuildConfigurationSection()),
+ key, configuration;
+
+ for (key in configurations){
+ configuration = configurations[key];
+ console.error(configuration);
+ if (configuration.buildSettings[prop] &&
+ !build_name || configuration.name === build_name){
+ delete configuration.buildSettings[prop];
+ }
+ }
+}
pbxProject.prototype.updateBuildProperty = function(prop, value) {
var config = this.pbxXCBuildConfigurationSection();
diff --git a/test/pbxProject.js b/test/pbxProject.js
index 77786b7..eacb61b 100644
--- a/test/pbxProject.js
+++ b/test/pbxProject.js
@@ -177,6 +177,90 @@
}
}
+exports['addBuildProperty function'] = {
+ setUp:function(callback) {
+ callback();
+ },
+ tearDown:function(callback) {
+ fs.writeFileSync(bcpbx, original_pbx, 'utf-8');
+ callback();
+ },
+ 'should add 4 build properties in the .pbxproj file': function (test) {
+ var myProj = new pbx('test/parser/projects/build-config.pbxproj');
+ myProj.parse(function(err, hash) {
+ myProj.addBuildProperty('ENABLE_BITCODE', 'NO');
+ var newContents = myProj.writeSync();
+ test.equal(newContents.match(/ENABLE_BITCODE\s*=\s*NO/g).length, 4);
+ test.done();
+ });
+ },
+ 'should add 2 build properties in the .pbxproj file for specific build': function (test) {
+ var myProj = new pbx('test/parser/projects/build-config.pbxproj');
+ myProj.parse(function(err, hash) {
+ myProj.addBuildProperty('ENABLE_BITCODE', 'NO', 'Release');
+ var newContents = myProj.writeSync();
+ test.equal(newContents.match(/ENABLE_BITCODE\s*=\s*NO/g).length, 2);
+ test.done();
+ });
+ },
+ 'should not add build properties in the .pbxproj file for nonexist build': function (test) {
+ var myProj = new pbx('test/parser/projects/build-config.pbxproj');
+ myProj.parse(function(err, hash) {
+ myProj.addBuildProperty('ENABLE_BITCODE', 'NO', 'nonexist');
+ var newContents = myProj.writeSync();
+ test.ok(!newContents.match(/ENABLE_BITCODE\s*=\s*NO/g));
+ test.done();
+ });
+ }
+}
+
+exports['removeBuildProperty function'] = {
+ setUp:function(callback) {
+ callback();
+ },
+ tearDown:function(callback) {
+ fs.writeFileSync(bcpbx, original_pbx, 'utf-8');
+ callback();
+ },
+ 'should remove all build properties in the .pbxproj file': function (test) {
+ var myProj = new pbx('test/parser/projects/build-config.pbxproj');
+ myProj.parse(function(err, hash) {
+ myProj.removeBuildProperty('IPHONEOS_DEPLOYMENT_TARGET');
+ var newContents = myProj.writeSync();
+ test.ok(!newContents.match(/IPHONEOS_DEPLOYMENT_TARGET/));
+ test.done();
+ });
+ },
+ 'should remove specific build properties in the .pbxproj file': function (test) {
+ var myProj = new pbx('test/parser/projects/build-config.pbxproj');
+ myProj.parse(function(err, hash) {
+ myProj.removeBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', 'Debug');
+ var newContents = myProj.writeSync();
+ test.equal(newContents.match(/IPHONEOS_DEPLOYMENT_TARGET/g).length, 2);
+ test.done();
+ });
+ },
+ 'should not remove any build properties in the .pbxproj file': function (test) {
+ var myProj = new pbx('test/parser/projects/build-config.pbxproj');
+ myProj.parse(function(err, hash) {
+ myProj.removeBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', 'notexist');
+ var newContents = myProj.writeSync();
+ test.equal(newContents.match(/IPHONEOS_DEPLOYMENT_TARGET/g).length, 4);
+ test.done();
+ });
+ },
+ 'should fine with remove inexist build properties in the .pbxproj file': function (test) {
+ var myProj = new pbx('test/parser/projects/build-config.pbxproj');
+ myProj.parse(function(err, hash) {
+ myProj.removeBuildProperty('ENABLE_BITCODE');
+ var newContents = myProj.writeSync();
+ test.ok(!newContents.match(/ENABLE_BITCODE/));
+ test.done();
+ });
+ }
+
+}
+
exports['productName field'] = {
'should return the product name': function (test) {
var newProj = new pbx('.');