Skip to content

Commit

Permalink
fix: apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonrybczak committed Dec 21, 2023
1 parent c959d6f commit 2442d5e
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions packages/cli-platform-apple/src/tools/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import chalk from 'chalk';
import {Device} from '../types';
import {prompt} from '@react-native-community/cli-tools';

function getVersionFromDevice({version}: Device) {
return version ? ` (${version.match(/^(\d+\.\d+)/)?.[1]})` : '';
}

export async function promptForSchemeSelection(
schemes: string[],
): Promise<string> {
Expand Down Expand Up @@ -57,17 +61,15 @@ export async function promptForDeviceSelection(
choices: sortedDevices
.filter(({type}) => type === 'device' || type === 'simulator')
.map((d) => {
const version = d.version
? ` (${d.version.match(/^(\d+\.\d+)/)?.[1]})`
: '';

const availability =
!d.isAvailable && !!d.availabilityError
? chalk.red(`(unavailable - ${d.availabilityError})`)
: '';

return {
title: `${chalk.bold(`${d.name}${version}`)} ${availability}`,
title: `${chalk.bold(
`${d.name}${getVersionFromDevice(d)}`,
)} ${availability}`,
value: d,
disabled: !d.isAvailable,
};
Expand All @@ -85,16 +87,10 @@ export async function promptForDeviceToTailLogs(
type: 'select',
name: 'udid',
message: `Select ${platformReadableName} simulators to tail logs from`,
choices: simulators.map((simulator) => {
const version = simulator.version
? ` (${simulator.version.match(/^(\d+\.\d+)/)?.[1]})`
: '';

return {
title: `${simulator.name}${version}`.trim(),
value: simulator.udid,
};
}),
choices: simulators.map((simulator) => ({
title: `${simulator.name}${getVersionFromDevice(simulator)}`.trim(),
value: simulator.udid,
})),
});

return udid;
Expand Down

0 comments on commit 2442d5e

Please sign in to comment.