(
executor: CommandExecutor,
options: { enabled?: boolean } = {},
)
| 73 | } |
| 74 | |
| 75 | export async function listSimulators( |
| 76 | executor: CommandExecutor, |
| 77 | options: { enabled?: boolean } = {}, |
| 78 | ): Promise<ListedSimulator[]> { |
| 79 | const result = await executor( |
| 80 | ['xcrun', 'simctl', 'list', 'devices', '--json'], |
| 81 | 'List Simulators', |
| 82 | false, |
| 83 | ); |
| 84 | |
| 85 | if (!result.success) { |
| 86 | throw new Error(`Failed to list simulators: ${result.error}`); |
| 87 | } |
| 88 | |
| 89 | const parsedData: unknown = JSON.parse(result.output); |
| 90 | if (!isSimulatorData(parsedData)) { |
| 91 | throw new Error('Unexpected simctl output format'); |
| 92 | } |
| 93 | |
| 94 | const listed: ListedSimulator[] = []; |
| 95 | for (const runtime in parsedData.devices) { |
| 96 | for (const device of parsedData.devices[runtime]) { |
| 97 | if (options.enabled === true && !device.isAvailable) { |
| 98 | continue; |
| 99 | } |
| 100 | |
| 101 | listed.push({ |
| 102 | runtime, |
| 103 | name: device.name, |
| 104 | udid: device.udid, |
| 105 | state: device.state, |
| 106 | isAvailable: device.isAvailable, |
| 107 | }); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return listed; |
| 112 | } |
| 113 | |
| 114 | function formatRuntimeName(runtime: string): string { |
| 115 | const match = runtime.match(/SimRuntime\.(.+)$/); |
no test coverage detected