Skip to content

Commit

Permalink
fix(schematics): use Angular default properties when not defined (#2507)
Browse files Browse the repository at this point in the history
Related to #1036
  • Loading branch information
timdeschryver authored May 4, 2020
1 parent 81efd42 commit 7cd0624
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
9 changes: 7 additions & 2 deletions modules/schematics/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from '@ngrx/schematics/schematics-core';
import { Schema as ContainerOptions } from './schema';

function addStateToComponent(options: ContainerOptions) {
function addStateToComponent(options: Partial<ContainerOptions>) {
return (host: Tree) => {
if (!options.state && !options.stateInterface) {
return host;
Expand Down Expand Up @@ -152,10 +152,15 @@ export default function(options: ContainerOptions): Rule {
]
);

// Remove all undefined values to use the schematic defaults (in angular.json or the Angular schema)
(Object.keys(opts) as (keyof ContainerOptions)[]).forEach(
key => (opts[key] === undefined ? delete opts[key] : {})
);

return chain([
externalSchematic('@schematics/angular', 'component', {
...opts,
skipTests: true
skipTests: true,
}),
addStateToComponent(options),
mergeWith(templateSource),
Expand Down
16 changes: 4 additions & 12 deletions modules/schematics/src/container/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
"inlineStyle": {
"description": "Specifies if the style will be in the ts file.",
"type": "boolean",
"default": false,
"alias": "s"
},
"inlineTemplate": {
"description": "Specifies if the template will be in the ts file.",
"type": "boolean",
"default": false,
"alias": "t"
},
"viewEncapsulation": {
Expand All @@ -46,7 +44,6 @@
"description": "Specifies the change detection strategy.",
"enum": ["Default", "OnPush"],
"type": "string",
"default": "Default",
"alias": "c"
},
"prefix": {
Expand All @@ -58,23 +55,19 @@
"style": {
"description":
"The file extension or preprocessor to use for style files.",
"type": "string",
"default": "css"
"type": "string"
},
"skipTest": {
"type": "boolean",
"description": "When true, does not create test files.",
"default": false
"description": "When true, does not create test files."
},
"flat": {
"type": "boolean",
"description": "Flag to indicate if a dir is created.",
"default": false
"description": "Flag to indicate if a dir is created."
},
"skipImport": {
"type": "boolean",
"description": "Flag to skip the module import.",
"default": false
"description": "Flag to skip the module import."
},
"selector": {
"type": "string",
Expand All @@ -88,7 +81,6 @@
},
"export": {
"type": "boolean",
"default": false,
"description": "Specifies if declaring module exports the component."
},
"state": {
Expand Down
12 changes: 1 addition & 11 deletions projects/ngrx.io/content/guide/schematics/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Scaffolding library for Angular applications using NgRx libraries.

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/).

## Installation
## Installation

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

Expand Down Expand Up @@ -50,13 +50,3 @@ ng config cli.defaultCollection @ngrx/schematics
```

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.

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`:

```json
"schematics": {
"@ngrx/schematics:component": {
"style": "scss"
}
}
```

0 comments on commit 7cd0624

Please sign in to comment.