Skip to content

Commit ae056a1

Browse files
chore: move devices prompt to prompts.ts (#2224)
* chore: move devices prompt to `prompts.ts` * feat: add simulator version * fix: apply code review suggestions
1 parent fc11714 commit ae056a1

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

packages/cli-platform-apple/src/commands/logCommand/createLog.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {CLIError, logger, prompt} from '@react-native-community/cli-tools';
1+
import {CLIError, logger} from '@react-native-community/cli-tools';
22
import {Config, IOSProjectConfig} from '@react-native-community/cli-types';
33
import {spawnSync} from 'child_process';
44
import os from 'os';
@@ -8,6 +8,7 @@ import listDevices from '../../tools/listDevices';
88
import {getPlatformInfo} from '../runCommand/getPlatformInfo';
99
import {BuilderCommand} from '../../types';
1010
import {supportedPlatforms} from '../../config/supportedPlatforms';
11+
import {promptForDeviceToTailLogs} from '../../tools/prompts';
1112

1213
/**
1314
* Starts Apple device syslog tail
@@ -64,15 +65,10 @@ const createLog =
6465
}
6566

6667
if (args.interactive && bootedAndAvailableSimulators.length > 1) {
67-
const {udid} = await prompt({
68-
type: 'select',
69-
name: 'udid',
70-
message: `Select ${platformReadableName} simulators to tail logs from`,
71-
choices: bootedAndAvailableSimulators.map((simulator) => ({
72-
title: simulator.name,
73-
value: simulator.udid,
74-
})),
75-
});
68+
const udid = await promptForDeviceToTailLogs(
69+
platformReadableName,
70+
bootedAndAvailableSimulators,
71+
);
7672

7773
tailDeviceLogs(udid);
7874
} else {

packages/cli-platform-apple/src/tools/prompts.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import chalk from 'chalk';
22
import {Device} from '../types';
33
import {prompt} from '@react-native-community/cli-tools';
44

5+
function getVersionFromDevice({version}: Device) {
6+
return version ? ` (${version.match(/^(\d+\.\d+)/)?.[1]})` : '';
7+
}
8+
59
export async function promptForSchemeSelection(
610
schemes: string[],
711
): Promise<string> {
@@ -57,17 +61,15 @@ export async function promptForDeviceSelection(
5761
choices: sortedDevices
5862
.filter(({type}) => type === 'device' || type === 'simulator')
5963
.map((d) => {
60-
const version = d.version
61-
? ` (${d.version.match(/^(\d+\.\d+)/)?.[1]})`
62-
: '';
63-
6464
const availability =
6565
!d.isAvailable && !!d.availabilityError
6666
? chalk.red(`(unavailable - ${d.availabilityError})`)
6767
: '';
6868

6969
return {
70-
title: `${chalk.bold(`${d.name}${version}`)} ${availability}`,
70+
title: `${chalk.bold(
71+
`${d.name}${getVersionFromDevice(d)}`,
72+
)} ${availability}`,
7173
value: d,
7274
disabled: !d.isAvailable,
7375
};
@@ -76,3 +78,20 @@ export async function promptForDeviceSelection(
7678
});
7779
return device;
7880
}
81+
82+
export async function promptForDeviceToTailLogs(
83+
platformReadableName: string,
84+
simulators: Device[],
85+
): Promise<string> {
86+
const {udid} = await prompt({
87+
type: 'select',
88+
name: 'udid',
89+
message: `Select ${platformReadableName} simulators to tail logs from`,
90+
choices: simulators.map((simulator) => ({
91+
title: `${simulator.name}${getVersionFromDevice(simulator)}`.trim(),
92+
value: simulator.udid,
93+
})),
94+
});
95+
96+
return udid;
97+
}

0 commit comments

Comments
 (0)