1import { isSimulatorDevice, resolveDeviceAsync } from './resolveDevice';
2import { resolveNativeSchemePropsAsync } from './resolveNativeScheme';
3import { resolveXcodeProject } from './resolveXcodeProject';
4import { isOSType } from '../../../start/platforms/ios/simctl';
5import { resolveBundlerPropsAsync } from '../../resolveBundlerProps';
6import { BuildProps, Options } from '../XcodeBuild.types';
7
8/** Resolve arguments for the `run:ios` command. */
9export async function resolveOptionsAsync(
10  projectRoot: string,
11  options: Options
12): Promise<BuildProps> {
13  const xcodeProject = resolveXcodeProject(projectRoot);
14
15  const bundlerProps = await resolveBundlerPropsAsync(projectRoot, options);
16
17  // Resolve the scheme before the device so we can filter devices based on
18  // whichever scheme is selected (i.e. don't present TV devices if the scheme cannot be run on a TV).
19  const { osType, name: scheme } = await resolveNativeSchemePropsAsync(
20    projectRoot,
21    options,
22    xcodeProject
23  );
24
25  // Resolve the device based on the provided device id or prompt
26  // from a list of devices (connected or simulated) that are filtered by the scheme.
27  const device = await resolveDeviceAsync(options.device, {
28    // It's unclear if there's any value to asserting that we haven't hardcoded the os type in the CLI.
29    osType: isOSType(osType) ? osType : undefined,
30  });
31
32  const isSimulator = isSimulatorDevice(device);
33
34  // Use the configuration or `Debug` if none is provided.
35  const configuration = options.configuration || 'Debug';
36
37  // This optimization skips resetting the Metro cache needlessly.
38  // The cache is reset in `../node_modules/react-native/scripts/react-native-xcode.sh` when the
39  // project is running in Debug and built onto a physical device. It seems that this is done because
40  // the script is run from Xcode and unaware of the CLI instance.
41  const shouldSkipInitialBundling = configuration === 'Debug' && !isSimulator;
42
43  return {
44    ...bundlerProps,
45    projectRoot,
46    isSimulator,
47    xcodeProject,
48    device,
49    configuration,
50    shouldSkipInitialBundling,
51    buildCache: options.buildCache !== false,
52    scheme,
53  };
54}
55