(config: Config, selectedPlatformName: string)
| 14 | import { logger } from '../log'; |
| 15 | |
| 16 | export async function openCommand(config: Config, selectedPlatformName: string): Promise<void> { |
| 17 | if (selectedPlatformName && !(await isValidPlatform(selectedPlatformName))) { |
| 18 | const platformDir = resolvePlatform(config, selectedPlatformName); |
| 19 | if (platformDir) { |
| 20 | await runPlatformHook(config, selectedPlatformName, platformDir, 'capacitor:open'); |
| 21 | } else { |
| 22 | logger.error(`Platform ${c.input(selectedPlatformName)} not found.`); |
| 23 | } |
| 24 | } else { |
| 25 | const platforms = await selectPlatforms(config, selectedPlatformName); |
| 26 | let platformName: string; |
| 27 | if (platforms.length === 1) { |
| 28 | platformName = platforms[0]; |
| 29 | } else { |
| 30 | platformName = await promptForPlatform( |
| 31 | platforms.filter(createOpenablePlatformFilter(config)), |
| 32 | `Please choose a platform to open:`, |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | try { |
| 37 | await open(config, platformName); |
| 38 | } catch (e: any) { |
| 39 | if (!isFatal(e)) { |
| 40 | fatal(e.stack ?? e); |
| 41 | } |
| 42 | |
| 43 | throw e; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | function createOpenablePlatformFilter(config: Config): (platform: string) => boolean { |
| 49 | return (platform) => platform === config.ios.name || platform === config.android.name; |
no test coverage detected