From f3a137c2dbcda5a0bcc58b370ca2d8f4f52b693c Mon Sep 17 00:00:00 2001 From: Murat Sari Date: Fri, 22 Feb 2019 10:20:04 +0100 Subject: [PATCH 01/14] * Prepare script update build properties for the main target only. With the old behavior it were not possible to add apple watch targets and build it because cordova bricked the bundleids for these targets. * Add new build parameter multipleProvisioningProfiles. Here the usage within the build.json: "multipleProvisioningProfiles": [ { "key": "de.demo.html5", "value": "DemoME-Enterprise" }, { "key": "de.demo.html5.watchkitapp", "value": "DemoWE-Enterprise" }, { "key": "de.demo.html5.watchkitapp.watchkitextension", "value": "DemoWE Extension-Enterprise" } ], This one is needed too otherwise the signing step fails because cordova generates a wrong bundleid to prov.profile mapping. With these settings the exportOptions.plist is written correctly for multiple targets. This patch is needed to make the apple watch targets work with the cordova-ios workflow (apple watch targets added within a post process scripts using npm xcode) --- bin/templates/scripts/cordova/build | 1 + bin/templates/scripts/cordova/lib/build.js | 13 +++-- bin/templates/scripts/cordova/lib/prepare.js | 55 ++++++++++++++++++-- bin/templates/scripts/cordova/run | 1 + 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/bin/templates/scripts/cordova/build b/bin/templates/scripts/cordova/build index bd5a61947..f9ca2122e 100755 --- a/bin/templates/scripts/cordova/build +++ b/bin/templates/scripts/cordova/build @@ -42,6 +42,7 @@ var buildOpts = nopt({ 'codeSignIdentity': String, 'codeSignResourceRules': String, 'provisioningProfile': String, + 'multipleProvisioningProfiles': Array, 'automaticProvisioning': Boolean, 'developmentTeam': String, 'packageType': String, diff --git a/bin/templates/scripts/cordova/lib/build.js b/bin/templates/scripts/cordova/lib/build.js index 4270c4769..9db9e0a37 100644 --- a/bin/templates/scripts/cordova/lib/build.js +++ b/bin/templates/scripts/cordova/lib/build.js @@ -129,7 +129,7 @@ module.exports.run = function (buildOpts) { var buildType = buildOpts.release ? 'release' : 'debug'; var config = buildConfig.ios[buildType]; if (config) { - ['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile', 'developmentTeam', 'packageType', 'buildFlag', 'iCloudContainerEnvironment', 'automaticProvisioning'].forEach( + ['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile', 'multipleProvisioningProfiles', 'developmentTeam', 'packageType', 'buildFlag', 'iCloudContainerEnvironment', 'automaticProvisioning'].forEach( function (key) { buildOpts[key] = buildOpts[key] || config[key]; }); @@ -247,8 +247,15 @@ module.exports.run = function (buildOpts) { exportOptions.teamID = buildOpts.developmentTeam; } - if (buildOpts.provisioningProfile && bundleIdentifier) { - exportOptions.provisioningProfiles = { [ bundleIdentifier ]: String(buildOpts.provisioningProfile) }; + if ((buildOpts.provisioningProfile || buildOpts.multipleProvisioningProfiles) && bundleIdentifier) { + if (buildOpts.multipleProvisioningProfiles) { + exportOptions.provisioningProfiles = {}; + for (var i = 0; i < buildOpts.multipleProvisioningProfiles.length; i++) { + exportOptions.provisioningProfiles[buildOpts.multipleProvisioningProfiles[i]["key"]] = String(buildOpts.multipleProvisioningProfiles[i]["value"]); + } + } else { + exportOptions.provisioningProfiles = { [bundleIdentifier]: String(buildOpts.provisioningProfile) }; + } exportOptions.signingStyle = 'manual'; } diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 29f6cc2e7..f117a97b5 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -275,12 +275,59 @@ function handleOrientationSettings (platformConfig, infoPlist) { } } +// Make sure only update properties from our target project +function updateBuildPropertyLocal(proj, displayName, prop, value, build) { + try { + // Check if we have a valid target - during prepare we do not have it + var target = proj.pbxTargetByName(displayName); + + if (target == null || target.buildConfigurationList == null) { + proj.updateBuildProperty(prop, value, build); + } else { + var targetProjectBuildReference = target.buildConfigurationList; + + // Collect the uuid's from the configuration of our target + var COMMENT_KEY = /_comment$/; + var validConfigs = []; + var configList = proj.pbxXCConfigurationList(); + for (var configName in configList) { + if (!COMMENT_KEY.test(configName) && targetProjectBuildReference === configName) { + var buildVariants = configList[configName].buildConfigurations; + for (var i = 0; i < buildVariants.length; i++) { + validConfigs.push(buildVariants[i].value); + } + break; + } + } + + // Only update target props + var configs = proj.pbxXCBuildConfigurationSection(); + for (var configName in configs) { + if (!COMMENT_KEY.test(configName)) { + if (validConfigs.indexOf(configName) == -1) { + continue; + } + + var config = configs[configName]; + if ((build && config.name === build) || (!build)) { + config.buildSettings[prop] = value; + } + } + } + } + } catch (e) { // fallback to default behavior on error + proj.updateBuildProperty(prop, value, build); + } +} + + function handleBuildSettings (platformConfig, locations, infoPlist) { var pkg = platformConfig.getAttribute('ios-CFBundleIdentifier') || platformConfig.packageName(); var targetDevice = parseTargetDevicePreference(platformConfig.getPreference('target-device', 'ios')); var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); + var displayName = platformConfig.shortName && platformConfig.shortName(); var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */ @@ -300,22 +347,22 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (origPkg !== pkg) { events.emit('verbose', 'Set PRODUCT_BUNDLE_IDENTIFIER to ' + pkg + '.'); - proj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', pkg); + updateBuildPropertyLocal(proj, displayName, 'PRODUCT_BUNDLE_IDENTIFIER', pkg); } if (targetDevice) { events.emit('verbose', 'Set TARGETED_DEVICE_FAMILY to ' + targetDevice + '.'); - proj.updateBuildProperty('TARGETED_DEVICE_FAMILY', targetDevice); + updateBuildPropertyLocal(proj, displayName, 'TARGETED_DEVICE_FAMILY', targetDevice); } if (deploymentTarget) { events.emit('verbose', 'Set IPHONEOS_DEPLOYMENT_TARGET to "' + deploymentTarget + '".'); - proj.updateBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget); + updateBuildPropertyLocal(proj, displayName, 'IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget); } if (swiftVersion) { events.emit('verbose', 'Set SwiftVersion to "' + swiftVersion + '".'); - proj.updateBuildProperty('SWIFT_VERSION', swiftVersion); + updateBuildPropertyLocal(proj, displayName, 'SWIFT_VERSION', swiftVersion); } updateBuildSettingsForLaunchStoryboard(proj, platformConfig, infoPlist); diff --git a/bin/templates/scripts/cordova/run b/bin/templates/scripts/cordova/run index c4cfca30a..bf734b249 100755 --- a/bin/templates/scripts/cordova/run +++ b/bin/templates/scripts/cordova/run @@ -45,6 +45,7 @@ var opts = nopt({ 'codeSignIdentity': String, 'codeSignResourceRules': String, 'provisioningProfile': String, + 'multipleProvisioningProfiles': Array, 'automaticProvisioning': Boolean, 'buildConfig' : String, 'noSign' : Boolean From 160542d9dd387a99c886b7903a0bd78a95a9ac05 Mon Sep 17 00:00:00 2001 From: Murat Sari Date: Mon, 25 Feb 2019 22:30:35 +0100 Subject: [PATCH 02/14] * Do not use the short name to retrieve the pbx target --- bin/templates/scripts/cordova/lib/prepare.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index f117a97b5..6b2285cdd 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -327,8 +327,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - var displayName = platformConfig.shortName && platformConfig.shortName(); - + var displayName = platformConfig.name().replace(/\"/g, ""); var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */ try { From 0c24c4bb046f1f4930b6090770b81b9c4a45bcb6 Mon Sep 17 00:00:00 2001 From: Murat Sari Date: Mon, 25 Feb 2019 22:41:03 +0100 Subject: [PATCH 03/14] Adapt style --- bin/templates/scripts/cordova/lib/build.js | 2 +- bin/templates/scripts/cordova/lib/prepare.js | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/build.js b/bin/templates/scripts/cordova/lib/build.js index 9db9e0a37..3ad97d134 100644 --- a/bin/templates/scripts/cordova/lib/build.js +++ b/bin/templates/scripts/cordova/lib/build.js @@ -251,7 +251,7 @@ module.exports.run = function (buildOpts) { if (buildOpts.multipleProvisioningProfiles) { exportOptions.provisioningProfiles = {}; for (var i = 0; i < buildOpts.multipleProvisioningProfiles.length; i++) { - exportOptions.provisioningProfiles[buildOpts.multipleProvisioningProfiles[i]["key"]] = String(buildOpts.multipleProvisioningProfiles[i]["value"]); + exportOptions.provisioningProfiles[buildOpts.multipleProvisioningProfiles[i]['key']] = String(buildOpts.multipleProvisioningProfiles[i]['value']); } } else { exportOptions.provisioningProfiles = { [bundleIdentifier]: String(buildOpts.provisioningProfile) }; diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 6b2285cdd..44a7182aa 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -276,16 +276,14 @@ function handleOrientationSettings (platformConfig, infoPlist) { } // Make sure only update properties from our target project -function updateBuildPropertyLocal(proj, displayName, prop, value, build) { +function updateBuildPropertyLocal (proj, displayName, prop, value, build) { try { // Check if we have a valid target - during prepare we do not have it var target = proj.pbxTargetByName(displayName); - if (target == null || target.buildConfigurationList == null) { proj.updateBuildProperty(prop, value, build); } else { var targetProjectBuildReference = target.buildConfigurationList; - // Collect the uuid's from the configuration of our target var COMMENT_KEY = /_comment$/; var validConfigs = []; @@ -299,15 +297,13 @@ function updateBuildPropertyLocal(proj, displayName, prop, value, build) { break; } } - // Only update target props var configs = proj.pbxXCBuildConfigurationSection(); - for (var configName in configs) { + for (configName in configs) { if (!COMMENT_KEY.test(configName)) { - if (validConfigs.indexOf(configName) == -1) { + if (validConfigs.indexOf(configName) === -1) { continue; } - var config = configs[configName]; if ((build && config.name === build) || (!build)) { config.buildSettings[prop] = value; @@ -327,7 +323,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - var displayName = platformConfig.name().replace(/\"/g, ""); + var displayName = platformConfig.name().replace(/\"/g, ''); var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */ try { From 342396b1eced50805992cfcc9b7d6a7432ea0552 Mon Sep 17 00:00:00 2001 From: Murat Sari Date: Mon, 25 Feb 2019 22:48:43 +0100 Subject: [PATCH 04/14] More linter fixes --- bin/templates/scripts/cordova/lib/prepare.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 44a7182aa..233959fa5 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -316,14 +316,13 @@ function updateBuildPropertyLocal (proj, displayName, prop, value, build) { } } - function handleBuildSettings (platformConfig, locations, infoPlist) { var pkg = platformConfig.getAttribute('ios-CFBundleIdentifier') || platformConfig.packageName(); var targetDevice = parseTargetDevicePreference(platformConfig.getPreference('target-device', 'ios')); var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - var displayName = platformConfig.name().replace(/\"/g, ''); + var displayName = platformConfig.name().replace(/"/g, ''); var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */ try { From 55a06f97bbc72769afa0d32b97053357ce5dba1d Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Tue, 5 Nov 2019 09:44:24 +0100 Subject: [PATCH 05/14] Remove 'multipleProvisioningProfiles' again --- bin/templates/scripts/cordova/build | 1 - bin/templates/scripts/cordova/lib/build.js | 13 +++---------- bin/templates/scripts/cordova/lib/prepare.js | 1 + bin/templates/scripts/cordova/run | 1 - 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/bin/templates/scripts/cordova/build b/bin/templates/scripts/cordova/build index f9ca2122e..bd5a61947 100755 --- a/bin/templates/scripts/cordova/build +++ b/bin/templates/scripts/cordova/build @@ -42,7 +42,6 @@ var buildOpts = nopt({ 'codeSignIdentity': String, 'codeSignResourceRules': String, 'provisioningProfile': String, - 'multipleProvisioningProfiles': Array, 'automaticProvisioning': Boolean, 'developmentTeam': String, 'packageType': String, diff --git a/bin/templates/scripts/cordova/lib/build.js b/bin/templates/scripts/cordova/lib/build.js index e4271680c..f8d301dfd 100644 --- a/bin/templates/scripts/cordova/lib/build.js +++ b/bin/templates/scripts/cordova/lib/build.js @@ -129,7 +129,7 @@ module.exports.run = function (buildOpts) { var buildType = buildOpts.release ? 'release' : 'debug'; var config = buildConfig.ios[buildType]; if (config) { - ['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile', 'multipleProvisioningProfiles', 'developmentTeam', 'packageType', 'buildFlag', 'iCloudContainerEnvironment', 'automaticProvisioning'].forEach( + ['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile', 'developmentTeam', 'packageType', 'buildFlag', 'iCloudContainerEnvironment', 'automaticProvisioning'].forEach( function (key) { buildOpts[key] = buildOpts[key] || config[key]; }); @@ -249,15 +249,8 @@ module.exports.run = function (buildOpts) { exportOptions.teamID = buildOpts.developmentTeam; } - if ((buildOpts.provisioningProfile || buildOpts.multipleProvisioningProfiles) && bundleIdentifier) { - if (buildOpts.multipleProvisioningProfiles) { - exportOptions.provisioningProfiles = {}; - for (var i = 0; i < buildOpts.multipleProvisioningProfiles.length; i++) { - exportOptions.provisioningProfiles[buildOpts.multipleProvisioningProfiles[i]['key']] = String(buildOpts.multipleProvisioningProfiles[i]['value']); - } - } else { - exportOptions.provisioningProfiles = { [bundleIdentifier]: String(buildOpts.provisioningProfile) }; - } + if (buildOpts.provisioningProfile && bundleIdentifier) { + exportOptions.provisioningProfiles = { [ bundleIdentifier ]: String(buildOpts.provisioningProfile) }; exportOptions.signingStyle = 'manual'; } diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index b76edafc8..8164acead 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -324,6 +324,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var displayName = platformConfig.name().replace(/"/g, ''); var project; + try { project = projectFile.parse(locations); } catch (err) { diff --git a/bin/templates/scripts/cordova/run b/bin/templates/scripts/cordova/run index bf734b249..c4cfca30a 100755 --- a/bin/templates/scripts/cordova/run +++ b/bin/templates/scripts/cordova/run @@ -45,7 +45,6 @@ var opts = nopt({ 'codeSignIdentity': String, 'codeSignResourceRules': String, 'provisioningProfile': String, - 'multipleProvisioningProfiles': Array, 'automaticProvisioning': Boolean, 'buildConfig' : String, 'noSign' : Boolean From 41d47679d57e367b3646440b6a1fdfd688f4f768 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Wed, 6 Nov 2019 09:56:06 +0100 Subject: [PATCH 06/14] Revert `updateBuildPropertyLocal` for deployment target and swift version --- bin/templates/scripts/cordova/lib/prepare.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 8164acead..dd4799b11 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -351,12 +351,12 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (deploymentTarget) { events.emit('verbose', 'Set IPHONEOS_DEPLOYMENT_TARGET to "' + deploymentTarget + '".'); - updateBuildPropertyLocal(project.xcode, displayName, 'IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget); + project.xcode.updateBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget); } if (swiftVersion) { events.emit('verbose', 'Set SwiftVersion to "' + swiftVersion + '".'); - updateBuildPropertyLocal(project.xcode, displayName, 'SWIFT_VERSION', swiftVersion); + project.xcode.updateBuildProperty('SWIFT_VERSION', swiftVersion); } updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist); From 9e6610126e9183cdff9f084bf231c020dd706358 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Wed, 6 Nov 2019 09:59:58 +0100 Subject: [PATCH 07/14] Set device family the old way, too Extension should work on iPads --- bin/templates/scripts/cordova/lib/prepare.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index dd4799b11..7d050acfe 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -346,7 +346,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (targetDevice) { events.emit('verbose', 'Set TARGETED_DEVICE_FAMILY to ' + targetDevice + '.'); - updateBuildPropertyLocal(project.xcode, displayName, 'TARGETED_DEVICE_FAMILY', targetDevice); + project.xcode.updateBuildProperty('TARGETED_DEVICE_FAMILY', targetDevice); } if (deploymentTarget) { From 88ae1f9050cb1db7e3aebf89307071fb2483004e Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Mon, 16 Dec 2019 21:10:22 +0100 Subject: [PATCH 08/14] Rename "displayName" to "targetName" --- bin/templates/scripts/cordova/lib/prepare.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 168a8566a..81c9a3780 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -276,10 +276,10 @@ function handleOrientationSettings (platformConfig, infoPlist) { } // Make sure only update properties from our target project -function updateBuildPropertyLocal (proj, displayName, prop, value, build) { +function updateBuildPropertyLocal (proj, targetName, prop, value, build) { try { // Check if we have a valid target - during prepare we do not have it - var target = proj.pbxTargetByName(displayName); + var target = proj.pbxTargetByName(targetName); if (target == null || target.buildConfigurationList == null) { proj.updateBuildProperty(prop, value, build); } else { @@ -322,7 +322,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - var displayName = platformConfig.name().replace(/"/g, ''); + var targetName = unorm.nfd(platformConfig.name()); var wkWebViewOnly = platformConfig.getPreference('WKWebViewOnly'); var project; @@ -343,7 +343,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (origPkg !== pkg) { events.emit('verbose', 'Set PRODUCT_BUNDLE_IDENTIFIER to ' + pkg + '.'); - updateBuildPropertyLocal(project.xcode, displayName, 'PRODUCT_BUNDLE_IDENTIFIER', pkg); + updateBuildPropertyLocal(project.xcode, targetName, 'PRODUCT_BUNDLE_IDENTIFIER', pkg); } if (targetDevice) { From a7b5ca2343b4d17c62a3cdcaf229175fe1326da6 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Tue, 24 Dec 2019 11:01:00 +0100 Subject: [PATCH 09/14] Update bin/templates/scripts/cordova/lib/prepare.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: エリス --- bin/templates/scripts/cordova/lib/prepare.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 81c9a3780..ca3fa2a53 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -279,7 +279,7 @@ function handleOrientationSettings (platformConfig, infoPlist) { function updateBuildPropertyLocal (proj, targetName, prop, value, build) { try { // Check if we have a valid target - during prepare we do not have it - var target = proj.pbxTargetByName(targetName); + const target = proj.pbxTargetByName(targetName); if (target == null || target.buildConfigurationList == null) { proj.updateBuildProperty(prop, value, build); } else { From dab75b279e002b863906fefd0a2c3d446dce8691 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Tue, 24 Dec 2019 11:02:30 +0100 Subject: [PATCH 10/14] Update bin/templates/scripts/cordova/lib/prepare.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: エリス --- bin/templates/scripts/cordova/lib/prepare.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index ca3fa2a53..d14d16727 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -280,7 +280,7 @@ function updateBuildPropertyLocal (proj, targetName, prop, value, build) { try { // Check if we have a valid target - during prepare we do not have it const target = proj.pbxTargetByName(targetName); - if (target == null || target.buildConfigurationList == null) { + if (!target || !target.buildConfigurationList) { proj.updateBuildProperty(prop, value, build); } else { var targetProjectBuildReference = target.buildConfigurationList; From f721ea3f025bf3102856f72533c0eea13d076476 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Tue, 24 Dec 2019 11:05:23 +0100 Subject: [PATCH 11/14] Update bin/templates/scripts/cordova/lib/prepare.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: エリス --- bin/templates/scripts/cordova/lib/prepare.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index d14d16727..2408454aa 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -301,7 +301,7 @@ function updateBuildPropertyLocal (proj, targetName, prop, value, build) { var configs = proj.pbxXCBuildConfigurationSection(); for (configName in configs) { if (!COMMENT_KEY.test(configName)) { - if (validConfigs.indexOf(configName) === -1) { + if (!validConfigs.includes(configName)) { continue; } var config = configs[configName]; From c5f5056ec74f21de4bbae9215911eaa588d2b6d3 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Tue, 24 Dec 2019 11:18:57 +0100 Subject: [PATCH 12/14] Fix code style issues --- bin/templates/scripts/cordova/lib/prepare.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index f059aa850..fb051f0b3 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -275,13 +275,12 @@ function updateBuildPropertyLocal (proj, targetName, prop, value, build) { if (!target || !target.buildConfigurationList) { proj.updateBuildProperty(prop, value, build); } else { - var targetProjectBuildReference = target.buildConfigurationList; // Collect the uuid's from the configuration of our target - var COMMENT_KEY = /_comment$/; - var validConfigs = []; - var configList = proj.pbxXCConfigurationList(); + const COMMENT_KEY = /_comment$/; + const validConfigs = []; + const configList = proj.pbxXCConfigurationList(); for (var configName in configList) { - if (!COMMENT_KEY.test(configName) && targetProjectBuildReference === configName) { + if (!COMMENT_KEY.test(configName) && target.buildConfigurationList === configName) { var buildVariants = configList[configName].buildConfigurations; for (var i = 0; i < buildVariants.length; i++) { validConfigs.push(buildVariants[i].value); From 57f9fb730d392bdac3da506c1c40593f9f805ecf Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Tue, 24 Dec 2019 11:27:34 +0100 Subject: [PATCH 13/14] Code styling --- bin/templates/scripts/cordova/lib/prepare.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index fb051f0b3..52752662f 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -279,23 +279,23 @@ function updateBuildPropertyLocal (proj, targetName, prop, value, build) { const COMMENT_KEY = /_comment$/; const validConfigs = []; const configList = proj.pbxXCConfigurationList(); - for (var configName in configList) { + for (const configName in configList) { if (!COMMENT_KEY.test(configName) && target.buildConfigurationList === configName) { - var buildVariants = configList[configName].buildConfigurations; - for (var i = 0; i < buildVariants.length; i++) { + const buildVariants = configList[configName].buildConfigurations; + for (let i = 0; i < buildVariants.length; i++) { validConfigs.push(buildVariants[i].value); } break; } } // Only update target props - var configs = proj.pbxXCBuildConfigurationSection(); - for (configName in configs) { + const configs = proj.pbxXCBuildConfigurationSection(); + for (const configName in configs) { if (!COMMENT_KEY.test(configName)) { if (!validConfigs.includes(configName)) { continue; } - var config = configs[configName]; + const config = configs[configName]; if ((build && config.name === build) || (!build)) { config.buildSettings[prop] = value; } From f9fd874c575605fceeca208f537f354dca6ae574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Wed, 25 Dec 2019 09:54:47 +0900 Subject: [PATCH 14/14] chore: updated syntax Used a throw to fall back to default. Changed a for loop to use for-of See: https://github.com/GEDYSIntraWare/cordova-ios/pull/1 --- bin/templates/scripts/cordova/lib/prepare.js | 61 +++++++++++--------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 52752662f..496d1914d 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -272,37 +272,46 @@ function updateBuildPropertyLocal (proj, targetName, prop, value, build) { try { // Check if we have a valid target - during prepare we do not have it const target = proj.pbxTargetByName(targetName); - if (!target || !target.buildConfigurationList) { - proj.updateBuildProperty(prop, value, build); - } else { - // Collect the uuid's from the configuration of our target - const COMMENT_KEY = /_comment$/; - const validConfigs = []; - const configList = proj.pbxXCConfigurationList(); - for (const configName in configList) { - if (!COMMENT_KEY.test(configName) && target.buildConfigurationList === configName) { - const buildVariants = configList[configName].buildConfigurations; - for (let i = 0; i < buildVariants.length; i++) { - validConfigs.push(buildVariants[i].value); - } - break; + const targetBuildConfigs = target && target.buildConfigurationList; + + // Go to fallback in the catch and update build properties + if (!targetBuildConfigs) throw new CordovaError(`The target "${targetName}" is missing build configurations. Falling back to update build properties.`); + + const COMMENT_KEY = /_comment$/; + const validConfigs = []; + const xcConfigList = proj.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; } - // Only update target props - const configs = proj.pbxXCBuildConfigurationSection(); - for (const configName in configs) { - if (!COMMENT_KEY.test(configName)) { - if (!validConfigs.includes(configName)) { - continue; - } - const config = configs[configName]; - if ((build && config.name === build) || (!build)) { - config.buildSettings[prop] = value; - } + } + + const configs = proj.pbxXCBuildConfigurationSection(); + + // Only update target props + for (const configName in configs) { + if (!COMMENT_KEY.test(configName)) { + if (!validConfigs.includes(configName)) continue; + + const config = configs[configName]; + + if ((build && config.name === build) || (!build)) { + config.buildSettings[prop] = value; } } } - } catch (e) { // fallback to default behavior on error + } catch (e) { + // fallback to default behavior on error + events.emit('verbose', e); + proj.updateBuildProperty(prop, value, build); } }