Skip to content

Commit 7cd0624

Browse files
fix(schematics): use Angular default properties when not defined (#2507)
Related to #1036
1 parent 81efd42 commit 7cd0624

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

modules/schematics/src/container/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
} from '@ngrx/schematics/schematics-core';
3030
import { Schema as ContainerOptions } from './schema';
3131

32-
function addStateToComponent(options: ContainerOptions) {
32+
function addStateToComponent(options: Partial<ContainerOptions>) {
3333
return (host: Tree) => {
3434
if (!options.state && !options.stateInterface) {
3535
return host;
@@ -152,10 +152,15 @@ export default function(options: ContainerOptions): Rule {
152152
]
153153
);
154154

155+
// Remove all undefined values to use the schematic defaults (in angular.json or the Angular schema)
156+
(Object.keys(opts) as (keyof ContainerOptions)[]).forEach(
157+
key => (opts[key] === undefined ? delete opts[key] : {})
158+
);
159+
155160
return chain([
156161
externalSchematic('@schematics/angular', 'component', {
157162
...opts,
158-
skipTests: true
163+
skipTests: true,
159164
}),
160165
addStateToComponent(options),
161166
mergeWith(templateSource),

modules/schematics/src/container/schema.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@
2727
"inlineStyle": {
2828
"description": "Specifies if the style will be in the ts file.",
2929
"type": "boolean",
30-
"default": false,
3130
"alias": "s"
3231
},
3332
"inlineTemplate": {
3433
"description": "Specifies if the template will be in the ts file.",
3534
"type": "boolean",
36-
"default": false,
3735
"alias": "t"
3836
},
3937
"viewEncapsulation": {
@@ -46,7 +44,6 @@
4644
"description": "Specifies the change detection strategy.",
4745
"enum": ["Default", "OnPush"],
4846
"type": "string",
49-
"default": "Default",
5047
"alias": "c"
5148
},
5249
"prefix": {
@@ -58,23 +55,19 @@
5855
"style": {
5956
"description":
6057
"The file extension or preprocessor to use for style files.",
61-
"type": "string",
62-
"default": "css"
58+
"type": "string"
6359
},
6460
"skipTest": {
6561
"type": "boolean",
66-
"description": "When true, does not create test files.",
67-
"default": false
62+
"description": "When true, does not create test files."
6863
},
6964
"flat": {
7065
"type": "boolean",
71-
"description": "Flag to indicate if a dir is created.",
72-
"default": false
66+
"description": "Flag to indicate if a dir is created."
7367
},
7468
"skipImport": {
7569
"type": "boolean",
76-
"description": "Flag to skip the module import.",
77-
"default": false
70+
"description": "Flag to skip the module import."
7871
},
7972
"selector": {
8073
"type": "string",
@@ -88,7 +81,6 @@
8881
},
8982
"export": {
9083
"type": "boolean",
91-
"default": false,
9284
"description": "Specifies if declaring module exports the component."
9385
},
9486
"state": {

projects/ngrx.io/content/guide/schematics/index.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Scaffolding library for Angular applications using NgRx libraries.
44

55
Schematics provides Angular CLI commands for generating files when building new NgRx feature areas and expanding existing ones. Built on top of [`Schematics`](https://blog.angular.io/schematics-an-introduction-dc1dfbc2a2b2), this tool integrates with the [`Angular CLI`](https://cli.angular.io/).
66

7-
## Installation
7+
## Installation
88

99
Detailed installation instructions can be found on the [Installation](guide/schematics/install) page.
1010

@@ -50,13 +50,3 @@ ng config cli.defaultCollection @ngrx/schematics
5050
```
5151

5252
The [collection schema](https://github.com/ngrx/platform/tree/master/modules/schematics/collection.json) also has aliases to the most common schematics used to generate files.
53-
54-
The `@ngrx/schematics` extend the default `@schematics/angular` collection. If you want to set defaults for schematics such as generating components with scss file, you must change the schematics package name from `@schematics/angular` to `@ngrx/schematics` in `angular.json`:
55-
56-
```json
57-
"schematics": {
58-
"@ngrx/schematics:component": {
59-
"style": "scss"
60-
}
61-
}
62-
```

0 commit comments

Comments
 (0)