Skip to content

Commit 9147b97

Browse files
Feature: Remove hardcoded index when selecting the correct build target (#2707)
* Fix: Remove hardcoded index when selecting the correct build target * Fix: Update comment
1 parent 3087830 commit 9147b97

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

packages/cli-platform-apple/src/commands/runCommand/getBuildSettings.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ export async function getBuildSettings(
3636

3737
const settings = JSON.parse(buildSettings);
3838

39-
const targets = settings.map(
40-
({target: settingsTarget}: any) => settingsTarget,
41-
);
42-
43-
let selectedTarget = targets[0];
39+
// Find all 'app' targets in the build settings
40+
const applicationTargets = settings
41+
.filter(
42+
(setting: any) =>
43+
setting.buildSettings.WRAPPER_EXTENSION ===
44+
'app',
45+
)
46+
.map(({target: settingsTarget}: any) => settingsTarget);
4447

48+
if (applicationTargets.length === 0) return null
49+
50+
let selectedTarget = applicationTargets[0];
51+
4552
if (target) {
46-
if (!targets.includes(target)) {
53+
if (!applicationTargets.includes(target)) {
4754
logger.info(
4855
`Target ${chalk.bold(target)} not found for scheme ${chalk.bold(
4956
scheme,
@@ -53,18 +60,9 @@ export async function getBuildSettings(
5360
selectedTarget = target;
5461
}
5562
}
56-
57-
// Find app in all building settings - look for WRAPPER_EXTENSION: 'app',
58-
const targetIndex = targets.indexOf(selectedTarget);
59-
const targetSettings = settings[targetIndex].buildSettings;
60-
61-
const wrapperExtension = targetSettings.WRAPPER_EXTENSION;
62-
63-
if (wrapperExtension === 'app') {
64-
return settings[targetIndex].buildSettings;
65-
}
66-
67-
return null;
63+
64+
const targetIndex = applicationTargets.indexOf(selectedTarget);
65+
return settings[targetIndex].buildSettings;
6866
}
6967

7068
function getPlatformName(buildOutput: string) {

0 commit comments

Comments
 (0)