Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

Commit afdf7cb

Browse files
committed
chore: fixes based on the review + Default configuration section
1 parent b764a6f commit afdf7cb

File tree

1 file changed

+70
-61
lines changed

1 file changed

+70
-61
lines changed

docs/tooling/angular-cli.md

Lines changed: 70 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Angular CLI
3-
description: Learn how to use the Angular CLI in your NativeScript app.
3+
description: Learn how to use the Angular CLI in your NativeScript app with @nativescript/schematics. The extension to Angular Schematisc allows you to use the Angular CLI in both NativeScript Angular projects and web+mobile code-sharing projects.
44
position: 80
55
environment: angular
66
---
@@ -11,7 +11,7 @@ The **Angular CLI** makes it easy to create an Angular application and generate
1111

1212
With the help of the [NativeScript Schematics](https://www.npmjs.com/package/@nativescript/schematics), you can also reap the benefits of the [Angular CLI](https://www.npmjs.com/package/@angular/cli) in your **Angular NativeScript** projects.
1313

14-
The **NativeScript Schematics** extend the **Angular Schematics**, by providing NativeScript-specific functionality and changes to the default **component** and **module** generators.
14+
The **NativeScript Schematics** extend the **Angular Schematics**, by providing NativeScript-specific functionality to the existing **Angular generators**.
1515

1616
## Installation
1717

@@ -37,34 +37,47 @@ npm i --save-dev @angular/cli
3737
npm i --save-dev @nativescript/schematics
3838
```
3939

40-
## Extending existing NativeScript Projects with the Angular CLI
40+
## Default configuration
41+
42+
All Angular projects created with the **NativeScript CLI 5.0** come preconfigured and ready to work with the **NativeScript Schematics** and the **Angular CLI**.
43+
44+
This is done by added:
45+
46+
- the **@nativescript/schematics** node module to **package.json**
47+
- an **angular.json** file configured to work with **@nativescript/schematics**
48+
49+
However, you will still need to have the **Angular CLI** installed either [globally](./angular-cli#global-installation) or [locally](./angular-cli#local-installation).
50+
51+
### Extending existing NativeScript Projects with the Angular CLI
52+
53+
For projects created with the NativeScript CLI v4 or older, you will need to
4154

4255
To introduce the Angular CLI to an **existing** NativeScript Angular Project, you need to add an **angular.json** file (which is used by the Angular CLI to understand the structure of the project) to the root of the project. The **angular.json** file should have the following content:
4356

4457
```json
4558
{
46-
"version": 1,
47-
"cli": {
48-
"defaultCollection": "@nativescript/schematics"
49-
},
50-
"projects": {
51-
"my-project-name": {
52-
"root": "",
53-
"sourceRoot": ".",
54-
"projectType": "application",
55-
"prefix": "app"
56-
}
57-
},
58-
"defaultProject": "my-project-name"
59+
"version": 1,
60+
"cli": {
61+
"defaultCollection": "@nativescript/schematics"
62+
},
63+
"projects": {
64+
"my-project-name": {
65+
"root": "",
66+
"sourceRoot": "src",
67+
"projectType": "application",
68+
"prefix": "ns"
69+
}
70+
},
71+
"defaultProject": "my-project-name"
5972
}
6073
```
6174

62-
The **defaultCollection** is where you specify that you want to use the **NativeScript Schematics**, as the default **Schematics collection** for your project.
75+
The **defaultCollection** is where you specify that you want to use the **NativeScript Schematics** when generating building blocks with the Angular CLI.
6376

6477
You could update:
6578

66-
* **my-project-name** to match the name of your project, but that is not absolutely necessary,
67-
* **prefix** to match the prefix for your component selectors (i.e. `"prefix": "app"` => `selector: 'app-home'`).
79+
- **my-project-name** to match the name of your project, but that is not absolutely necessary,
80+
- **prefix** to match the prefix for your component selectors (i.e. `"prefix": "app"` => `selector: 'app-home'`).
6881

6982
## New Project
7083

@@ -82,18 +95,18 @@ ng new -c=@nativescript/schematics my-mobile-app
8295

8396
This notifies the Angular CLI that it should use the **ng-new** schematic from the **@nativescript/schematics** npm package. Which in turn creates a new NativeScript Angular project and performs an npm install.
8497

85-
> Note, the NativeScript projects created with the Angular CLI, come with the Angular CLI and NativeScript Schematics **already configured**. There is no need to add the **angular.json** file manually.
98+
> Note, the NativeScript projects created with the Angular CLI come with the Angular CLI and NativeScript Schematics **already configured**. There is no need to add the **angular.json** file manually.
8699
87100
### Additional Options
88101

89102
You can specify the following options when generating new applications:
90103

91-
| Option | Description | Default
92-
| --- | --- | --- |
93-
| prefix | The prefix to apply to generated selectors. | `app` |
94-
| theme | Specifies whether the **NativeScript Core Theme** should be included. | `true` |
95-
| style | Specifies whether to use `css` or `scss` files for styling. | `css` |
96-
| webpack | Specifies whether the project should use webpack. | `true`
104+
| Option | Description | Default |
105+
| ------- | --------------------------------------------------------------------- | ------- |
106+
| prefix | The prefix to apply to generated selectors. | `app` |
107+
| theme | Specifies whether the **NativeScript Core Theme** should be included. | `true` |
108+
| style | Specifies whether to use `css` or `scss` files for styling. | `css` |
109+
| webpack | Specifies whether the project should use webpack. | `true` |
97110

98111
Here is an example on how you could provide a different value for each of the flags:
99112

@@ -118,29 +131,27 @@ It allows you to generate **components**, **routes**, **services** and **pipes**
118131

119132
> Feel free to check out the [official Angular CLI documentation for the generate command](https://github.com/angular/angular-cli/wiki/generate), as there is a lot of available options.
120133
121-
In the **NativeScript Schematics** we have extended the schematics for generating **components** and **modules**. The schematics to generate **services**, **pipes**, etc remain the same.
122-
123134
### Component
124135

125136
To generate a new component, you need to use the **component schematic**. Like this:
126137

127138
```long
128-
ng generate component my-name
139+
ng generate component my-name
129140
```
141+
130142
```short
131-
ng g c my-name
143+
ng g c my-name
132144
```
133145

134146
#### NativeScript Only Project
135147

136-
In a NativeScript Only project (*not code-sharing*), this command:
137-
138-
* creates component files:
139-
* **my-name.component.ts** - a class file,
140-
* **my-name.component.html** - a template file,
141-
* and **my-name.component.css** or **my-name.component.scss** - a style file,
142-
* adds the component to the **AppModule Providers**,
143-
* adds `moduleId: module.id` to the `@Component` decorator - which is the **modification introduced** by the NativeScript Schematics.
148+
In a NativeScript Only project (_not code-sharing_), this command:
149+
150+
- creates component files:
151+
_ **my-name.component.ts** - a class file,
152+
_ **my-name.component.html** - a template file, \* and **my-name.component.css** or **my-name.component.scss** - a style file,
153+
- adds the component to the **AppModule Providers**,
154+
- adds `moduleId: module.id` to the `@Component` decorator - which is the **modification introduced** by the NativeScript Schematics.
144155

145156
The component files should be generated in the **app/my-name** folder, like this:
146157

@@ -155,16 +166,15 @@ app
155166
#### Code-Sharing Project
156167

157168
In a Code-Sharing Project, this command:
158-
159-
* creates **shared** and **platform-specific** component files:
160-
* **my-name.component.ts** - a **shared** class file,
161-
* **my-name.component.html** - a **web-specific** template file,
162-
* **my-name.component.html** - a **NativeScript-specific** template file,
163-
* **my-name.component.css** - a **web-specific** style file,
164-
* and **my-name.component.tns.css** - a **NativeScript-specific** style file,
165-
* adds the component to the **AppModule Providers** of both:
166-
* **app.module.ts** - the **web-specific** AppModule file,
167-
* and **app.module.tns.ts** - the **nativescript-specific** AppModule file.
169+
170+
- creates **shared** and **platform-specific** component files:
171+
_ **my-name.component.ts** - a **shared** class file,
172+
_ **my-name.component.html** - a **web-specific** template file,
173+
_ **my-name.component.html** - a **NativeScript-specific** template file,
174+
_ **my-name.component.css** - a **web-specific** style file, \* and **my-name.component.tns.css** - a **NativeScript-specific** style file,
175+
- adds the component to the **AppModule Providers** of both:
176+
_ **app.module.ts** - the **web-specific** AppModule file,
177+
_ and **app.module.tns.ts** - the **nativescript-specific** AppModule file.
168178

169179
The component files should be generated in the **src/app/my-name** folder, like this:
170180

@@ -184,10 +194,11 @@ src
184194
To generate a new module, you need to use the **module schematic**. Like this:
185195

186196
```long
187-
ng generate module my-name
197+
ng generate module my-name
188198
```
199+
189200
```short
190-
ng g m my-name
201+
ng g m my-name
191202
```
192203

193204
#### NativeScript Only Project
@@ -210,8 +221,8 @@ export class MyNameModule { }
210221

211222
The most notable changes introduced by the NativeScript Schematics, are:
212223

213-
* the import of the **NativeScriptCommonModule**, as opposed to the **CommonModule** used by the Angular web projects,
214-
* and the inclusions of the **NO_ERRORS_SCHEMA** schema, which is required to allow using the NativeScript specific selectors (i.e. **StackLayout**).
224+
- the import of the **NativeScriptCommonModule**, as opposed to the **CommonModule** used by the Angular web projects,
225+
- and the inclusions of the **NO_ERRORS_SCHEMA** schema, which is required to allow using the NativeScript specific selectors (i.e. **StackLayout**).
215226

216227
The module file should be generated in the **src/app/my-name** folder, like this:
217228

@@ -225,9 +236,9 @@ app
225236

226237
In a Code-Sharing Project, this command creates:
227238

228-
* **my-name.module.ts** - a **web-specific** module file, which imports the **CommonModule**
229-
* **my-name.module.tns.ts** - a **NativeScript-specific** module file, which imports the **NativeScriptCommonModule** and includes the **NO_ERRORS_SCHEMA** schema,
230-
* and **my-name.common.ts** - a **shared** file with constants that allow you to easily share the declarations for the components, providers and routes used by both modules.
239+
- **my-name.module.ts** - a **web-specific** module file, which imports the **CommonModule**
240+
- **my-name.module.tns.ts** - a **NativeScript-specific** module file, which imports the **NativeScriptCommonModule** and includes the **NO_ERRORS_SCHEMA** schema,
241+
- and **my-name.common.ts** - a **shared** file with constants that allow you to easily share the declarations for the components, providers and routes used by both modules.
231242

232243
The module files should be generated in the **src/app/my-name** folder, like this:
233244

@@ -240,7 +251,6 @@ src
240251
└── my-name.module.tns.ts
241252
```
242253

243-
244254
### Bonus: Generate Components inside a Module
245255

246256
You can also generate components inside other modules. This works the same for the NativeScript Only and Code-Sharing projects.
@@ -259,7 +269,6 @@ These three commands will:
259269
2. Generate a **cat component** inside the pets module and it will add it to the pets module declarations.
260270
3. Generate a **dog component** inside the pets module and it will add it to the pets module declarations.
261271

262-
263272
## Additional Template Generators
264273

265274
The **NativeScript Schematics** also come with additional templates that help you build your apps faster.
@@ -283,7 +292,7 @@ dogs
283292

284293
#### Options
285294

286-
| Option | Description
287-
| --- | ---
288-
| master | The name of the master component and the name of the module.
289-
| detail | The name of the detail component
295+
| Option | Description |
296+
| ------ | ------------------------------------------------------------ |
297+
| master | The name of the master component and the name of the module. |
298+
| detail | The name of the detail component |

0 commit comments

Comments
 (0)