From 7187925ff1f79a76a0b128748e2b7ac8b55a7bf4 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Dall'Agnol Date: Mon, 29 Apr 2024 15:08:39 -0300 Subject: [PATCH] [cli] Update listDevices order to show physical devices first (#197) * [cli] Update listDevices order to show physical devices first * Add changelog entry --- CHANGELOG.md | 2 ++ apps/cli/src/commands/ListDevices.ts | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48caeb2f..0f8f048f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ ### 💡 Others +- Update devices order to show physical devices first. ([#197](https://github.com/expo/orbit/pull/197) by [@gabrieldonadel](https://github.com/gabrieldonadel)) + ## 1.1.1 — 2024-03-15 ### 🐛 Bug fixes diff --git a/apps/cli/src/commands/ListDevices.ts b/apps/cli/src/commands/ListDevices.ts index 0c5847c0..1f7a29aa 100644 --- a/apps/cli/src/commands/ListDevices.ts +++ b/apps/cli/src/commands/ListDevices.ts @@ -1,6 +1,6 @@ import { AppleDevice, Emulator, Simulator } from 'eas-shared'; import { DevicesPerPlatform } from 'common-types/build/cli-commands/listDevices'; -import { InternalError, Platform } from 'common-types'; +import { InternalError, Platform, Devices } from 'common-types'; export async function listDevicesAsync

({ platform, @@ -14,16 +14,16 @@ export async function listDevicesAsync

({ if (platform === Platform.Ios || platform === Platform.All) { try { - result.ios.devices = result.ios.devices.concat( - await Simulator.getAvailableIosSimulatorsListAsync() - ); - const connectedDevices = await AppleDevice.getConnectedDevicesAsync(); - for (let connectedDevice of connectedDevices) { + for (const connectedDevice of connectedDevices) { if (!result.ios.devices.some(({ udid }) => udid === connectedDevice.udid)) { result.ios.devices.push(connectedDevice); } } + + result.ios.devices = result.ios.devices.concat( + await Simulator.getAvailableIosSimulatorsListAsync() + ); } catch (error) { console.warn('Unable to get iOS devices', error); if (error instanceof Error) { @@ -39,7 +39,11 @@ export async function listDevicesAsync

({ try { const runningDevices = await Emulator.getRunningDevicesAsync(); - result.android.devices = (await Emulator.getAvailableAndroidEmulatorsAsync())?.map( + result.android.devices = result.android.devices.concat( + runningDevices.filter((r) => r.deviceType === 'device') + ); + + const androidEmulators = ((await Emulator.getAvailableAndroidEmulatorsAsync()) || [])?.map( (emulator) => { const runningEmulator = runningDevices.find( (r) => r.deviceType === 'emulator' && r.name === emulator.name @@ -48,12 +52,11 @@ export async function listDevicesAsync

({ ...emulator, state: runningEmulator ? 'Booted' : 'Shutdown', pid: runningEmulator?.pid, - }; + } as Devices.AndroidEmulator; } ); - result.android.devices = result.android.devices.concat( - runningDevices.filter((r) => r.deviceType === 'device') - ); + + result.android.devices = result.android.devices.concat(androidEmulators); } catch (error) { console.warn('Unable to get Android devices', error); if (error instanceof Error) {