( config: Config, selectedPlatformName: string, options: RunCommandOptions, )
| 38 | } |
| 39 | |
| 40 | export async function runCommand( |
| 41 | config: Config, |
| 42 | selectedPlatformName: string, |
| 43 | options: RunCommandOptions, |
| 44 | ): Promise<void> { |
| 45 | options.host = options.host ?? CapLiveReloadHelper.getIpAddress() ?? 'localhost'; |
| 46 | if (!options.https && !options.port) { |
| 47 | options.port = '3000'; |
| 48 | } |
| 49 | if (selectedPlatformName && !(await isValidPlatform(selectedPlatformName))) { |
| 50 | const platformDir = resolvePlatform(config, selectedPlatformName); |
| 51 | if (platformDir) { |
| 52 | await runPlatformHook(config, selectedPlatformName, platformDir, 'capacitor:run'); |
| 53 | } else { |
| 54 | logger.error(`Platform ${c.input(selectedPlatformName)} not found.`); |
| 55 | } |
| 56 | } else { |
| 57 | const platforms = await selectPlatforms(config, selectedPlatformName); |
| 58 | let platformName: string; |
| 59 | if (platforms.length === 1) { |
| 60 | platformName = platforms[0]; |
| 61 | } else { |
| 62 | platformName = await promptForPlatform( |
| 63 | platforms.filter(createRunnablePlatformFilter(config)), |
| 64 | `Please choose a platform to run:`, |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | if (options.list) { |
| 69 | const targets = await getPlatformTargets(platformName); |
| 70 | const outputTargets = targets.map((t) => ({ |
| 71 | name: getPlatformTargetName(t), |
| 72 | api: `${t.platform === 'ios' ? 'iOS' : 'API'} ${t.sdkVersion}`, |
| 73 | id: t.id ?? '?', |
| 74 | })); |
| 75 | |
| 76 | if (options.json) { |
| 77 | process.stdout.write(`${JSON.stringify(outputTargets)}\n`); |
| 78 | } else { |
| 79 | const rows = outputTargets.map((t) => [t.name, t.api, t.id]); |
| 80 | |
| 81 | output.write( |
| 82 | `${columnar(rows, { |
| 83 | headers: ['Name', 'API', 'Target ID'], |
| 84 | vsep: ' ', |
| 85 | })}\n`, |
| 86 | ); |
| 87 | } |
| 88 | |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | try { |
| 93 | if (options.sync) { |
| 94 | await sync(config, platformName, false, true); |
| 95 | } |
| 96 | const cordovaPlugins = await getCordovaPlugins(config, platformName); |
| 97 | if (options.liveReload) { |
no test coverage detected