Skip to content

Commit 8a2f48d

Browse files
Overhaul RNW CLI documentation (#947)
## Description This PR does multiple things in order to improve the RNW CLI documentation, including: * Creating separate pages for each CLI command * Updating existing documentation to point to these new pages where appropriate * Updated Getting Started to use the new `init-windows` command * Updated other references to the old `react-native-windows-init` command with links to the new command and changed functionality * Clarified references where we used "React Native Windows CLI" as a generic term when we mean specific commands within the CLI ### Why To improve out documentation in time for the 0.75 release. Resolves microsoft/react-native-windows#13394 ## Screenshots N/A Co-authored-by: Tatiana Kapos <[email protected]>
1 parent 854904c commit 8a2f48d

20 files changed

+258
-87
lines changed

.spelling

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
accessors
33
APIs
44
Appium
5+
autolink
6+
autolink-windows
57
autolinked
68
autolinking
79
bool
@@ -14,6 +16,7 @@ Chakra
1416
changelog
1517
CocoaPods
1618
codegen
19+
codegen-windows
1720
comboboxes
1821
config
1922
configJson
@@ -35,11 +38,12 @@ functor
3538
HomeBrew
3639
hostname
3740
i.e.
41+
init-windows
3842
initializer
3943
interop
4044
iOS
41-
KeyEvents
4245
ItemGroup
46+
KeyEvents
4347
lifecycle
4448
macOS
4549
middleware
@@ -72,6 +76,7 @@ repo
7276
repos
7377
RNW-on-WinUI
7478
roadmap
79+
run-windows
7580
runtime
7681
runtimes
7782
schemas

docs/autolink-windows-cli.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
id: autolink-windows-cli
3+
title: react-native autolink-windows
4+
---
5+
6+
This guide will give you more information on the `autolink-windows` command of the React Native Windows CLI.
7+
8+
## `autolink-windows`
9+
10+
The `autolink-windows` CLI command is used to link the native code and build systems for a React Native for Windows app with any native community modules it uses.
11+
12+
**Note:** Autolinking runs automatically as part of running the [run-windows command](run-windows-cli.md), unless the `--no-autolink` argument is used.
13+
14+
### Usage
15+
Runs Windows-specific autolinking for your RNW project.
16+
17+
```bat
18+
npx react-native autolink-windows
19+
```
20+
### Options
21+
22+
Here are the options that `react-native autolink-windows` takes:
23+
| Option | Input Type | Description |
24+
|-----------------------|------------|--------------------------------------------------|
25+
| `--logging` | boolean | Verbose output logging |
26+
| `--check` | boolean | Only check whether any autolinked files need to change |
27+
| `--sln` | string | Override the app solution file determined by 'react-native config', i.e. `windows\myApp.sln` |
28+
| `--proj` | string | Override the app project file determined by 'react-native config', i.e. `windows\myApp\myApp.vcxproj` |
29+
| `--no-telemetry` | boolean | Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI |
30+
| `-h`, `--help` | boolean | Display help for command |
31+
32+
This sends telemetry to Microsoft by default. You can prevent the telemetry from being sent by using the `--no-telemetry` command line option. See below for more details.
33+
34+
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
35+
36+
This data collection notice only applies to the process of running the react-native-windows CLI commands.
37+

docs/codegen-windows-cli.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
id: codegen-windows-cli
3+
title: react-native codegen-windows
4+
---
5+
6+
This guide will give you more information on the `codegen-windows` command of the React Native Windows CLI.
7+
8+
## `codegen-windows`
9+
10+
The `codegen-windows` CLI command is used to generate some necessary Windows-specific native code for native modules.
11+
12+
### Usage
13+
Runs Windows-specific codegen for native modules.
14+
15+
```bat
16+
npx react-native codegen-windows
17+
```
18+
### Options
19+
20+
Here are the options that `react-native codegen-windows` takes:
21+
| Option | Input Type | Description |
22+
|-----------------------|------------|--------------------------------------------------|
23+
| `--logging` | boolean | Verbose output logging |
24+
| `--check` | boolean | Only check whether any codegen files need to change |
25+
| `--no-telemetry` | boolean | Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI |
26+
| `-h`, `--help` | boolean | Display help for command |
27+
28+
This sends telemetry to Microsoft by default. You can prevent the telemetry from being sent by using the `--no-telemetry` command line option. See below for more details.
29+
30+
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
31+
32+
This data collection notice only applies to the process of running the react-native-windows CLI commands.
33+

docs/debugging-javascript.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ InstanceSettings.UseDirectDebugger = true;
6363

6464
2. Then simply re-build and launch your RNW app as usual.
6565

66-
> For a new RNW app created using `react-native-windows-init`, `UseDirectDebugger` defaults to `false`.
66+
> For a new RNW app `UseDirectDebugger` defaults to `true` for Debug builds, and `false` for Release builds.
6767
6868
#### Option 2: Using the Developer Menu
6969

@@ -127,7 +127,7 @@ You can direct debug RNW apps using the (default) Chakra JS engine with [Visual
127127
2. For C# RNW apps, open the *Debug* tab, set the *Debugger type > Application process* to *Script*, then close the properties
128128
4. Click on *Debug* in the menu bar and select *Start Debugging*
129129
4. **Option B:** Attach Visual Studio to the app that's already running
130-
1. Make sure that your native app and Metro is already running (i.e. `npx react-native run-windows`)
130+
1. Make sure that your native app and Metro is already running (i.e. using the [run-windows command](run-windows-cli.md))
131131
2. Click on *Debug* in Visual Studio's menu bar and select *Attach to Process...*
132132
3. Find and select the native process for your app (not Metro)
133133
4. Make sure *Attach to:* is set to *Automatic: Script code* or *Script code*
@@ -154,7 +154,7 @@ You can direct debug RNW apps using the Hermes JS engine with [Visual Studio](ht
154154
> **Important:** Launching the app and starting direct debug with Hermes isn't supported in Visual Studio.
155155
156156
4. **Option B:** Attach Visual Studio to the app that's already running
157-
1. Make sure that your native app and Metro is already running (i.e. `npx react-native run-windows`)
157+
1. Make sure that your native app and Metro is already running (i.e. using the [run-windows command](run-windows-cli.md))
158158
2. Click on *Debug* in Visual Studio's menu bar and select *Attach to Process...*
159159
3. Make sure *Connection type:* is set to *JavaScript and TypeScript (Chrome DevTools/V8 Inspector)*
160160
> If you don't see *JavaScript and TypeScript (Chrome DevTools/V8 Inspector)*, make sure you've installed the *Node.js development* workload for your version of Visual Studio.
@@ -204,7 +204,7 @@ You can direct debug RNW apps using the Hermes JS engine with [VS Code](http://c
204204
"type": "node"
205205
}
206206
```
207-
3. Make sure that your native app and Metro is already running (i.e. `npx react-native run-windows`)
207+
3. Make sure that your native app and Metro is already running (i.e. using the [run-windows command](run-windows-cli.md))
208208
4. Open the *Run and Debug* sidebar by clicking on the button in the sidebar or by pressing `Ctrl+Shift+D`
209209
5. Make sure the new config is selected at the top of the *Run and Debug* sidebar
210210
6. Click on the ▶️ button or press `F5` in VS Code
@@ -258,7 +258,7 @@ You can direct debug RNW apps using the Hermes JS engine with [VS Code](http://c
258258
"request": "attach"
259259
}
260260
```
261-
3. Make sure that your native app and Metro is already running (i.e. `npx react-native run-windows`)
261+
3. Make sure that your native app and Metro is already running (i.e. using the [run-windows command](run-windows-cli.md))
262262
4. Open the *Run and Debug* sidebar by clicking on the button in the sidebar or by pressing `Ctrl+Shift+D`
263263
5. Make sure the new config is selected at the top of the *Run and Debug* sidebar
264264
6. Click on the ▶️ button or press `F5` in VS Code
@@ -326,7 +326,7 @@ InstanceSettings().UseDirectDebugger(false);
326326
327327
2. Then simply re-build and launch your RNW app as usual.
328328
329-
> For a new RNW app created using `react-native-windows-init`, `UseWebDebugger` defaults to `true` for Debug builds, and `false` for Release builds.
329+
> Unless otherwise specified, for a new RNW app, `UseWebDebugger` defaults to `false`.
330330
331331
### Step 2: Connect a debugger
332332

docs/getting-started.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Make sure you have installed all of the [development dependencies](rnw-dependenc
99

1010
For information around how to set up React Native, see the [React Native Getting Started Guide](https://reactnative.dev/docs/getting-started).
1111

12-
## Install React Native for Windows
12+
## Create a new React Native project
1313

1414
Remember to call `react-native init` from the place you want your project directory to live.
1515

@@ -27,23 +27,47 @@ npx --yes react-native@nightly init <projectName> --version "nightly"
2727

2828
### Navigate into this newly created directory
2929

30-
Once your project has been initialized, React Native will have created a new sub directory where all your generated files live.
30+
React Native will have created your project in a new sub-directory, which you must enter before continuing.
3131

3232
```bat
33-
cd projectName
33+
cd <projectName>
3434
```
3535

36-
### Install the Windows extension
36+
### Add React Native Windows to your project's dependencies
3737

38-
Lastly, install the React Native for Windows packages.
38+
<!-- Note, make sure "version" is pointing to the correct react-native-windows NPM tag in the command below. -->
39+
40+
<!-- 1. For the next version (i.e. in docs/getting-started.md) use "canary" -->
41+
<!-- 2. For the latest stable version in versioned_docs use "latest" -->
42+
<!-- 3. For older stable versions use the stable tag name, i.e. "0.73-stable" -->
43+
44+
<!--DOCUSAURUS_CODE_TABS-->
45+
46+
<!--Using Yarn (Recommended)-->
47+
48+
```bat
49+
yarn add react-native-windows@canary
50+
```
51+
52+
<!--Using NPM-->
53+
54+
```bat
55+
npm install --save react-native-windows@canary
56+
```
57+
58+
<!--END_DOCUSAURUS_CODE_TABS-->
59+
60+
### Initialize the React Native Windows native code and projects
61+
62+
Lastly, initialize the React Native for Windows application with the [init-windows command](init-windows-cli.md):
3963

4064
```bat
41-
npx --yes react-native-windows-init --overwrite
65+
npx react-native init-windows --overwrite
4266
```
4367

44-
> The --overwrite flag copies a custom `metro.config.js` file. If you are starting a new app, this should have no impact. If you are adding Windows to your existing app and you have modified the `metro.config.js` file, please back up your changes, run the command and copy over to take effect.
68+
> **Note:** RNW templates contain a customized `metro.config.js` file, which is meant to merge cleanly into the default config provided by the standard React Native project template. If you are starting a new app, overwriting `metro.config.js` should have no impact. However, if you are adding Windows to an existing app with an already modified `metro.config.js` file, please make sure to back up and re-apply your modifications after adding RNW.
4569
46-
For information on the options that `react-native-windows-init` takes see [React Native Windows Init CLI](https://microsoft.github.io/react-native-windows/init-cli).
70+
> **Note:** Previous versions of the RNW Getting Started steps recommend the use of the `react-native-windows-init` command, which is being phased out. For documentation of that command, see: [React Native Windows Init CLI](https://microsoft.github.io/react-native-windows/init-cli).
4771
4872
## Running a React Native Windows App
4973

@@ -52,19 +76,17 @@ For information on the options that `react-native-windows-init` takes see [React
5276
5377
- Without Using Visual Studio
5478

55-
In your React Native Windows project directory, run:
79+
In your React Native Windows project directory, run the [run-windows command](run-windows-cli.md):
5680

5781
```bat
5882
npx react-native run-windows
5983
```
6084

61-
For information on the options that `@react-native-windows/cli` takes see [React Native Windows CLI](run-windows-cli.md).
62-
63-
A new Command Prompt window will open with the React packager as well as a `react-native-windows` app. This step may take a while during first run since it involves building the entire project and all dependencies. You can now start developing! :tada:
85+
A new Command Prompt window will open with the React packager as well as your React Native for Windows app. This step may take a while during first run since it involves building the entire project and all dependencies. You can now start developing! :tada:
6486

6587
- Using Visual Studio
6688

67-
- From the root of the project directory, run the following script which will automatically link your app's dependencies:
89+
- From the root of the project directory, run the [autolink-windows command](autolink-windows-cli.md), which will automatically link your app's dependencies:
6890
```bat
6991
npx react-native autolink-windows
7092
```

docs/hermes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ Follow steps 1-7 from above, and then
107107

108108
### Enable debugging/profiling on release builds
109109

110-
We keep the inspector turned off on release builds by default. If you want to debug or profile release builds, set the MSBuild property `EnableHermesInspectorInReleaseFlavor` to `'true'` when building the platform.
110+
We keep the inspector turned off on release builds by default. If you want to debug or profile release builds, set the MSBuild property `EnableHermesInspectorInReleaseFlavor` to `'true'` when building the platform with the [run-windows command](run-windows-cli.md), i.e.:
111111

112112
```bash
113-
npx react-native run-windows --msbuild EnableHermesInspectorInReleaseFlavor=true
113+
npx react-native run-windows --msbuildprops EnableHermesInspectorInReleaseFlavor=true
114114
```
115115

116116
### Known Issues

docs/init-windows-cli.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
id: init-windows-cli
3+
title: react-native init-windows
4+
---
5+
6+
This guide will give you more information on the `init-windows` command of the React Native Windows CLI.
7+
8+
## `init-windows`
9+
10+
The `init-windows` CLI command is used to initialize a new React Native for Windows project inside an existing React Native project.
11+
12+
### Usage
13+
Initializes a new RNW project from a given template.
14+
15+
```bat
16+
npx react-native init-windows
17+
```
18+
### Options
19+
20+
Here are the options that `react-native init-windows` takes:
21+
| Option | Input Type | Description |
22+
|-----------------------|------------|--------------------------------------------------|
23+
| `--logging` | boolean | Verbose output logging |
24+
| `--template` | string | Specify the template to use |
25+
| `--name` | string | The native project name. Defaults to the name property in `app.json` or `package.json` |
26+
| `--namespace` | string | The native project namespace, expressed using dots as separators, i.e. `Level1.Level2.Level3`. Defaults to the same as name |
27+
| `--overwrite` | boolean | Overwrite any existing files without prompting |
28+
| `--no-telemetry` | boolean | Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI |
29+
| `-h`, `--help` | boolean | Display help for command |
30+
31+
### Templates
32+
33+
The following templates are available for use with `init-windows` by replacing `--template XYZ`, where `XYZ` can be:
34+
35+
| Template | Name |
36+
|:-:|:--|
37+
| `cpp-app` | React Native Windows Application (New Arch, C++, Win32, Hermes) |
38+
| `cpp-lib` | React Native Windows Turbo Module (New Arch, C++) |
39+
| `old/uwp-cpp-app` | React Native Windows Application (Old Arch, UWP, C++) |
40+
| `old/uwp-cpp-lib` | React Native Windows Library (Old Arch, UWP, C++) |
41+
| `old/uwp-cs-app` | React Native Windows Application (Old Arch, UWP, C#) |
42+
| `old/uwp-cs-lib` | React Native Windows Library (Old Arch, UWP, C#) |
43+
44+
This sends telemetry to Microsoft by default. You can prevent the telemetry from being sent by using the `--no-telemetry` command line option. See below for more details.
45+
46+
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
47+
48+
This data collection notice only applies to the process of running the react-native-windows CLI commands.
49+

0 commit comments

Comments
 (0)