@@ -2,6 +2,10 @@ import chalk from 'chalk';
2
2
import { Device } from '../types' ;
3
3
import { prompt } from '@react-native-community/cli-tools' ;
4
4
5
+ function getVersionFromDevice ( { version} : Device ) {
6
+ return version ? ` (${ version . match ( / ^ ( \d + \. \d + ) / ) ?. [ 1 ] } )` : '' ;
7
+ }
8
+
5
9
export async function promptForSchemeSelection (
6
10
schemes : string [ ] ,
7
11
) : Promise < string > {
@@ -57,17 +61,15 @@ export async function promptForDeviceSelection(
57
61
choices : sortedDevices
58
62
. filter ( ( { type} ) => type === 'device' || type === 'simulator' )
59
63
. map ( ( d ) => {
60
- const version = d . version
61
- ? ` (${ d . version . match ( / ^ ( \d + \. \d + ) / ) ?. [ 1 ] } )`
62
- : '' ;
63
-
64
64
const availability =
65
65
! d . isAvailable && ! ! d . availabilityError
66
66
? chalk . red ( `(unavailable - ${ d . availabilityError } )` )
67
67
: '' ;
68
68
69
69
return {
70
- title : `${ chalk . bold ( `${ d . name } ${ version } ` ) } ${ availability } ` ,
70
+ title : `${ chalk . bold (
71
+ `${ d . name } ${ getVersionFromDevice ( d ) } ` ,
72
+ ) } ${ availability } `,
71
73
value : d ,
72
74
disabled : ! d . isAvailable ,
73
75
} ;
@@ -76,3 +78,20 @@ export async function promptForDeviceSelection(
76
78
} ) ;
77
79
return device ;
78
80
}
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