Skip to content
Open
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
42 changes: 42 additions & 0 deletions packages/community-cli-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,48 @@ npx @react-native-community/cli bundle --entry-file <path> [options]
| `--read-global-cache` | Attempt to fetch transformed JS code from the global cache, if configured. Defaults to `false`. |
| `--config <string>` | Path to the CLI configuration file. |

### `codegen`

Run the React Native codegen, generating native boilerplate from JS spec files.

#### Usage

```sh
npx @react-native-community/cli codegen [options]
```

#### Options

| Option | Description |
| - | - |
| `--path <path>` | Path to the React Native project root. Defaults to the current working directory. |
| `--platform <string>` | Target platform. Supported values: `"android"`, `"ios"`, `"all"`. Defaults to `"all"`. |
| `--outputPath <path>` | Path where generated artifacts will be output to. |
| `--source <string>` | Whether the script is invoked from an `app` or a `library`. Defaults to `"app"`. |

### `spm [action]`

Set up or maintain Swift Package Manager support for the iOS/macOS app. Actions: `add`, `update`, `deinit`, `scaffold`. With no action: `add` (or `update` if SPM is already set up).

#### Usage

```sh
npx @react-native-community/cli spm [action] [options]
```

#### Options

| Option | Description |
| - | - |
| `--version <string>` | React Native version (e.g. `0.80.0`). Defaults to the version in `node_modules/react-native/package.json`. |
| `--yes` | Skip the dirty-pbxproj confirmation prompt. |
| `--xcodeproj <path>` | **[add]** Path to the `.xcodeproj` to inject SPM packages into (disambiguates when several exist). |
| `--productName <string>` | **[add]** App target to inject into (disambiguates when several exist). |
| `--deintegrate` | **[add]** Run `pod deintegrate` and strip React Native from the Podfile before injecting (CocoaPods → SwiftPM migration). |
| `--artifacts <path>` | **[advanced]** Local artifact root containing complete `debug/` and `release/` slots. |
| `--download <string>` | **[advanced]** Artifact download policy: `auto` (default), `skip`, or `force`. |
| `--skipCodegen` | **[advanced]** Skip the react-native codegen step. |

## Contributing

Changes to this package can be made locally and tested against the `rn-tester` app, per the [Contributing guide](https://reactnative.dev/contributing/overview#contributing-code). During development, this package is automatically run from source with no build step.
63 changes: 63 additions & 0 deletions packages/community-cli-plugin/src/commands/codegen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

import type {Command, Config} from '@react-native-community/cli-types';

export type CodegenCommandArgs = {
path: string,
platform: string,
outputPath?: string,
source: string,
};

const codegenCommand: Command = {
name: 'codegen',
options: [
{
name: '--path <path>',
description: 'Path to the React Native project root.',
default: process.cwd(),
},
{
name: '--platform <string>',
description:
'Target platform. Supported values: "android", "ios", "all".',
default: 'all',
},
{
name: '--outputPath <path>',
description: 'Path where generated artifacts will be output to.',
},
{
name: '--source <string>',
description: 'Whether the script is invoked from an `app` or a `library`',
default: 'app',
},
],
func: (
argv: Array<string>,
config: Config,
args: CodegenCommandArgs,
): void => {
const generateArtifactsExecutor = require.resolve(
'react-native/scripts/codegen/generate-artifacts-executor',
{paths: [config.root]},
);
// $FlowFixMe[unsupported-syntax] dynamic require of a resolved path
require(generateArtifactsExecutor).execute(
args.path,
args.platform,
args.outputPath,
args.source,
);
},
};

export default codegenCommand;
118 changes: 118 additions & 0 deletions packages/community-cli-plugin/src/commands/spm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

import type {Command, Config} from '@react-native-community/cli-types';

export type SpmCommandArgs = {
version?: string,
yes?: boolean,
xcodeproj?: string,
productName?: string,
deintegrate?: boolean,
artifacts?: string,
download?: string,
skipCodegen?: boolean,
};

const spmCommand: Command = {
name: 'spm [action]',
description:
'Set up or maintain Swift Package Manager support for the iOS/macOS app. ' +
'Actions: add, update, deinit, scaffold. With no action: add (or update ' +
'if SPM is already set up).',
options: [
{
name: '--version <string>',
description:
'React Native version (e.g. 0.80.0). Defaults to the version in node_modules/react-native/package.json.',
},
{
name: '--yes',
description: 'Skip the dirty-pbxproj confirmation prompt.',
},
{
name: '--xcodeproj <path>',
description:
'[add] Path to the .xcodeproj to inject SPM packages into ' +
'(disambiguates when several exist).',
},
{
name: '--productName <string>',
description:
'[add] App target to inject into (disambiguates when several exist).',
},
{
name: '--deintegrate',
description:
'[add] Run `pod deintegrate` and strip React Native from the Podfile ' +
'before injecting (CocoaPods → SwiftPM migration).',
},
{
name: '--artifacts <path>',
description:
'[advanced] Local artifact root containing complete debug/ and release/ slots.',
},
{
name: '--download <string>',
description:
'[advanced] Artifact download policy: auto (default), skip, or force.',
},
{
name: '--skipCodegen',
description: '[advanced] Skip the react-native codegen step.',
},
],
func: async (
argv: Array<string>,
config: Config,
args: SpmCommandArgs,
): Promise<void> => {
const passthrough: Array<string> = [];
if (argv[0] != null) {
passthrough.push(argv[0]);
}
const stringOpts: Array<
[
'version' | 'productName' | 'xcodeproj' | 'artifacts' | 'download',
string,
],
> = [
['version', '--version'],
['productName', '--product-name'],
['xcodeproj', '--xcodeproj'],
['artifacts', '--artifacts'],
['download', '--download'],
];
for (const [key, flag] of stringOpts) {
const value = args[key];
if (value != null) {
passthrough.push(flag, String(value));
}
}
const boolOpts: Array<['skipCodegen' | 'deintegrate' | 'yes', string]> = [
['skipCodegen', '--skip-codegen'],
['deintegrate', '--deintegrate'],
['yes', '--yes'],
];
for (const [key, flag] of boolOpts) {
if (args[key] === true) {
passthrough.push(flag);
}
}
const setupAppleSpm = require.resolve(
'react-native/scripts/setup-apple-spm',
{paths: [config.root]},
);
// $FlowFixMe[unsupported-syntax] dynamic require of a resolved path
await require(setupAppleSpm).main(passthrough);
},
};

export default spmCommand;
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@

import type {Command} from '@react-native-community/cli-types';

import runServer from './runServer';
import runDevServer from '../dev-server/runDevServer';
import path from 'node:path';

export type {StartCommandArgs} from './runServer';

const startCommand: Command = {
name: 'start',
func: runServer,
func: runDevServer,
description: 'Start the React Native development server.',
options: [
{
Expand Down
96 changes: 0 additions & 96 deletions packages/community-cli-plugin/src/commands/start/middleware.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default async function isDevServerRunning(
return 'not_running';
}

// FIXME: Depends on @react-native-community/cli-server-api
const statusResponse = await fetch(`${devServerUrl}/status`);
const body = await statusResponse.text();

Expand Down
Loading
Loading