MCPcopy Index your code
hub / github.com/ionic-team/capacitor / promptForPlatformTarget

Function promptForPlatformTarget

cli/src/common.ts:378–444  ·  view source on GitHub ↗
(
  targets: PlatformTarget[],
  selectedTarget?: string,
  selectedTargetSdkVersion?: string,
  selectByName?: boolean,
)

Source from the content-addressed store, hash-verified

376}
377
378export async function promptForPlatformTarget(
379 targets: PlatformTarget[],
380 selectedTarget?: string,
381 selectedTargetSdkVersion?: string,
382 selectByName?: boolean,
383): Promise<PlatformTarget> {
384 const { prompt } = await import('prompts');
385 const validTargets = targets.filter((t) => t.id !== undefined);
386 if (!selectedTarget) {
387 if (validTargets.length === 1) {
388 return validTargets[0];
389 } else {
390 const answers = await prompt(
391 [
392 {
393 type: 'select',
394 name: 'target',
395 message: 'Please choose a target device:',
396 choices: validTargets.map((t) => ({
397 title: `${getPlatformTargetName(t)} (${t.id})`,
398 value: t,
399 })),
400 },
401 ],
402 { onCancel: () => process.exit(1) },
403 );
404
405 return answers.target;
406 }
407 }
408
409 const targetID = selectedTarget.trim();
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 });
428
429 if (!target) {
430 if (selectByName) {
431 let invalidTargetName = targetID;
432 if (selectedTargetSdkVersion) {
433 invalidTargetName += ` [${selectedTargetSdkVersion}]`;
434 }
435 fatal(

Callers 2

runAndroidFunction · 0.90
runIOSFunction · 0.90

Calls 2

fatalFunction · 0.90
getPlatformTargetNameFunction · 0.85

Tested by

no test coverage detected