Skip to content

Commit 520c90f

Browse files
authored
refactor(iOS): remove unintended flags from build-ios (#2078)
* refactor(iOS): remove unintended flags from build-ios * test: update snapshot * docs: move binary-path and list-devices to run-ios
1 parent 4fac063 commit 520c90f

File tree

11 files changed

+208
-432
lines changed

11 files changed

+208
-432
lines changed

__e2e__/__snapshots__/config.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exports[`shows up current config without unnecessary output 1`] = `
2626
},
2727
{
2828
"name": "build-ios",
29-
"description": "builds your app on iOS simulator",
29+
"description": "builds your app for iOS platform",
3030
"examples": [
3131
"<<REPLACED>>"
3232
],

packages/cli-platform-ios/README.md

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ Example:
104104
npx react-native run-ios --extra-params "-jobs 4"
105105
```
106106

107+
#### `--binary-path <path>`
108+
109+
Installs passed binary instead of building a fresh one.
110+
111+
#### `--list-devices`
112+
113+
> default: false
114+
115+
List all available iOS devices and simulators and let you choose one to run the app.
116+
107117
### `build-ios`
108118

109119
Usage:
@@ -112,31 +122,10 @@ Usage:
112122
npx react-native build-ios [options]
113123
```
114124

115-
Builds IOS app.
125+
Builds iOS app.
116126

117127
#### Options
118128

119-
#### `--simulator <simulator_name>`
120-
121-
> default: iPhone 14
122-
123-
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)"`.
124-
125-
Notes: If selected simulator does not exist, cli will try to run fallback simulators in following order:
126-
127-
- `iPhone 14`
128-
- `iPhone 13`
129-
- `iPhone 12`
130-
- `iPhone 11`
131-
132-
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).
133-
134-
Example: this will launch your project directly onto the iPhone 14 simulator:
135-
136-
```sh
137-
npx react-native build-ios --simulator "iPhone 14"
138-
```
139-
140129
#### `--mode <string>`
141130

142131
Explicitly set the scheme configuration to use. This option is case sensitive.
@@ -155,28 +144,10 @@ Explicitly set Xcode scheme to use.
155144

156145
Explicitly set Xcode target to use.
157146

158-
#### `--device [string]`
159-
160-
Explicitly set device to use by name. The value is not required if you have a single device connected.
161-
162-
#### `--udid <string>`
163-
164-
Explicitly set device to use by udid.
165-
166-
#### `--no-packager`
167-
168-
Do not launch packager while building.
169-
170147
#### `--verbose`
171148

172149
Do not use `xcbeautify` or `xcpretty` even if installed.
173150

174-
#### `--port <number>`
175-
176-
Runs packager on specified port.
177-
178-
Default: `process.env.RCT_METRO_PORT || 8081`
179-
180151
#### `--xcconfig <string>`
181152

182153
Explicitly pass `xcconfig` options from the command line.
@@ -185,16 +156,6 @@ Explicitly pass `xcconfig` options from the command line.
185156

186157
Location for iOS build artifacts. Corresponds to Xcode's `-derivedDataPath`.
187158

188-
#### `--binary-path <path>`
189-
190-
Installs passed binary instead of building a fresh one.
191-
192-
#### `--list-devices`
193-
194-
> default: false
195-
196-
List all available iOS devices and simulators and let you choose one to run the app.
197-
198159
#### `--extra-params <string>`
199160

200161
Custom params that will be passed to `xcodebuild` command.
@@ -204,8 +165,6 @@ Example:
204165
npx react-native build-ios --extra-params "-jobs 4"
205166
```
206167

207-
### log-ios
208-
209168
### `log-ios`
210169

211170
Usage:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
export type BuildFlags = {
2+
mode?: string;
3+
target?: string;
4+
verbose?: boolean;
5+
scheme?: string;
6+
xcconfig?: string;
7+
buildFolder?: string;
8+
interactive?: boolean;
9+
destination?: string;
10+
extraParams?: string[];
11+
};
12+
13+
export const buildOptions = [
14+
{
15+
name: '--mode <string>',
16+
description:
17+
'Explicitly set the scheme configuration to use. This option is case sensitive.',
18+
},
19+
{
20+
name: '--scheme <string>',
21+
description: 'Explicitly set Xcode scheme to use',
22+
},
23+
{
24+
name: '--destination <string>',
25+
description: 'Explicitly extend destination e.g. "arch=x86_64"',
26+
},
27+
{
28+
name: '--verbose',
29+
description: 'Do not use xcbeautify or xcpretty even if installed',
30+
},
31+
{
32+
name: '--xcconfig [string]',
33+
description: 'Explicitly set xcconfig to use',
34+
},
35+
{
36+
name: '--buildFolder <string>',
37+
description:
38+
'Location for iOS build artifacts. Corresponds to Xcode\'s "-derivedDataPath".',
39+
},
40+
{
41+
name: '--extra-params <string>',
42+
description: 'Custom params that will be passed to xcodebuild command.',
43+
parse: (val: string) => val.split(' '),
44+
},
45+
{
46+
name: '--target <string>',
47+
description: 'Explicitly set Xcode target to use.',
48+
},
49+
{
50+
name: '--interactive',
51+
description:
52+
'Explicitly select which scheme and configuration to use before running a build',
53+
},
54+
];

packages/cli-platform-ios/src/commands/buildIOS/buildProject.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,12 @@ import {
1010
printRunDoctorTip,
1111
getLoader,
1212
} from '@react-native-community/cli-tools';
13-
14-
export type BuildFlags = {
15-
mode: string;
16-
target: string;
17-
verbose: boolean;
18-
xcconfig?: string;
19-
buildFolder?: string;
20-
interactive?: boolean;
21-
destination?: string;
22-
extraParams?: string[];
23-
};
13+
import type {BuildFlags} from './buildOptions';
2414

2515
export function buildProject(
2616
xcodeProject: IOSProjectInfo,
2717
udid: string | undefined,
18+
mode: string,
2819
scheme: string,
2920
args: BuildFlags,
3021
): Promise<string> {
@@ -35,13 +26,13 @@ export function buildProject(
3526
...(args.xcconfig ? ['-xcconfig', args.xcconfig] : []),
3627
...(args.buildFolder ? ['-derivedDataPath', args.buildFolder] : []),
3728
'-configuration',
38-
args.mode,
29+
mode,
3930
'-scheme',
4031
scheme,
4132
'-destination',
4233
(udid
4334
? `id=${udid}`
44-
: args.mode === 'Debug'
35+
: mode === 'Debug'
4536
? 'generic/platform=iOS Simulator'
4637
: 'generic/platform=iOS') +
4738
(args.destination ? ',' + args.destination : ''),
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import chalk from 'chalk';
2+
import {IOSProjectInfo} from '@react-native-community/cli-types';
3+
import {logger} from '@react-native-community/cli-tools';
4+
import {selectFromInteractiveMode} from '../../tools/selectFromInteractiveMode';
5+
import {getProjectInfo} from '../../tools/getProjectInfo';
6+
import {checkIfConfigurationExists} from '../../tools/checkIfConfigurationExists';
7+
import type {BuildFlags} from './buildOptions';
8+
import {getBuildConfigurationFromXcScheme} from '../../tools/getBuildConfigurationFromXcScheme';
9+
10+
export async function getConfiguration(
11+
xcodeProject: IOSProjectInfo,
12+
sourceDir: string,
13+
args: BuildFlags,
14+
) {
15+
const projectInfo = getProjectInfo();
16+
17+
if (args.mode) {
18+
checkIfConfigurationExists(projectInfo, args.mode);
19+
}
20+
21+
let scheme = args.scheme || projectInfo.schemes[0];
22+
let mode =
23+
args.mode ||
24+
getBuildConfigurationFromXcScheme(scheme, 'Debug', sourceDir, projectInfo);
25+
26+
if (args.interactive) {
27+
const selection = await selectFromInteractiveMode({
28+
scheme,
29+
mode,
30+
projectInfo,
31+
});
32+
33+
if (selection.scheme) {
34+
scheme = selection.scheme;
35+
}
36+
37+
if (selection.mode) {
38+
mode = selection.mode;
39+
}
40+
}
41+
42+
logger.info(
43+
`Found Xcode ${
44+
xcodeProject.isWorkspace ? 'workspace' : 'project'
45+
} "${chalk.bold(xcodeProject.name)}"`,
46+
);
47+
48+
return {scheme, mode};
49+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {IOSProjectConfig} from '@react-native-community/cli-types';
2+
import {CLIError} from '@react-native-community/cli-tools';
3+
4+
export function getXcodeProjectAndDir(
5+
iosProjectConfig: IOSProjectConfig | undefined,
6+
) {
7+
if (!iosProjectConfig) {
8+
throw new CLIError(
9+
'iOS project folder not found. Are you sure this is a React Native project?',
10+
);
11+
}
12+
13+
const {xcodeProject, sourceDir} = iosProjectConfig;
14+
15+
if (!xcodeProject) {
16+
throw new CLIError(
17+
`Could not find Xcode project files in "${sourceDir}" folder`,
18+
);
19+
}
20+
21+
return {xcodeProject, sourceDir};
22+
}

0 commit comments

Comments
 (0)