Skip to content

Commit 72c3849

Browse files
Ombuwebrigor789
andauthored
docs: CLI Basics (#10)
Co-authored-by: Igor Randjelovic <[email protected]>
1 parent c957e3d commit 72c3849

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

content/guide/cli-basics.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: CLI Basics
3+
contributors:
4+
- Ombuweb
5+
- rigor789
6+
---
7+
8+
When working with NativeScript, you will often interact with the NativeScript CLI. The CLI is self-documented, so you can always run `ns --help` or `ns <command> --help` to view available commands, flags and descriptions.
9+
10+
This page is a quick reference for useful development commands, but it's not meant to be an exhaustive list of all the commands.
11+
12+
**The following workflows have their dedicated pages with further information:**
13+
14+
- [Running](/guide/running)
15+
- [Debugging](/guide/debugging)
16+
- [Publishing](/guide/publishing/)
17+
18+
## Cleaning
19+
20+
### Cleaning a single project
21+
22+
When you're installing plugins with native dependencies or updating runtime versions, it's a good practice to perform a clean build.
23+
This helps ensure everything fits together correctly. If you're dealing with mysterious build errors, they might disappear after a clean build.
24+
25+
To clean, run this command from your project's root directory:
26+
27+
```cli
28+
ns clean
29+
```
30+
31+
Running `ns clean` removes the `node_modules`, `hooks`, and `platforms` directories. You can customize what's cleaned in the [nativescript.config.ts](/project-structure/nativescript-config#cli-pathstoclean).
32+
33+
### Cleaning multiple projects
34+
35+
If you have multiple projects piled up in your projects folder, and would like to free up some disk space, you can run `ns clean` in your projects folder, and it will scan for any valid NativeScript projects in sub-directories and the prompt you to choose the ones to clean.
36+
37+
<DeviceFrame type="ios">
38+
<video controls src="https://user-images.githubusercontent.com/879060/230395606-dbb4a56f-74e8-403b-a687-62e27a61f8d4.mov"></video>
39+
</DeviceFrame>
40+
41+
## Listing connected devices
42+
43+
To list all connected devices (both physical and virtual), run:
44+
45+
```cli
46+
ns devices
47+
```
48+
49+
Example output:
50+
51+
```
52+
| # | Device Name | Platform | Device Identifier | Type | Status | Connection Type |
53+
| - | -------------- | -------- | ------------------------------------ | -------- | --------- | --------------- |
54+
| 1 | Pixel 4 API 33 | Android | emulator-5554 | Emulator | Connected | Local |
55+
| 2 | generic_device | Android | XXXXXXXXXXXXXX | Device | Connected | USB |
56+
| 3 | iPhone 14 Pro | iOS | XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX | Emulator | Connected | Local |
57+
```
58+
59+
## Setting the default package manager
60+
61+
To set the default package manager that the CLI uses (unless overridden in [nativescript.config.ts](/project-structure/nativescript-config#cli-packagemanager)):
62+
63+
```cli
64+
ns package-manager set npm
65+
ns package-manager set yarn
66+
ns package-manager set yarn2 # experimental
67+
ns package-manager set pnpm
68+
```

content/guide/running.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ These flags are identical. Using them runs the project only on virtual devices.
2424

2525
#### --device &lt;id&gt;
2626

27-
Only run on the specified device. The id is taken from the output of `ns devices`.
27+
Only run on the specified device. The id is taken from the output of [`ns devices`](/guide/cli-basics#listing-connected-devices).
28+
29+
#### --timeout &lt;seconds&gt;
30+
31+
The number of seconds to wait for the debugger to boot.
32+
The default timeout is 90 seconds.
33+
34+
#### --clean
35+
36+
Forces a clean rebuild of the native application.
2837

2938
## Running on physical devices
3039

content/sidebar.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export default [
3131
{
3232
text: 'Development Workflow',
3333
items: [
34+
{
35+
text: 'CLI Basics',
36+
link: '/guide/cli-basics',
37+
},
3438
{
3539
text: 'Running',
3640
link: '/guide/running',

0 commit comments

Comments
 (0)