From 2501dee0438862d5ce90e81a5f6dc76dd9782473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 18 Sep 2023 17:42:08 +0200 Subject: [PATCH 1/3] refactor(iOS): remove unintended flags from build-ios --- packages/cli-platform-ios/README.md | 43 +-- .../src/commands/buildIOS/buildOptions.ts | 54 ++++ .../src/commands/buildIOS/buildProject.ts | 17 +- .../src/commands/buildIOS/getConfiguration.ts | 49 ++++ .../buildIOS/getXcodeProjectAndDir.ts | 22 ++ .../src/commands/buildIOS/index.ts | 253 +----------------- .../src/commands/runIOS/index.ts | 129 +++------ .../getBuildConfigurationFromXcScheme.ts | 9 +- .../src/tools/getConfigurationScheme.ts | 22 -- .../src/tools/selectFromInteractiveMode.ts | 20 +- 10 files changed, 197 insertions(+), 421 deletions(-) create mode 100644 packages/cli-platform-ios/src/commands/buildIOS/buildOptions.ts create mode 100644 packages/cli-platform-ios/src/commands/buildIOS/getConfiguration.ts create mode 100644 packages/cli-platform-ios/src/commands/buildIOS/getXcodeProjectAndDir.ts delete mode 100644 packages/cli-platform-ios/src/tools/getConfigurationScheme.ts diff --git a/packages/cli-platform-ios/README.md b/packages/cli-platform-ios/README.md index c4a6545c1..162f1603e 100644 --- a/packages/cli-platform-ios/README.md +++ b/packages/cli-platform-ios/README.md @@ -112,31 +112,10 @@ Usage: npx react-native build-ios [options] ``` -Builds IOS app. +Builds iOS app. #### Options -#### `--simulator ` - -> default: iPhone 14 - -Explicitly set the simulator to use. Optionally include iOS version between parenthesis at the end to match an exact version, e.g. `"iPhone 6 (10.0)"`. - -Notes: If selected simulator does not exist, cli will try to run fallback simulators in following order: - -- `iPhone 14` -- `iPhone 13` -- `iPhone 12` -- `iPhone 11` - -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). - -Example: this will launch your project directly onto the iPhone 14 simulator: - -```sh -npx react-native build-ios --simulator "iPhone 14" -``` - #### `--mode ` Explicitly set the scheme configuration to use. This option is case sensitive. @@ -155,28 +134,10 @@ Explicitly set Xcode scheme to use. Explicitly set Xcode target to use. -#### `--device [string]` - -Explicitly set device to use by name. The value is not required if you have a single device connected. - -#### `--udid ` - -Explicitly set device to use by udid. - -#### `--no-packager` - -Do not launch packager while building. - #### `--verbose` Do not use `xcbeautify` or `xcpretty` even if installed. -#### `--port ` - -Runs packager on specified port. - -Default: `process.env.RCT_METRO_PORT || 8081` - #### `--xcconfig ` Explicitly pass `xcconfig` options from the command line. @@ -204,8 +165,6 @@ Example: npx react-native build-ios --extra-params "-jobs 4" ``` -### log-ios - ### `log-ios` Usage: diff --git a/packages/cli-platform-ios/src/commands/buildIOS/buildOptions.ts b/packages/cli-platform-ios/src/commands/buildIOS/buildOptions.ts new file mode 100644 index 000000000..27ebd690e --- /dev/null +++ b/packages/cli-platform-ios/src/commands/buildIOS/buildOptions.ts @@ -0,0 +1,54 @@ +export type BuildFlags = { + mode?: string; + target?: string; + verbose?: boolean; + scheme?: string; + xcconfig?: string; + buildFolder?: string; + interactive?: boolean; + destination?: string; + extraParams?: string[]; +}; + +export const buildOptions = [ + { + name: '--mode ', + description: + 'Explicitly set the scheme configuration to use. This option is case sensitive.', + }, + { + name: '--scheme ', + description: 'Explicitly set Xcode scheme to use', + }, + { + name: '--destination ', + description: 'Explicitly extend destination e.g. "arch=x86_64"', + }, + { + name: '--verbose', + description: 'Do not use xcbeautify or xcpretty even if installed', + }, + { + name: '--xcconfig [string]', + description: 'Explicitly set xcconfig to use', + }, + { + name: '--buildFolder ', + description: + 'Location for iOS build artifacts. Corresponds to Xcode\'s "-derivedDataPath".', + }, + { + name: '--extra-params ', + description: 'Custom params that will be passed to xcodebuild command.', + parse: (val: string) => val.split(' '), + }, + { + name: '--target ', + description: 'Explicitly set Xcode target to use.', + }, + { + name: '--interactive', + description: + 'Explicitly select which scheme and configuration to use before running a build', + }, +]; diff --git a/packages/cli-platform-ios/src/commands/buildIOS/buildProject.ts b/packages/cli-platform-ios/src/commands/buildIOS/buildProject.ts index d3b781fd1..4917cf5ac 100644 --- a/packages/cli-platform-ios/src/commands/buildIOS/buildProject.ts +++ b/packages/cli-platform-ios/src/commands/buildIOS/buildProject.ts @@ -10,21 +10,12 @@ import { printRunDoctorTip, getLoader, } from '@react-native-community/cli-tools'; - -export type BuildFlags = { - mode: string; - target: string; - verbose: boolean; - xcconfig?: string; - buildFolder?: string; - interactive?: boolean; - destination?: string; - extraParams?: string[]; -}; +import type {BuildFlags} from './buildOptions'; export function buildProject( xcodeProject: IOSProjectInfo, udid: string | undefined, + mode: string, scheme: string, args: BuildFlags, ): Promise { @@ -35,13 +26,13 @@ export function buildProject( ...(args.xcconfig ? ['-xcconfig', args.xcconfig] : []), ...(args.buildFolder ? ['-derivedDataPath', args.buildFolder] : []), '-configuration', - args.mode, + mode, '-scheme', scheme, '-destination', (udid ? `id=${udid}` - : args.mode === 'Debug' + : mode === 'Debug' ? 'generic/platform=iOS Simulator' : 'generic/platform=iOS') + (args.destination ? ',' + args.destination : ''), diff --git a/packages/cli-platform-ios/src/commands/buildIOS/getConfiguration.ts b/packages/cli-platform-ios/src/commands/buildIOS/getConfiguration.ts new file mode 100644 index 000000000..7da525d22 --- /dev/null +++ b/packages/cli-platform-ios/src/commands/buildIOS/getConfiguration.ts @@ -0,0 +1,49 @@ +import chalk from 'chalk'; +import {IOSProjectInfo} from '@react-native-community/cli-types'; +import {logger} from '@react-native-community/cli-tools'; +import {selectFromInteractiveMode} from '../../tools/selectFromInteractiveMode'; +import {getProjectInfo} from '../../tools/getProjectInfo'; +import {checkIfConfigurationExists} from '../../tools/checkIfConfigurationExists'; +import type {BuildFlags} from './buildOptions'; +import {getBuildConfigurationFromXcScheme} from '../../tools/getBuildConfigurationFromXcScheme'; + +export async function getConfiguration( + xcodeProject: IOSProjectInfo, + sourceDir: string, + args: BuildFlags, +) { + const projectInfo = getProjectInfo(); + + if (args.mode) { + checkIfConfigurationExists(projectInfo, args.mode); + } + + let scheme = args.scheme || projectInfo.schemes[0]; + let mode = + args.mode || + getBuildConfigurationFromXcScheme(scheme, 'Debug', sourceDir, projectInfo); + + if (args.interactive) { + const selection = await selectFromInteractiveMode({ + scheme, + mode, + projectInfo, + }); + + if (selection.scheme) { + scheme = selection.scheme; + } + + if (selection.mode) { + mode = selection.mode; + } + } + + logger.info( + `Found Xcode ${ + xcodeProject.isWorkspace ? 'workspace' : 'project' + } "${chalk.bold(xcodeProject.name)}"`, + ); + + return {scheme, mode}; +} diff --git a/packages/cli-platform-ios/src/commands/buildIOS/getXcodeProjectAndDir.ts b/packages/cli-platform-ios/src/commands/buildIOS/getXcodeProjectAndDir.ts new file mode 100644 index 000000000..cccfb30cc --- /dev/null +++ b/packages/cli-platform-ios/src/commands/buildIOS/getXcodeProjectAndDir.ts @@ -0,0 +1,22 @@ +import {IOSProjectConfig} from '@react-native-community/cli-types'; +import {CLIError} from '@react-native-community/cli-tools'; + +export function getXcodeProjectAndDir( + iosProjectConfig: IOSProjectConfig | undefined, +) { + if (!iosProjectConfig) { + throw new CLIError( + 'iOS project folder not found. Are you sure this is a React Native project?', + ); + } + + const {xcodeProject, sourceDir} = iosProjectConfig; + + if (!xcodeProject) { + throw new CLIError( + `Could not find Xcode project files in "${sourceDir}" folder`, + ); + } + + return {xcodeProject, sourceDir}; +} diff --git a/packages/cli-platform-ios/src/commands/buildIOS/index.ts b/packages/cli-platform-ios/src/commands/buildIOS/index.ts index f10f971a5..08ba61b0c 100644 --- a/packages/cli-platform-ios/src/commands/buildIOS/index.ts +++ b/packages/cli-platform-ios/src/commands/buildIOS/index.ts @@ -6,262 +6,31 @@ * */ -import path from 'path'; -import chalk from 'chalk'; import {Config} from '@react-native-community/cli-types'; -import {logger, CLIError} from '@react-native-community/cli-tools'; -import {Device} from '../../types'; -import {BuildFlags, buildProject} from './buildProject'; -import {getDestinationSimulator} from '../../tools/getDestinationSimulator'; -import {selectFromInteractiveMode} from '../../tools/selectFromInteractiveMode'; -import {getProjectInfo} from '../../tools/getProjectInfo'; -import {checkIfConfigurationExists} from '../../tools/checkIfConfigurationExists'; -import {getConfigurationScheme} from '../../tools/getConfigurationScheme'; -import listIOSDevices from '../../tools/listIOSDevices'; +import {buildProject} from './buildProject'; +import {BuildFlags, buildOptions} from './buildOptions'; +import {getConfiguration} from './getConfiguration'; +import {getXcodeProjectAndDir} from './getXcodeProjectAndDir'; -export interface FlagsT extends BuildFlags { - simulator?: string; - device?: string | true; - udid?: string; - scheme?: string; -} - -async function buildIOS(_: Array, ctx: Config, args: FlagsT) { - if (!ctx.project.ios) { - throw new CLIError( - 'iOS project folder not found. Are you sure this is a React Native project?', - ); - } - - const {xcodeProject, sourceDir} = ctx.project.ios; - - if (!xcodeProject) { - throw new CLIError( - `Could not find Xcode project files in "${sourceDir}" folder`, - ); - } +async function buildIOS(_: Array, ctx: Config, args: BuildFlags) { + const {xcodeProject, sourceDir} = getXcodeProjectAndDir(ctx.project.ios); process.chdir(sourceDir); - const projectInfo = getProjectInfo(); - - if (args.mode) { - checkIfConfigurationExists(projectInfo, args.mode); - } - - const inferredSchemeName = path.basename( - xcodeProject.name, - path.extname(xcodeProject.name), - ); - - let scheme = args.scheme || inferredSchemeName; - let mode = args.mode; - - if (args.interactive) { - const selection = await selectFromInteractiveMode({scheme, mode}); - - if (selection.scheme) { - scheme = selection.scheme; - } - - if (selection.mode) { - mode = selection.mode; - } - } - - const modifiedArgs = {...args, scheme, mode}; - - args.mode = getConfigurationScheme( - {scheme: args.scheme, mode: args.mode}, - sourceDir, - ); - - logger.info( - `Found Xcode ${ - xcodeProject.isWorkspace ? 'workspace' : 'project' - } "${chalk.bold(xcodeProject.name)}"`, - ); - - // // No need to load all available devices - if (!args.device && !args.udid) { - if (!args.simulator) { - return buildProject(xcodeProject, undefined, scheme, modifiedArgs); - } - - /** - * If provided simulator does not exist, try simulators in following order - * - iPhone 14 - * - iPhone 13 - * - iPhone 12 - * - iPhone 11 - */ - const fallbackSimulators = [ - 'iPhone 14', - 'iPhone 13', - 'iPhone 12', - 'iPhone 11', - ]; - - const selectedSimulator = getDestinationSimulator(args, fallbackSimulators); - - return buildProject( - xcodeProject, - selectedSimulator.udid, - scheme, - modifiedArgs, - ); - } + const {scheme, mode} = await getConfiguration(xcodeProject, sourceDir, args); - if (args.device && args.udid) { - return logger.error( - 'The `device` and `udid` options are mutually exclusive.', - ); - } - - const devices = await listIOSDevices(); - - if (args.udid) { - const device = devices.find((d) => d.udid === args.udid); - if (!device) { - return logger.error( - `Could not find a device with udid: "${chalk.bold( - args.udid, - )}". ${printFoundDevices(devices)}`, - ); - } - - return buildProject(xcodeProject, device.udid, scheme, modifiedArgs); - } else { - const physicalDevices = devices.filter((d) => d.type !== 'simulator'); - const device = matchingDevice(physicalDevices, args.device); - if (device) { - return buildProject(xcodeProject, device.udid, scheme, modifiedArgs); - } - } -} - -function matchingDevice( - devices: Array, - deviceName: string | true | undefined, -) { - if (deviceName === true) { - const firstIOSDevice = devices.find((d) => d.type === 'device')!; - if (firstIOSDevice) { - logger.info( - `Using first available device named "${chalk.bold( - firstIOSDevice.name, - )}" due to lack of name supplied.`, - ); - return firstIOSDevice; - } else { - logger.error('No iOS devices connected.'); - return undefined; - } - } - const deviceByName = devices.find( - (device) => - device.name === deviceName || formattedDeviceName(device) === deviceName, - ); - if (!deviceByName) { - logger.error( - `Could not find a device named: "${chalk.bold( - String(deviceName), - )}". ${printFoundDevices(devices)}`, - ); - } - return deviceByName; -} - -function formattedDeviceName(simulator: Device) { - return simulator.version - ? `${simulator.name} (${simulator.version})` - : simulator.name; -} - -function printFoundDevices(devices: Array) { - return [ - 'Available devices:', - ...devices.map((device) => ` - ${device.name} (${device.udid})`), - ].join('\n'); + return buildProject(xcodeProject, undefined, mode, scheme, args); } -export const iosBuildOptions = [ - { - name: '--simulator ', - description: - 'Explicitly set simulator to use. Optionally include iOS version between ' + - 'parenthesis at the end to match an exact version: "iPhone 6 (10.0)"', - }, - { - name: '--mode ', - description: - 'Explicitly set the scheme configuration to use. This option is case sensitive.', - }, - { - name: '--scheme ', - description: 'Explicitly set Xcode scheme to use', - }, - { - name: '--device [string]', - description: - 'Explicitly set device to use by name. The value is not required if you have a single device connected.', - }, - { - name: '--destination ', - description: 'Explicitly extend destination e.g. "arch=x86_64"', - }, - { - name: '--udid ', - description: 'Explicitly set device to use by udid', - }, - { - name: '--verbose', - description: 'Do not use xcbeautify or xcpretty even if installed', - }, - { - name: '--xcconfig [string]', - description: 'Explicitly set xcconfig to use', - }, - { - name: '--buildFolder ', - description: - 'Location for iOS build artifacts. Corresponds to Xcode\'s "-derivedDataPath".', - }, - { - name: '--extra-params ', - description: 'Custom params that will be passed to xcodebuild command.', - parse: (val: string) => val.split(' '), - }, - { - name: '--target ', - description: 'Explicitly set Xcode target to use.', - }, -]; - export default { name: 'build-ios', - description: 'builds your app on iOS simulator', + description: 'builds your app for iOS platform', func: buildIOS, examples: [ { - desc: 'Build the app for the IOS simulator', - cmd: 'npx react-native build-ios', - }, - { - desc: 'Build the app for all IOS devices', + desc: 'Build the app for all iOS devices in Release mode', cmd: 'npx react-native build-ios --mode "Release"', }, - { - desc: 'Build the app for a specific IOS device', - cmd: 'npx react-native build-ios --simulator "IPhone 11"', - }, - ], - options: [ - ...iosBuildOptions, - { - name: '--interactive', - description: - 'Explicitly select which scheme and configuration to use before running a build', - }, ], + options: buildOptions, }; diff --git a/packages/cli-platform-ios/src/commands/runIOS/index.ts b/packages/cli-platform-ios/src/commands/runIOS/index.ts index 9d375293c..eb0b95244 100644 --- a/packages/cli-platform-ios/src/commands/runIOS/index.ts +++ b/packages/cli-platform-ios/src/commands/runIOS/index.ts @@ -22,21 +22,17 @@ import { logAlreadyRunningBundler, handlePortUnavailable, } from '@react-native-community/cli-tools'; -import {BuildFlags, buildProject} from '../buildIOS/buildProject'; -import {iosBuildOptions} from '../buildIOS'; +import {buildProject} from '../buildIOS/buildProject'; +import {BuildFlags, buildOptions} from '../buildIOS/buildOptions'; +import {getConfiguration} from '../buildIOS/getConfiguration'; import {Device} from '../../types'; import listIOSDevices from '../../tools/listIOSDevices'; -import {checkIfConfigurationExists} from '../../tools/checkIfConfigurationExists'; -import {getProjectInfo} from '../../tools/getProjectInfo'; -import {getConfigurationScheme} from '../../tools/getConfigurationScheme'; -import {selectFromInteractiveMode} from '../../tools/selectFromInteractiveMode'; import {promptForDeviceSelection} from '../../tools/prompts'; import getSimulators from '../../tools/getSimulators'; +import {getXcodeProjectAndDir} from '../buildIOS/getXcodeProjectAndDir'; export interface FlagsT extends BuildFlags { simulator?: string; - scheme?: string; - projectPath: string; device?: string | true; udid?: string; binaryPath?: string; @@ -82,19 +78,7 @@ async function runIOS(_: Array, ctx: Config, args: FlagsT) { link.setVersion(ctx.reactNativeVersion); } - if (!ctx.project.ios) { - throw new CLIError( - 'iOS project folder not found. Are you sure this is a React Native project?', - ); - } - - const {xcodeProject, sourceDir} = ctx.project.ios; - - if (!xcodeProject) { - throw new CLIError( - `Could not find Xcode project files in "${sourceDir}" folder`, - ); - } + const {xcodeProject, sourceDir} = getXcodeProjectAndDir(ctx.project.ios); process.chdir(sourceDir); @@ -110,51 +94,14 @@ async function runIOS(_: Array, ctx: Config, args: FlagsT) { } } - const projectInfo = getProjectInfo(); - - if (args.mode) { - checkIfConfigurationExists(projectInfo, args.mode); - } - - const inferredSchemeName = path.basename( - xcodeProject.name, - path.extname(xcodeProject.name), - ); - - let scheme = args.scheme || inferredSchemeName; - let mode = args.mode; - - if (args.interactive) { - const selection = await selectFromInteractiveMode({scheme, mode}); - - if (selection.scheme) { - scheme = selection.scheme; - } - - if (selection.mode) { - mode = selection.mode; - } - } - - const modifiedArgs = {...args, scheme, mode}; - - modifiedArgs.mode = getConfigurationScheme( - {scheme: modifiedArgs.scheme, mode: modifiedArgs.mode}, - sourceDir, - ); - - logger.info( - `Found Xcode ${ - xcodeProject.isWorkspace ? 'workspace' : 'project' - } "${chalk.bold(xcodeProject.name)}"`, - ); + const {mode, scheme} = await getConfiguration(xcodeProject, sourceDir, args); const availableDevices = await listIOSDevices(); - if (modifiedArgs.listDevices || modifiedArgs.interactive) { - if (modifiedArgs.device || modifiedArgs.udid) { + if (args.listDevices || args.interactive) { + if (args.device || args.udid) { logger.warn( `Both ${ - modifiedArgs.device ? 'device' : 'udid' + args.device ? 'device' : 'udid' } and "list-devices" parameters were passed to "run" command. We will list available devices and let you choose from one.`, ); } @@ -167,13 +114,13 @@ async function runIOS(_: Array, ctx: Config, args: FlagsT) { ); } if (selectedDevice.type === 'simulator') { - return runOnSimulator(xcodeProject, scheme, modifiedArgs, selectedDevice); + return runOnSimulator(xcodeProject, mode, scheme, args, selectedDevice); } else { - return runOnDevice(selectedDevice, scheme, xcodeProject, modifiedArgs); + return runOnDevice(selectedDevice, mode, scheme, xcodeProject, args); } } - if (!modifiedArgs.device && !modifiedArgs.udid && !modifiedArgs.simulator) { + if (!args.device && !args.udid && !args.simulator) { const bootedDevices = availableDevices.filter( ({type, isAvailable}) => type === 'device' && isAvailable, ); @@ -189,54 +136,56 @@ async function runIOS(_: Array, ctx: Config, args: FlagsT) { logger.info( 'No booted devices or simulators found. Launching first available simulator...', ); - return runOnSimulator(xcodeProject, scheme, modifiedArgs); + return runOnSimulator(xcodeProject, mode, scheme, args); } logger.info(`Found booted ${booted.map(({name}) => name).join(', ')}`); return runOnBootedDevicesSimulators( + mode, scheme, xcodeProject, - modifiedArgs, + args, bootedDevices, bootedSimulators, ); } - if (modifiedArgs.device && modifiedArgs.udid) { + if (args.device && args.udid) { return logger.error( 'The `device` and `udid` options are mutually exclusive.', ); } - if (modifiedArgs.udid) { - const device = availableDevices.find((d) => d.udid === modifiedArgs.udid); + if (args.udid) { + const device = availableDevices.find((d) => d.udid === args.udid); if (!device) { return logger.error( `Could not find a device with udid: "${chalk.bold( - modifiedArgs.udid, + args.udid, )}". ${printFoundDevices(availableDevices)}`, ); } if (device.type === 'simulator') { - return runOnSimulator(xcodeProject, scheme, modifiedArgs); + return runOnSimulator(xcodeProject, mode, scheme, args); } else { - return runOnDevice(device, scheme, xcodeProject, modifiedArgs); + return runOnDevice(device, mode, scheme, xcodeProject, args); } - } else if (modifiedArgs.device) { + } else if (args.device) { const physicalDevices = availableDevices.filter( ({type}) => type !== 'simulator', ); - const device = matchingDevice(physicalDevices, modifiedArgs.device); + const device = matchingDevice(physicalDevices, args.device); if (device) { - return runOnDevice(device, scheme, xcodeProject, modifiedArgs); + return runOnDevice(device, mode, scheme, xcodeProject, args); } } else { - runOnSimulator(xcodeProject, scheme, modifiedArgs); + runOnSimulator(xcodeProject, mode, scheme, args); } } async function runOnBootedDevicesSimulators( + mode: string, scheme: string, xcodeProject: IOSProjectInfo, args: FlagsT, @@ -244,16 +193,17 @@ async function runOnBootedDevicesSimulators( simulators: Device[], ) { for (const device of devices) { - await runOnDevice(device, scheme, xcodeProject, args); + await runOnDevice(device, mode, scheme, xcodeProject, args); } for (const simulator of simulators) { - await runOnSimulator(xcodeProject, scheme, args, simulator); + await runOnSimulator(xcodeProject, mode, scheme, args, simulator); } } async function runOnSimulator( xcodeProject: IOSProjectInfo, + mode: string, scheme: string, args: FlagsT, simulator?: Device, @@ -318,13 +268,14 @@ async function runOnSimulator( buildOutput = await buildProject( xcodeProject, selectedSimulator.udid, + mode, scheme, args, ); appPath = await getBuildPath( xcodeProject, - args.mode, + mode, buildOutput, scheme, args.target, @@ -372,6 +323,7 @@ async function runOnSimulator( async function runOnDevice( selectedDevice: Device, + mode: string, scheme: string, xcodeProject: IOSProjectInfo, args: FlagsT, @@ -400,13 +352,14 @@ async function runOnDevice( const buildOutput = await buildProject( xcodeProject, selectedDevice.udid, + mode, scheme, args, ); const appPath = await getBuildPath( xcodeProject, - args.mode, + mode, buildOutput, scheme, args.target, @@ -423,13 +376,14 @@ async function runOnDevice( buildOutput = await buildProject( xcodeProject, selectedDevice.udid, + mode, scheme, args, ); appPath = await getBuildPath( xcodeProject, - args.mode, + mode, buildOutput, scheme, args.target, @@ -516,10 +470,10 @@ async function getTargetPaths( async function getBuildPath( xcodeProject: IOSProjectInfo, - mode: BuildFlags['mode'], + mode: string, buildOutput: string, scheme: string, - target: string, + target: string | undefined, isCatalyst: boolean = false, ) { const buildSettings = child_process.execFileSync( @@ -636,7 +590,7 @@ export default { }, ], options: [ - ...iosBuildOptions, + ...buildOptions, { name: '--no-packager', description: 'Do not launch packager while running the app', @@ -662,10 +616,5 @@ export default { description: 'List all available iOS devices and simulators and let you choose one to run the app. ', }, - { - name: '--interactive', - description: - 'Explicitly select which scheme and configuration to use before running a build and select device to run the application.', - }, ], }; diff --git a/packages/cli-platform-ios/src/tools/getBuildConfigurationFromXcScheme.ts b/packages/cli-platform-ios/src/tools/getBuildConfigurationFromXcScheme.ts index de4b9dada..95255fc3e 100644 --- a/packages/cli-platform-ios/src/tools/getBuildConfigurationFromXcScheme.ts +++ b/packages/cli-platform-ios/src/tools/getBuildConfigurationFromXcScheme.ts @@ -1,7 +1,9 @@ import {CLIError} from '@react-native-community/cli-tools'; +import chalk from 'chalk'; import {XMLParser} from 'fast-xml-parser'; import fs from 'fs'; import path from 'path'; +import {IosProjectInfo} from '../types'; const xmlParser = new XMLParser({ignoreAttributes: false}); @@ -9,7 +11,8 @@ export function getBuildConfigurationFromXcScheme( scheme: string, configuration: string, sourceDir: string, -) { + projectInfo: IosProjectInfo, +): string { try { const xcProject = fs .readdirSync(sourceDir) @@ -35,7 +38,9 @@ export function getBuildConfigurationFromXcScheme( } } catch { throw new CLIError( - `Could not find scheme ${scheme}. Please make sure the schema you want to run exists.`, + `Could not find scheme ${scheme}. Please make sure the schema you want to run exists. Available schemas are: ${projectInfo.schemes + .map((name) => chalk.bold(name)) + .join(', ')}'`, ); } diff --git a/packages/cli-platform-ios/src/tools/getConfigurationScheme.ts b/packages/cli-platform-ios/src/tools/getConfigurationScheme.ts deleted file mode 100644 index ecbdd9a6c..000000000 --- a/packages/cli-platform-ios/src/tools/getConfigurationScheme.ts +++ /dev/null @@ -1,22 +0,0 @@ -import {getBuildConfigurationFromXcScheme} from './getBuildConfigurationFromXcScheme'; - -interface Args { - scheme?: string; - mode: string; -} - -export function getConfigurationScheme( - {scheme, mode}: Args, - sourceDir: string, -) { - if (scheme && mode) { - return mode; - } - - const configuration = mode || 'Debug'; - if (scheme) { - return getBuildConfigurationFromXcScheme(scheme, configuration, sourceDir); - } - - return configuration; -} diff --git a/packages/cli-platform-ios/src/tools/selectFromInteractiveMode.ts b/packages/cli-platform-ios/src/tools/selectFromInteractiveMode.ts index 03a92aeb4..105d0d85d 100644 --- a/packages/cli-platform-ios/src/tools/selectFromInteractiveMode.ts +++ b/packages/cli-platform-ios/src/tools/selectFromInteractiveMode.ts @@ -1,33 +1,33 @@ import {logger} from '@react-native-community/cli-tools'; import chalk from 'chalk'; -import {getProjectInfo} from './getProjectInfo'; +import {IosProjectInfo} from '../types'; import { promptForConfigurationSelection, promptForSchemeSelection, } from './prompts'; interface Args { - scheme: string; - mode: string; + scheme?: string; + mode?: string; + projectInfo: IosProjectInfo; } export async function selectFromInteractiveMode({ scheme, mode, -}: Args): Promise { + projectInfo, +}: Args): Promise<{scheme?: string; mode?: string}> { let newScheme = scheme; let newMode = mode; - const project = getProjectInfo(); - - if (project.schemes.length > 1) { - newScheme = await promptForSchemeSelection(project); + if (projectInfo.schemes.length > 1) { + newScheme = await promptForSchemeSelection(projectInfo); } else { logger.info(`Automatically selected ${chalk.bold(scheme)} scheme.`); } - if (project.configurations.length > 1) { - newMode = await promptForConfigurationSelection(project); + if (projectInfo.configurations.length > 1) { + newMode = await promptForConfigurationSelection(projectInfo); } else { logger.info(`Automatically selected ${chalk.bold(mode)} configuration.`); } From 6b3146b8ceaf17b30bf165d048c14e5558bfe361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 18 Sep 2023 17:58:11 +0200 Subject: [PATCH 2/3] test: update snapshot --- __e2e__/__snapshots__/config.test.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__e2e__/__snapshots__/config.test.ts.snap b/__e2e__/__snapshots__/config.test.ts.snap index 0aaacdeeb..0249bc706 100644 --- a/__e2e__/__snapshots__/config.test.ts.snap +++ b/__e2e__/__snapshots__/config.test.ts.snap @@ -26,7 +26,7 @@ exports[`shows up current config without unnecessary output 1`] = ` }, { "name": "build-ios", - "description": "builds your app on iOS simulator", + "description": "builds your app for iOS platform", "examples": [ "<>" ], From 5cc7de2e5f44545296f277fb21f112173e45c20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 19 Sep 2023 12:44:04 +0200 Subject: [PATCH 3/3] docs: move binary-path and list-devices to run-ios --- packages/cli-platform-ios/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/cli-platform-ios/README.md b/packages/cli-platform-ios/README.md index 162f1603e..4dc15d0e3 100644 --- a/packages/cli-platform-ios/README.md +++ b/packages/cli-platform-ios/README.md @@ -104,6 +104,16 @@ Example: npx react-native run-ios --extra-params "-jobs 4" ``` +#### `--binary-path ` + +Installs passed binary instead of building a fresh one. + +#### `--list-devices` + +> default: false + +List all available iOS devices and simulators and let you choose one to run the app. + ### `build-ios` Usage: @@ -146,16 +156,6 @@ Explicitly pass `xcconfig` options from the command line. Location for iOS build artifacts. Corresponds to Xcode's `-derivedDataPath`. -#### `--binary-path ` - -Installs passed binary instead of building a fresh one. - -#### `--list-devices` - -> default: false - -List all available iOS devices and simulators and let you choose one to run the app. - #### `--extra-params ` Custom params that will be passed to `xcodebuild` command.