Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert command options and dependencyConfig into getters #2226

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/cli-platform-apple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Inside of `<oot-platform>/packages/react-native/react-native.config.js`:

```js
const {
buildOptions,
getBuildOptions,
createBuild,
} = require('@react-native-community/cli-platform-apple');

Expand All @@ -32,11 +32,29 @@ const buildVisionOS = {
cmd: 'npx react-native build-visionos --mode "Release"',
},
],
options: buildOptions,
options: getBuildOptions({platformName: 'visionos'}),
};

module.exports = {
commands: [buildVisionOS], // <- Add command here
//..
};
```

`cli-platform-apple` also exports utilities to create OOT platform config.

- `getProjectConfig()` - creates project config for given platform
- `getDependencyConfg()` - creates dependency config for given platform

Example (`<oot-platform>/packages/react-native/react-native.config.js`):

```js
platforms: {
visionos: {
npmPackageName: '@callstack/react-native-visionos',
projectConfig: getProjectConfig({platformName: 'visionos'}),
dependencyConfig: getDependencyConfg({platformName: 'visionos'}),
},
..
},
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {BuilderCommand} from '../../types';
import {getPlatformInfo} from '../runCommand/getPlatformInfo';

export type BuildFlags = {
mode?: string;
target?: string;
Expand All @@ -11,49 +14,51 @@ export type BuildFlags = {
forcePods?: boolean;
};

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',
},
{
name: '--force-pods',
description: 'Force CocoaPods installation',
},
];
export const getBuildOptions = ({platformName}: BuilderCommand) => {
const {readableName} = getPlatformInfo(platformName);
return [
{
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 ${readableName} 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',
},
{
name: '--force-pods',
description: 'Force CocoaPods installation',
},
];
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const logOptions = [
import {BuilderCommand} from '../../types';

export const getLogOptions = ({}: BuilderCommand) => [
{
name: '--interactive',
description:
Expand Down
97 changes: 51 additions & 46 deletions packages/cli-platform-apple/src/commands/runCommand/runOptions.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
import {getDefaultUserTerminal} from '@react-native-community/cli-tools';
import {buildOptions} from '../buildCommand/buildOptions';
import {BuilderCommand} from '../../types';
import {getPlatformInfo} from './getPlatformInfo';
import {getBuildOptions} from '../buildCommand/buildOptions';

export const runOptions = [
{
name: '--no-packager',
description: 'Do not launch packager while running the app',
},
{
name: '--port <number>',
default: process.env.RCT_METRO_PORT || 8081,
parse: Number,
},
{
name: '--terminal <string>',
description:
'Launches the Metro Bundler in a new window using the specified terminal path.',
default: getDefaultUserTerminal(),
},
{
name: '--binary-path <string>',
description:
'Path relative to project root where pre-built .app binary lives.',
},
{
name: '--list-devices',
description:
'List all available iOS devices and simulators and let you choose one to run the app. ',
},
{
name: '--simulator <string>',
description:
'Explicitly set the simulator to use. Optionally set the iOS version ' +
'between parentheses at the end to match an exact version: ' +
'"iPhone 15 (17.0)"',
},
{
name: '--device <string>',
description:
'Explicitly set the device to use by name. The value is not required ' +
'if you have a single device connected.',
},
{
name: '--udid <string>',
description: 'Explicitly set the device to use by UDID',
},
...buildOptions,
];
export const getRunOptions = ({platformName}: BuilderCommand) => {
const {readableName} = getPlatformInfo(platformName);
const isMac = platformName === 'macos';
return [
{
name: '--no-packager',
description: 'Do not launch packager while running the app',
},
{
name: '--port <number>',
default: process.env.RCT_METRO_PORT || 8081,
parse: Number,
},
{
name: '--terminal <string>',
description:
'Launches the Metro Bundler in a new window using the specified terminal path.',
default: getDefaultUserTerminal(),
},
{
name: '--binary-path <string>',
description:
'Path relative to project root where pre-built .app binary lives.',
},
{
name: '--list-devices',
description: `List all available ${readableName} devices and simulators and let you choose one to run the app. `,
},
{
name: '--udid <string>',
description: 'Explicitly set the device to use by UDID',
},
!isMac && {
name: '--simulator <string>',
description:
`Explicitly set the simulator to use. Optionally set the ${readableName} version ` +
'between parentheses at the end to match an exact version: ' +
'"iPhone 15 (17.0)"',
},
!isMac && {
name: '--device <string>',
description:
'Explicitly set the device to use by name. The value is not required ' +
'if you have a single device connected.',
},
...getBuildOptions({platformName}),
];
};
63 changes: 34 additions & 29 deletions packages/cli-platform-apple/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,42 +55,47 @@ export const getProjectConfig =
};
};

export function dependencyConfig(
folder: string,
userConfig: IOSDependencyParams | null = {},
): IOSDependencyConfig | null {
if (userConfig === null) {
return null;
}
/**
* Make getDependencyConfig follow the same pattern as getProjectConfig
*/
export const getDependencyConfig =
({}: BuilderCommand) =>
(
folder: string,
userConfig: IOSDependencyParams | null = {},
): IOSDependencyConfig | null => {
if (userConfig === null) {
return null;
}

const podspecPath = findPodspec(folder);
const podspecPath = findPodspec(folder);

if (!podspecPath) {
return null;
}
if (!podspecPath) {
return null;
}

let version = 'unresolved';
let version = 'unresolved';

try {
const packageJson = require(path.join(folder, 'package.json'));
try {
const packageJson = require(path.join(folder, 'package.json'));

if (packageJson.version) {
version = packageJson.version;
if (packageJson.version) {
version = packageJson.version;
}
} catch {
throw new CLIError(
`Failed to locate package.json file from ${chalk.underline(
folder,
)}. This is most likely issue with your node_modules folder being corrupted. Please force install dependencies and try again`,
);
}
} catch {
throw new CLIError(
`Failed to locate package.json file from ${chalk.underline(
folder,
)}. This is most likely issue with your node_modules folder being corrupted. Please force install dependencies and try again`,
);
}

return {
podspecPath,
version,
configurations: userConfig.configurations || [],
scriptPhases: userConfig.scriptPhases || [],
return {
podspecPath,
version,
configurations: userConfig.configurations || [],
scriptPhases: userConfig.scriptPhases || [],
};
};
}

export const findPodfilePaths = findAllPodfilePaths;
12 changes: 8 additions & 4 deletions packages/cli-platform-apple/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export {dependencyConfig, getProjectConfig, findPodfilePaths} from './config';
export {
getDependencyConfig,
getProjectConfig,
findPodfilePaths,
} from './config';

export {buildOptions} from './commands/buildCommand/buildOptions';
export {logOptions} from './commands/logCommand/logOptions';
export {runOptions} from './commands/runCommand/runOptions';
export {getBuildOptions} from './commands/buildCommand/buildOptions';
export {getLogOptions} from './commands/logCommand/logOptions';
export {getRunOptions} from './commands/runCommand/runOptions';

export {default as createBuild} from './commands/buildCommand/createBuild';
export {default as createLog} from './commands/logCommand/createLog';
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-platform-ios/src/commands/buildIOS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import {
buildOptions,
getBuildOptions,
createBuild,
} from '@react-native-community/cli-platform-apple';

Expand All @@ -21,5 +21,5 @@ export default {
cmd: 'npx react-native build-ios --mode "Release"',
},
],
options: buildOptions,
options: getBuildOptions({platformName: 'ios'}),
};
4 changes: 2 additions & 2 deletions packages/cli-platform-ios/src/commands/logIOS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import {
createLog,
logOptions,
getLogOptions,
} from '@react-native-community/cli-platform-apple';

export default {
name: 'log-ios',
description: 'starts iOS device syslog tail',
func: createLog({platformName: 'ios'}),
options: logOptions,
options: getLogOptions({platformName: 'ios'}),
};
4 changes: 2 additions & 2 deletions packages/cli-platform-ios/src/commands/runIOS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import {
createRun,
runOptions,
getRunOptions,
} from '@react-native-community/cli-platform-apple';

export default {
Expand All @@ -29,5 +29,5 @@ export default {
cmd: 'npx react-native run-ios --simulator "Apple TV" --scheme "helloworld-tvOS"',
},
],
options: runOptions,
options: getRunOptions({platformName: 'ios'}),
};
Loading