From 060709b3d786967ec7180318892e7538172f7c71 Mon Sep 17 00:00:00 2001 From: Warren Falk Date: Tue, 23 Jan 2024 22:00:23 -0500 Subject: [PATCH] feat: Add ability to use PREFERRED_IOS_DEVICES environment variable #2274 --- .../src/commands/runCommand/createRun.ts | 27 +++++++++++++++++++ packages/cli-platform-ios/README.md | 9 +++++++ 2 files changed, 36 insertions(+) diff --git a/packages/cli-platform-apple/src/commands/runCommand/createRun.ts b/packages/cli-platform-apple/src/commands/runCommand/createRun.ts index f2a67a66a..8ac6bbc83 100644 --- a/packages/cli-platform-apple/src/commands/runCommand/createRun.ts +++ b/packages/cli-platform-apple/src/commands/runCommand/createRun.ts @@ -218,6 +218,33 @@ const createRun = } if (!args.device && !args.udid && !args.simulator) { + const preferences = process.env.PREFERRED_IOS_DEVICES?.split(',') ?? []; + const found = preferences.flatMap((pref) => + devices.filter((dev) => dev.name === pref || dev.udid === pref), + )[0]; + if (found) { + logger.info('Running on device from preferred devices list'); + if (found.type === 'simulator') { + return runOnSimulator( + xcodeProject, + platformName, + mode, + scheme, + args, + found, + ); + } else { + return runOnDevice( + found, + platformName, + mode, + scheme, + xcodeProject, + args, + ); + } + } + const bootedSimulators = devices.filter( ({state, type}) => state === 'Booted' && type === 'simulator', ); diff --git a/packages/cli-platform-ios/README.md b/packages/cli-platform-ios/README.md index 6d8dae878..20815fc97 100644 --- a/packages/cli-platform-ios/README.md +++ b/packages/cli-platform-ios/README.md @@ -118,6 +118,15 @@ List all available iOS devices and simulators and let you choose one to run the Force running `pod install` before running an app +#### Environment Variables + +#### `PREFERRED_IOS_DEVICES` + +Comma-separated list of devices or simulators to use when none are specified +in the command line options. These can be either names or udids. The first to match +an attached device or a simulator will be selected. Matched simulators will be booted +if necessary. + ### `build-ios` Usage: