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

refactor: extract cli-config-apple for linking #2536

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 31 additions & 0 deletions packages/cli-config-apple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# @react-native-community/cli-config-apple

This package is part of the [React Native CLI](../../README.md). It contains utilities for building reusable commands targeting Apple platforms.

## Installation

```sh
yarn add @react-native-community/cli-config-apple
```

## Usage

This package is intended to be used internally in [React Native CLI](../../README.md) and by out of tree platforms.

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

- `getProjectConfig()` - creates project config for given platform
- `getDependencyConfig()` - 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: getDependencyConfig({platformName: 'visionos'}),
},
..
},
```
32 changes: 32 additions & 0 deletions packages/cli-config-apple/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@react-native-community/cli-config-apple",
"version": "15.0.0",
"license": "MIT",
"main": "build/index.js",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@react-native-community/cli-tools": "15.0.0",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"fast-glob": "^3.3.2"
},
"devDependencies": {
"@react-native-community/cli-types": "15.0.0",
"@types/lodash": "^4.14.149",
thymikee marked this conversation as resolved.
Show resolved Hide resolved
"hasbin": "^1.2.3",
"ora": "^5.4.1"
},
"files": [
"build",
"!*.d.ts",
"!*.map"
],
"homepage": "https://github.com/react-native-community/cli/tree/main/packages/cli-config-apple",
"repository": {
"type": "git",
"url": "https://github.com/react-native-community/cli.git",
"directory": "packages/cli-config-apple"
}
}
11 changes: 11 additions & 0 deletions packages/cli-config-apple/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export {
getDependencyConfig,
getProjectConfig,
findPodfilePaths,
} from './config';

export {default as installPods} from './tools/installPods';
export {default as resolvePods} from './tools/pods';
export {default as findXcodeProject} from './config/findXcodeProject';
export {default as findPbxprojFile} from './config/findPbxprojFile';
export {supportedPlatforms} from './config/supportedPlatforms';
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface NativeDependencies {
[key: string]: DependencyConfig;
}

export function getPackageJson(root: string) {
function getPackageJson(root: string) {
try {
return require(path.join(root, 'package.json'));
} catch {
Expand Down
13 changes: 13 additions & 0 deletions packages/cli-config-apple/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {supportedPlatforms} from './config/supportedPlatforms';

type ObjectValues<T> = T[keyof T];

export type ApplePlatform = ObjectValues<typeof supportedPlatforms>;

export interface BuilderCommand {
/**
* Lowercase name of the platform.
* Example: 'ios', 'visionos'
*/
platformName: ApplePlatform;
}
8 changes: 8 additions & 0 deletions packages/cli-config-apple/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
},
"references": [{"path": "../cli-tools"}, {"path": "../cli-types"}]
}
5 changes: 2 additions & 3 deletions packages/cli-platform-apple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
"access": "public"
},
"dependencies": {
"@react-native-community/cli-config-apple": "15.0.0",
"@react-native-community/cli-tools": "15.0.0",
"chalk": "^4.1.2",
"execa": "^5.0.0",
"fast-glob": "^3.3.2",
"fast-xml-parser": "^4.4.1",
"ora": "^5.4.1"
"fast-xml-parser": "^4.4.1"
},
"devDependencies": {
"@react-native-community/cli-types": "15.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@react-native-community/cli-tools';
import type {BuildFlags} from './buildOptions';
import {simulatorDestinationMap} from './simulatorDestinationMap';
import {supportedPlatforms} from '../../config/supportedPlatforms';
import {supportedPlatforms} from '@react-native-community/cli-config-apple';
import {ApplePlatform} from '../../types';

function prettifyXcodebuildMessages(output: string): Set<string> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {CLIError} from '@react-native-community/cli-tools';
import {Config, IOSProjectConfig} from '@react-native-community/cli-types';
import getArchitecture from '../../tools/getArchitecture';
import resolvePods from '../../tools/pods';
import {BuildFlags} from './buildOptions';
import {buildProject} from './buildProject';
import {getConfiguration} from './getConfiguration';
import {getXcodeProjectAndDir} from './getXcodeProjectAndDir';
import {BuilderCommand} from '../../types';
import {supportedPlatforms} from '../../config/supportedPlatforms';
import {
supportedPlatforms,
resolvePods,
} from '@react-native-community/cli-config-apple';

const createBuild =
({platformName}: BuilderCommand) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import {IOSProjectConfig} from '@react-native-community/cli-types';
import {CLIError} from '@react-native-community/cli-tools';
import findXcodeProject from '../../config/findXcodeProject';
import {findXcodeProject} from '@react-native-community/cli-config-apple';
import {getPlatformInfo} from '../runCommand/getPlatformInfo';
import {ApplePlatform} from '../../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from 'path';
import listDevices from '../../tools/listDevices';
import {getPlatformInfo} from '../runCommand/getPlatformInfo';
import {BuilderCommand, Device} from '../../types';
import {supportedPlatforms} from '../../config/supportedPlatforms';
import {supportedPlatforms} from '@react-native-community/cli-config-apple';
import {promptForDeviceToTailLogs} from '../../tools/prompts';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '@react-native-community/cli-tools';
import getArchitecture from '../../tools/getArchitecture';
import listDevices from '../../tools/listDevices';
import resolvePods, {getPackageJson} from '../../tools/pods';
import {promptForDeviceSelection} from '../../tools/prompts';
import {BuildFlags} from '../buildCommand/buildOptions';
import {buildProject} from '../buildCommand/buildProject';
Expand All @@ -32,7 +31,10 @@ import {printFoundDevices, matchingDevice} from './matchingDevice';
import {runOnDevice} from './runOnDevice';
import {runOnSimulator} from './runOnSimulator';
import {BuilderCommand} from '../../types';
import {supportedPlatforms} from '../../config/supportedPlatforms';
import {
supportedPlatforms,
resolvePods,
} from '@react-native-community/cli-config-apple';
import openApp from './openApp';

export interface FlagsT extends BuildFlags {
Expand All @@ -46,6 +48,16 @@ export interface FlagsT extends BuildFlags {
terminal?: string;
}

function getPackageJson(root: string) {
try {
return require(path.join(root, 'package.json'));
} catch {
throw new CLIError(
'No package.json found. Please make sure the file exists in the current folder.',
);
}
}

const createRun =
({platformName}: BuilderCommand) =>
async (_: Array<string>, ctx: Config, args: FlagsT) => {
Expand Down
9 changes: 4 additions & 5 deletions packages/cli-platform-apple/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ export {
getDependencyConfig,
getProjectConfig,
findPodfilePaths,
} from './config';
installPods,
findXcodeProject,
findPbxprojFile,
} from '@react-native-community/cli-config-apple';

export {getBuildOptions} from './commands/buildCommand/buildOptions';
export {getLogOptions} from './commands/logCommand/logOptions';
Expand All @@ -13,7 +16,3 @@ export {default as createLog} from './commands/logCommand/createLog';
export {default as createRun} from './commands/runCommand/createRun';

export {default as getArchitecture} from './tools/getArchitecture';
export {default as installPods} from './tools/installPods';

export {default as findXcodeProject} from './config/findXcodeProject';
export {default as findPbxprojFile} from './config/findPbxprojFile';
2 changes: 1 addition & 1 deletion packages/cli-platform-apple/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {supportedPlatforms} from './config/supportedPlatforms';
import {supportedPlatforms} from '@react-native-community/cli-config-apple';

type ObjectValues<T> = T[keyof T];

Expand Down
8 changes: 6 additions & 2 deletions packages/cli-platform-apple/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"outDir": "build"
},
"references": [{"path": "../cli-tools"}, {"path": "../cli-types"}]
"references": [
{"path": "../cli-tools"},
{"path": "../cli-types"},
{"path": "../cli-config-apple"}
]
}
Loading