0
# CLI Commands
1
2
Complete command-line interface providing project initialization, configuration management, diagnostics, and maintenance tools. Commands are categorized as either project commands (requiring React Native project configuration) or detached commands (working standalone).
3
4
## Capabilities
5
6
### Project Commands
7
8
Commands that require a React Native project configuration and only work within a React Native project directory.
9
10
#### Config Command
11
12
Outputs the current CLI configuration as JSON for debugging and inspection.
13
14
```bash { .api }
15
npx react-native config [options]
16
17
Options:
18
--platform <platform> Output configuration for a specific platform (ios, android, etc.)
19
--verbose Increase logging verbosity
20
```
21
22
**Usage Examples:**
23
24
```bash
25
# Display full configuration
26
npx react-native config
27
28
# Display iOS-specific configuration
29
npx react-native config --platform ios
30
31
# Display Android-specific configuration
32
npx react-native config --platform android
33
```
34
35
#### Clean Command
36
37
Cleans the project by removing React Native related caches and modules to resolve build and dependency issues.
38
39
```bash { .api }
40
npx react-native clean [options]
41
42
Options:
43
--include <string> Comma-separated flag of caches to clear
44
--project-root <string> Root path to React Native project (default: current directory)
45
--verify-cache Whether to verify the cache (npm only)
46
--verbose Increase logging verbosity
47
```
48
49
**Supported cache types:**
50
- `metro`: Metro bundler cache
51
- `watchman`: Watchman file watching cache (macOS/Linux)
52
- `android`: Android build cache and gradle cache
53
- `cocoapods`: CocoaPods cache (macOS only)
54
- `yarn`: Yarn cache
55
- `npm`: npm cache
56
- `bun`: Bun cache
57
58
**Usage Examples:**
59
60
```bash
61
# Clean all caches
62
npx react-native clean
63
64
# Clean specific caches
65
npx react-native clean --include metro,android
66
67
# Clean with cache verification
68
npx react-native clean --verify-cache
69
70
# Clean from specific project root
71
npx react-native clean --project-root /path/to/project
72
```
73
74
#### Info Command
75
76
Displays system information including React Native version, platform tools, and development environment details.
77
78
```bash { .api }
79
npx react-native info [options]
80
81
Options:
82
--verbose Increase logging verbosity
83
```
84
85
**Usage Examples:**
86
87
```bash
88
# Display system information
89
npx react-native info
90
```
91
92
**Sample output includes:**
93
- React Native version and installation path
94
- Node.js version
95
- npm/Yarn version
96
- Platform-specific tools (Android SDK, Xcode, etc.)
97
- Development environment status
98
99
### Detached Commands
100
101
Commands that work without requiring a React Native project configuration and can be run from any directory.
102
103
#### Init Command
104
105
Initializes a new React Native project with the specified name and configuration options.
106
107
```bash { .api }
108
npx react-native init [projectName] [options]
109
110
Arguments:
111
projectName Name of the new React Native project (optional)
112
113
Options:
114
--version <string> React Native version to install in the template
115
--template <string> Uses a custom template (npm package name or path)
116
--pm <string> Use specific package manager (yarn, npm, bun). Default: npm
117
--directory <string> Uses a custom directory instead of <projectName>
118
--title <string> Uses a custom app title name for application
119
--skip-install Skips dependencies installation step
120
--install-pods [boolean] Determine if CocoaPods should be installed (iOS)
121
--package-name <string> Custom package name (Android) and bundle ID (iOS)
122
--platform-name <string> Name of out of tree platform (e.g., react-native-macos)
123
--skip-git-init Skip git repository initialization
124
--replace-directory [boolean] Replaces the directory if it already exists
125
--yarn-config-options <string> Extra options for .yarnrc.yml file (key=value,key2=value2)
126
--verbose Increase logging verbosity
127
```
128
129
**Usage Examples:**
130
131
```bash
132
# Create new project with default settings
133
npx react-native init MyApp
134
135
# Create project with TypeScript template
136
npx react-native init MyApp --template react-native-template-typescript
137
138
# Create project with specific React Native version
139
npx react-native init MyApp --version 0.72.0
140
141
# Create project with custom package name
142
npx react-native init MyApp --package-name com.company.myapp
143
144
# Create project with Yarn
145
npx react-native init MyApp --pm yarn
146
147
# Create project without installing dependencies
148
npx react-native init MyApp --skip-install
149
150
# Create project in custom directory
151
npx react-native init MyApp --directory my-custom-directory
152
153
# Create project for out-of-tree platform
154
npx react-native init MyApp --platform-name macos
155
156
# Replace existing directory
157
npx react-native init MyApp --replace-directory true
158
```
159
160
#### Doctor Command
161
162
Diagnoses and optionally fixes common Node.js, iOS, Android, and React Native development environment issues.
163
164
```bash { .api }
165
npx react-native doctor [options]
166
167
Options:
168
--fix Attempt to fix all diagnosed issues automatically
169
--contributor Add healthchecks for React Native contributors
170
--verbose Increase logging verbosity
171
```
172
173
**Usage Examples:**
174
175
```bash
176
# Run diagnostics only
177
npx react-native doctor
178
179
# Run diagnostics and attempt fixes
180
npx react-native doctor --fix
181
182
# Include contributor-specific checks
183
npx react-native doctor --contributor
184
```
185
186
**Diagnostic checks include:**
187
- Node.js version compatibility
188
- Android development environment (SDK, tools, paths)
189
- iOS development environment (Xcode, simulators, CocoaPods)
190
- Common configuration issues
191
- Development server accessibility
192
193
## Command Architecture
194
195
### Command Registration
196
197
Commands are automatically registered with the following features:
198
199
- **Error Handling**: Automatic error catching and user-friendly error messages
200
- **Verbose Logging**: Optional detailed logging with `--verbose` flag
201
- **Help Generation**: Automatic help text with examples and option descriptions
202
- **Option Parsing**: Type-safe option parsing and validation
203
204
### Command Types
205
206
```typescript { .api }
207
type ProjectCommand = {
208
name: "config" | "clean" | "info";
209
detached: false;
210
requiresProject: true;
211
};
212
213
type DetachedCommand = {
214
name: "init" | "doctor";
215
detached: true;
216
requiresProject: false;
217
};
218
```
219
220
### Global Options
221
222
All commands support these global options:
223
224
- `--verbose`: Increase logging verbosity for debugging
225
- `--help`: Display command-specific help information
226
- `--version`: Display CLI version (when used without command)