MCPcopy
hub / github.com/ionic-team/capacitor / openCommand

Function openCommand

cli/src/tasks/open.ts:16–46  ·  view source on GitHub ↗
(config: Config, selectedPlatformName: string)

Source from the content-addressed store, hash-verified

14import { logger } from '../log';
15
16export 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
48function createOpenablePlatformFilter(config: Config): (platform: string) => boolean {
49 return (platform) => platform === config.ios.name || platform === config.android.name;

Callers 1

runProgramFunction · 0.85

Calls 10

isValidPlatformFunction · 0.90
resolvePlatformFunction · 0.90
runPlatformHookFunction · 0.90
selectPlatformsFunction · 0.90
promptForPlatformFunction · 0.90
isFatalFunction · 0.90
fatalFunction · 0.90
openFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected