@@ -378,6 +378,8 @@ export interface PlatformTarget {
378378export async function promptForPlatformTarget (
379379 targets : PlatformTarget [ ] ,
380380 selectedTarget ?: string ,
381+ selectedTargetSdkVersion ?: string ,
382+ selectByName ?: boolean ,
381383) : Promise < PlatformTarget > {
382384 const { prompt } = await import ( 'prompts' ) ;
383385 const validTargets = targets . filter ( ( t ) => t . id !== undefined ) ;
@@ -405,10 +407,37 @@ export async function promptForPlatformTarget(
405407 }
406408
407409 const targetID = selectedTarget . trim ( ) ;
408- const target = targets . find ( ( t ) => t . id === targetID ) ;
410+ const target = targets . find ( ( t ) => {
411+ if ( selectByName === true ) {
412+ let name = t . name ?? t . model ;
413+ if ( name ) {
414+ // Apple device names may have "smart quotes" in the name,
415+ // strip them and replace them with the "straight" versions
416+ name = name . replace ( / [ \u2018 \u2019 ] / g, "'" ) . replace ( / [ \u201C \u201D ] / g, '"' ) ;
417+ }
418+
419+ if ( selectedTargetSdkVersion ) {
420+ return name === targetID && t . sdkVersion === selectedTargetSdkVersion ;
421+ }
422+
423+ return name === targetID ;
424+ }
425+
426+ return t . id === targetID ;
427+ } ) ;
409428
410429 if ( ! target ) {
411- fatal ( `Invalid target ID: ${ c . input ( targetID ) } .\n` + `Valid targets are: ${ targets . map ( ( t ) => t . id ) . join ( ', ' ) } ` ) ;
430+ if ( selectByName ) {
431+ let invalidTargetName = targetID ;
432+ if ( selectedTargetSdkVersion ) {
433+ invalidTargetName += ` [${ selectedTargetSdkVersion } ]` ;
434+ }
435+ fatal (
436+ `Invalid target name: ${ c . input ( invalidTargetName ) } .\n` +
437+ `Valid targets are:\n ${ targets . map ( ( t ) => `${ t . name ?? t . model } [${ t . sdkVersion } ]` ) . join ( '\n' ) } ` ,
438+ ) ;
439+ }
440+ fatal ( `Invalid target ID: ${ c . input ( targetID ) } .\n` + `Valid targets are:\n ${ targets . map ( ( t ) => t . id ) . join ( '\n' ) } ` ) ;
412441 }
413442
414443 return target ;
0 commit comments