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

Function getPlatformTargets

cli/src/util/native-run.ts:26–66  ·  view source on GitHub ↗
(platformName: string)

Source from the content-addressed store, hash-verified

24}
25
26export async function getPlatformTargets(platformName: string): Promise<PlatformTarget[]> {
27 const errors = [];
28 try {
29 const output = await runNativeRun([platformName, '--list', '--json']);
30 const parsedOutput = JSON.parse(output);
31 if (parsedOutput.devices.length || parsedOutput.virtualDevices.length) {
32 return [
33 ...parsedOutput.devices.map((t: any) => ({ ...t, virtual: false })),
34 ...parsedOutput.virtualDevices.map((t: any) => ({
35 ...t,
36 virtual: true,
37 })),
38 ];
39 } else {
40 parsedOutput.errors.map((e: any) => {
41 errors.push(e);
42 });
43 }
44 } catch (e: any) {
45 const err = JSON.parse(e);
46 errors.push(err);
47 }
48
49 if (errors.length === 0) {
50 logger.info('No devices found.');
51 return [];
52 }
53
54 const plural = errors.length > 1 ? 's' : '';
55 const errMsg = `${c.strong('native-run')} failed with error${plural}\n
56 ${errors
57 .map((e: any) => {
58 return `\t${c.strong(e.code)}: ${e.error}`;
59 })
60 .join('\n')}
61 \n\tMore details for this error${plural} may be available online: ${c.strong(
62 'https://github.com/ionic-team/native-run/wiki/Android-Errors',
63 )}
64 `;
65 throw errMsg;
66}

Callers 3

runAndroidFunction · 0.90
runIOSFunction · 0.90
runCommandFunction · 0.90

Calls 3

runNativeRunFunction · 0.85
infoMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected