@@ -11,26 +11,25 @@ import {
11
11
mergeWith ,
12
12
move ,
13
13
noop ,
14
- template ,
15
14
url ,
16
15
} from '@angular-devkit/schematics' ;
17
- import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks' ;
18
- import * as ts from 'typescript' ;
19
16
import {
20
- stringUtils ,
21
- insertImport ,
22
- buildRelativePath ,
23
- addImportToModule ,
24
17
InsertChange ,
25
- getProjectPath ,
18
+ addImportToModule ,
19
+ buildRelativePath ,
26
20
findModuleFromOptions ,
21
+ getProjectPath ,
22
+ insertImport ,
23
+ parseName ,
24
+ stringUtils ,
27
25
addPackageToPackageJson ,
28
26
platformVersion ,
29
- parseName ,
30
27
} from '@ngrx/effects/schematics-core' ;
31
- import { Schema as RootEffectOptions } from './schema' ;
28
+ import * as ts from 'typescript' ;
29
+ import { Schema as EffectOptions } from './schema' ;
30
+ import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks' ;
32
31
33
- function addImportToNgModule ( options : RootEffectOptions ) : Rule {
32
+ function addImportToNgModule ( options : EffectOptions ) : Rule {
34
33
return ( host : Tree ) => {
35
34
const modulePath = options . module ;
36
35
@@ -39,7 +38,7 @@ function addImportToNgModule(options: RootEffectOptions): Rule {
39
38
}
40
39
41
40
if ( ! host . exists ( modulePath ) ) {
42
- throw new Error ( ' Specified module does not exist' ) ;
41
+ throw new Error ( ` Specified module path ${ modulePath } does not exist` ) ;
43
42
}
44
43
45
44
const text = host . read ( modulePath ) ;
@@ -77,13 +76,21 @@ function addImportToNgModule(options: RootEffectOptions): Rule {
77
76
effectsName ,
78
77
relativePath
79
78
) ;
79
+
80
+ const effectsSetup = options . minimal ? `[]` : `[${ effectsName } ]` ;
80
81
const [ effectsNgModuleImport ] = addImportToModule (
81
82
source ,
82
83
modulePath ,
83
- `EffectsModule.forRoot([ ${ effectsName } ] )` ,
84
+ `EffectsModule.forRoot(${ effectsSetup } )` ,
84
85
relativePath
85
86
) ;
86
- const changes = [ effectsModuleImport , effectsImport , effectsNgModuleImport ] ;
87
+
88
+ let changes = [ effectsModuleImport , effectsNgModuleImport ] ;
89
+
90
+ if ( ! options . minimal ) {
91
+ changes = changes . concat ( [ effectsImport ] ) ;
92
+ }
93
+
87
94
const recorder = host . beginUpdate ( modulePath ) ;
88
95
for ( const change of changes ) {
89
96
if ( change instanceof InsertChange ) {
@@ -109,22 +116,23 @@ function addNgRxEffectsToPackageJson() {
109
116
} ;
110
117
}
111
118
112
- export default function ( options : RootEffectOptions ) : Rule {
119
+ export default function ( options : EffectOptions ) : Rule {
113
120
return ( host : Tree , context : SchematicContext ) => {
114
121
options . path = getProjectPath ( host , options ) ;
115
122
116
123
if ( options . module ) {
117
124
options . module = findModuleFromOptions ( host , options ) ;
118
125
}
119
126
120
- const parsedPath = parseName ( options . path , options . name ) ;
127
+ const parsedPath = parseName ( options . path , options . name || '' ) ;
121
128
options . name = parsedPath . name ;
122
129
options . path = parsedPath . path ;
123
130
124
131
const templateSource = apply ( url ( './files' ) , [
125
132
options . spec
126
133
? noop ( )
127
134
: filter ( path => ! path . endsWith ( '.spec.ts.template' ) ) ,
135
+ options . minimal ? filter ( _ => false ) : noop ( ) ,
128
136
applyTemplates ( {
129
137
...stringUtils ,
130
138
'if-flat' : ( s : string ) =>
0 commit comments