Skip to content

Commit

Permalink
refactor(iOS): remove unintended flags from build-ios (#2078)
Browse files Browse the repository at this point in the history
* refactor(iOS): remove unintended flags from build-ios

* test: update snapshot

* docs: move binary-path and list-devices to run-ios
  • Loading branch information
thymikee committed Sep 20, 2023
1 parent 4fac063 commit 520c90f
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 432 deletions.
2 changes: 1 addition & 1 deletion __e2e__/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
"<<REPLACED>>"
],
Expand Down
63 changes: 11 additions & 52 deletions packages/cli-platform-ios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ Example:
npx react-native run-ios --extra-params "-jobs 4"
```

#### `--binary-path <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:
Expand All @@ -112,31 +122,10 @@ Usage:
npx react-native build-ios [options]
```

Builds IOS app.
Builds iOS app.

#### Options

#### `--simulator <simulator_name>`

> 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 <string>`

Explicitly set the scheme configuration to use. This option is case sensitive.
Expand All @@ -155,28 +144,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 <string>`

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 <number>`

Runs packager on specified port.

Default: `process.env.RCT_METRO_PORT || 8081`

#### `--xcconfig <string>`

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

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

#### `--binary-path <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 <string>`

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

### log-ios

### `log-ios`

Usage:
Expand Down
54 changes: 54 additions & 0 deletions packages/cli-platform-ios/src/commands/buildIOS/buildOptions.ts
Original file line number Diff line number Diff line change
@@ -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 <string>',
description:
'Explicitly set the scheme configuration to use. This option is case sensitive.',
},
{
name: '--scheme <string>',
description: 'Explicitly set Xcode scheme to use',
},
{
name: '--destination <string>',
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 <string>',
description:
'Location for iOS build artifacts. Corresponds to Xcode\'s "-derivedDataPath".',
},
{
name: '--extra-params <string>',
description: 'Custom params that will be passed to xcodebuild command.',
parse: (val: string) => val.split(' '),
},
{
name: '--target <string>',
description: 'Explicitly set Xcode target to use.',
},
{
name: '--interactive',
description:
'Explicitly select which scheme and configuration to use before running a build',
},
];
17 changes: 4 additions & 13 deletions packages/cli-platform-ios/src/commands/buildIOS/buildProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
Expand All @@ -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 : ''),
Expand Down
Original file line number Diff line number Diff line change
@@ -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};
}
Original file line number Diff line number Diff line change
@@ -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};
}
Loading

0 comments on commit 520c90f

Please sign in to comment.