Skip to content
Permalink
Browse files
[MAJOR] Add new optional paramter to pbxProject.addTarget (#79)
Allows plugins to set bundle ids for extensions.
  • Loading branch information
NiklasMerz committed Apr 9, 2020
1 parent 9fb83bb commit 022c69ef1615f934f7ac0e6560e47633b2a4c6cb
Showing 2 changed files with 31 additions and 3 deletions.
@@ -1385,13 +1385,14 @@ pbxProject.prototype.hasFile = function(filePath) {
return false;
}

pbxProject.prototype.addTarget = function(name, type, subfolder) {
pbxProject.prototype.addTarget = function(name, type, subfolder, bundleId) {

// Setup uuid and name of new target
var targetUuid = this.generateUuid(),
targetType = type,
targetSubfolder = subfolder || name,
targetName = name.trim();
targetName = name.trim(),
targetBundleId = bundleId;

// Check type against list of allowed target types
if (!targetName) {
@@ -1433,6 +1434,14 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) {
}
];

// Add optional bundleId to build configuration
if (targetBundleId) {
buildConfigurationsList = buildConfigurationsList.map((elem) => {
elem.buildSettings.PRODUCT_BUNDLE_IDENTIFIER = '"' + targetBundleId + '"';
return elem;
});
}

// Build Configuration: Add
var buildConfigurations = this.addXCConfigurationList(buildConfigurationsList, 'Release', 'Build configuration list for PBXNativeTarget "' + targetName +'"');

@@ -27,7 +27,8 @@ function cleanHash() {

var TARGET_NAME = 'TestExtension',
TARGET_TYPE = 'app_extension',
TARGET_SUBFOLDER_NAME = 'TestExtensionFiles';
TARGET_SUBFOLDER_NAME = 'TestExtensionFiles',
TARGET_BUNDLE_ID ="com.cordova.test.appextension";

exports.setUp = function (callback) {
proj.hash = cleanHash();
@@ -93,6 +94,24 @@ exports.addTarget = {

test.done();
},
'should create a new target with bundleid': function (test) {
var target = proj.addTarget(TARGET_NAME, TARGET_TYPE, TARGET_SUBFOLDER_NAME, TARGET_BUNDLE_ID);

test.ok(typeof target == 'object');
test.ok(target.uuid);
test.ok(target.pbxNativeTarget);
test.ok(target.pbxNativeTarget.isa);
test.ok(target.pbxNativeTarget.name);
test.ok(target.pbxNativeTarget.productName);
test.ok(target.pbxNativeTarget.productReference);
test.ok(target.pbxNativeTarget.productType);
test.ok(target.pbxNativeTarget.buildConfigurationList);
test.ok(target.pbxNativeTarget.buildPhases);
test.ok(target.pbxNativeTarget.buildRules);
test.ok(target.pbxNativeTarget.dependencies);

test.done();
},
'should add debug and release configurations to build configuration list': function (test) {
var pbxXCBuildConfigurationSection = proj.pbxXCBuildConfigurationSection(),
pbxXCConfigurationList = proj.pbxXCConfigurationList(),

0 comments on commit 022c69e

Please sign in to comment.