Command line tools to interact with React Native projects
npx @tessl/cli install tessl/npm-react-native-community--cli@20.0.00
# React Native CLI
1
2
React Native CLI is the official command-line interface for React Native development. It provides essential commands for project initialization, configuration management, debugging, and development workflow automation. The CLI serves as both a programmatic API and a comprehensive set of command-line tools that handle the complete React Native development lifecycle.
3
4
## Package Information
5
6
- **Package Name**: @react-native-community/cli
7
- **Package Type**: npm
8
- **Language**: TypeScript
9
- **Installation**: `npm install @react-native-community/cli`
10
11
## Core Imports
12
13
```typescript
14
import { run, loadConfig, loadConfigAsync, createDevServerMiddleware, bin } from "@react-native-community/cli";
15
```
16
17
For CommonJS:
18
19
```javascript
20
const { run, loadConfig, loadConfigAsync, createDevServerMiddleware, bin } = require("@react-native-community/cli");
21
```
22
23
## Basic Usage
24
25
### Programmatic Usage
26
27
```typescript
28
import { run, loadConfigAsync } from "@react-native-community/cli";
29
30
// Load React Native project configuration
31
const config = await loadConfigAsync();
32
console.log("Project root:", config.root);
33
console.log("Available platforms:", Object.keys(config.platforms));
34
35
// Run CLI programmatically (typically not needed)
36
await run();
37
```
38
39
### Command Line Usage
40
41
```bash
42
# Initialize a new React Native project
43
npx react-native init MyApp
44
45
# Get project information
46
npx react-native info
47
48
# Clean project caches
49
npx react-native clean
50
51
# Display current configuration
52
npx react-native config
53
54
# Run diagnostics and fix issues
55
npx react-native doctor
56
```
57
58
## Architecture
59
60
The React Native CLI is built around several key components:
61
62
- **Command System**: Unified command registration using Commander.js with automatic error handling
63
- **Configuration Loading**: Async/sync configuration discovery and loading from React Native projects
64
- **Plugin Architecture**: Extensible command system through external packages and project configuration
65
- **Multi-Platform Support**: Android, iOS, and out-of-tree platform support with conditional command availability
66
- **Development Integration**: Metro bundler middleware and development server integration
67
68
## Capabilities
69
70
### Main API Functions
71
72
Core programmatic interface for running the CLI, loading configurations, and integrating with development tools.
73
74
```typescript { .api }
75
function run(platformName?: string): Promise<void>;
76
function loadConfig(): Config;
77
function loadConfigAsync(options?: {selectedPlatform?: string}): Promise<Config>;
78
function createDevServerMiddleware(options: MiddlewareOptions): DevServerMiddleware;
79
```
80
81
[Main API Functions](./main-api.md)
82
83
### CLI Commands
84
85
Complete command-line interface providing project initialization, configuration management, diagnostics, and maintenance tools.
86
87
```typescript { .api }
88
// Project Commands (require React Native project)
89
type ProjectCommand = "config" | "clean" | "info";
90
91
// Detached Commands (work standalone)
92
type DetachedCommand = "init" | "doctor";
93
```
94
95
[CLI Commands](./cli-commands.md)
96
97
### TypeScript Types
98
99
Comprehensive type system covering CLI configuration, commands, platform definitions, and development tool integration.
100
101
```typescript { .api }
102
interface Config {
103
root: string;
104
reactNativePath: string;
105
platforms: Record<string, PlatformConfig>;
106
commands: Command[];
107
dependencies: Record<string, DependencyConfig>;
108
}
109
110
interface Command<IsDetached extends boolean = boolean> {
111
name: string;
112
description?: string;
113
func: IsDetached extends true ? DetachedCommandFunction : CommandFunction;
114
detached?: IsDetached;
115
options?: CommandOption[];
116
examples?: Array<{desc: string; cmd: string}>;
117
}
118
```
119
120
[TypeScript Types](./typescript-types.md)