Skip to content
Permalink
Browse files
Add targetName to paramter to getBuildProperty (#109)
* Add targetName to parameter to getBuildProperty
* Update lib/pbxProject.js

Co-authored-by: Tim Brust <github@timbrust.de>
  • Loading branch information
NiklasMerz and timbru31 committed May 14, 2020
1 parent 6c019dd commit cd6f86f9ab0d53bf07e1ad405226bd1e2d8772ca
Showing 2 changed files with 52 additions and 1 deletion.
@@ -2068,11 +2068,34 @@ pbxProject.prototype.removeFile = function (path, group, opt) {



pbxProject.prototype.getBuildProperty = function(prop, build) {
pbxProject.prototype.getBuildProperty = function(prop, build, targetName) {
var target;
let validConfigs = [];

if (targetName) {
const target = this.pbxTargetByName(targetName);
const targetBuildConfigs = target && target.buildConfigurationList;

const xcConfigList = this.pbxXCConfigurationList();

// Collect the UUID's from the configuration of our target
for (const configName in xcConfigList) {
if (!COMMENT_KEY.test(configName) && targetBuildConfigs === configName) {
const buildVariants = xcConfigList[configName].buildConfigurations;

for (const item of buildVariants) {
validConfigs.push(item.value);
}

break;
}
}
}

var configs = this.pbxXCBuildConfigurationSection();
for (var configName in configs) {
if (!COMMENT_KEY.test(configName)) {
if (targetName && !validConfigs.includes(configName)) continue;
var config = configs[configName];
if ( (build && config.name === build) || (build === undefined) ) {
if (config.buildSettings[prop] !== undefined) {
@@ -214,6 +214,34 @@ exports['updateBuildProperty function'] = {
}
}

exports['getBuildProperty function'] = {
setUp:function(callback) {
callback();
},
tearDown:function(callback) {
fs.writeFileSync(bcpbx, original_pbx, 'utf-8');
callback();
},
'should change all targets in .pbxproj with multiple targets': function (test) {
var myProj = new pbx('test/parser/projects/multitarget.pbxproj');
myProj.parse(function(err, hash) {
myProj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', 'comcompanytest');
myProj.writeSync();
test.ok(myProj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER') === 'comcompanytest');
test.done();
});
},
'should change only one target in .pbxproj with multiple targets': function (test) {
var myProj = new pbx('test/parser/projects/multitarget.pbxproj');
myProj.parse(function(err, hash) {
myProj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', 'comcompanytest', null, 'MultiTargetTest');
myProj.writeSync();
test.ok(myProj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', undefined, 'MultiTargetTest') === 'comcompanytest');
test.done();
});
}
}

exports['addBuildProperty function'] = {
setUp:function(callback) {
callback();

0 comments on commit cd6f86f

Please sign in to comment.