From df82f0f4b284c114900ff57ff06c9954ef21e076 Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Thu, 24 Nov 2022 19:55:26 +0100 Subject: [PATCH] feat: add support for running currently booted simulator --- docs/commands.md | 2 + .../src/commands/runIOS/index.ts | 39 +++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 2c4b9e156..fda097471 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -404,6 +404,8 @@ Notes: If selected simulator does not exist, cli will try to run fallback simula Notes: `simulator_name` must be a valid iOS simulator name. If in doubt, open your AwesomeApp/ios/AwesomeApp.xcodeproj folder on XCode and unroll the dropdown menu containing the simulator list. The dropdown menu is situated on the right hand side of the play button (top left corner). +Notes: You can pass `booted` as the `simulator_name` to launch the currently booted simulator. + Example: this will launch your project directly onto the iPhone XS Max simulator: ```sh diff --git a/packages/cli-platform-ios/src/commands/runIOS/index.ts b/packages/cli-platform-ios/src/commands/runIOS/index.ts index 99fe43cf2..2d396a073 100644 --- a/packages/cli-platform-ios/src/commands/runIOS/index.ts +++ b/packages/cli-platform-ios/src/commands/runIOS/index.ts @@ -154,18 +154,35 @@ async function runOnSimulator( 'iPhone 12', 'iPhone 11', ]; - const selectedSimulator = fallbackSimulators.reduce((simulator, fallback) => { - return ( - simulator || findMatchingSimulator(simulators, {simulator: fallback}) - ); - }, findMatchingSimulator(simulators, args)); - if (!selectedSimulator) { - throw new CLIError( - `No simulator available with ${ - args.simulator ? `name "${args.simulator}"` : `udid "${args.udid}"` - }`, - ); + let selectedSimulator; + + if (args.simulator && args.simulator === 'booted') { + Object.values(simulators.devices).forEach((devices) => { + const bootedSimulator = devices.find(({state}) => state === 'Booted'); + + if (bootedSimulator) { + selectedSimulator = bootedSimulator; + } + }); + + if (!selectedSimulator) { + throw new CLIError('No booted simulator found.'); + } + } else { + selectedSimulator = fallbackSimulators.reduce((simulator, fallback) => { + return ( + simulator || findMatchingSimulator(simulators, {simulator: fallback}) + ); + }, findMatchingSimulator(simulators, args)); + + if (!selectedSimulator) { + throw new CLIError( + `No simulator available with ${ + args.simulator ? `name "${args.simulator}"` : `udid "${args.udid}"` + }`, + ); + } } /**