Skip to content

Commit

Permalink
feat: Add ability to use PREFERRED_IOS_DEVICES environment variable #…
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenfalk committed Jan 25, 2024
1 parent f9d8a74 commit 060709b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/cli-platform-apple/src/commands/runCommand/createRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down
9 changes: 9 additions & 0 deletions packages/cli-platform-ios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 060709b

Please sign in to comment.