1
- import { Tree , formatFiles , installPackagesTask , generateFiles , joinPathFragments } from '@nrwl/devkit' ;
1
+ import {
2
+ Tree ,
3
+ formatFiles ,
4
+ installPackagesTask ,
5
+ generateFiles ,
6
+ joinPathFragments ,
7
+ } from '@nrwl/devkit' ;
2
8
import { libraryGenerator } from '@nrwl/angular/generators' ;
3
9
import { FeatureOptions } from './schema' ;
4
10
import { strings } from '@angular-devkit/core' ;
5
11
import { addTsExport } from '../utils/add-ts-exports' ;
6
- import { addDeclarationWithExportToNgModule , addImportToNgModule } from '../utils/addToNgModule' ;
12
+ import {
13
+ addDeclarationWithExportToNgModule ,
14
+ addImportToNgModule ,
15
+ } from '../utils/addToNgModule' ;
7
16
import { addNgrxImportsToDomain } from '../utils/add-ngrx-imports-to-domain' ;
8
17
import { fileContains } from '../utils/fileContains' ;
9
18
import { getWorkspaceScope } from '../utils/get-workspace-scope' ;
10
19
11
20
export default async function ( tree : Tree , options : FeatureOptions ) {
12
-
13
21
options . app ??= options . domain ;
14
22
options . domainDirectory ??= '' ;
15
23
options . entity ??= '' ;
@@ -61,9 +69,8 @@ export default async function (tree: Tree, options: FeatureOptions) {
61
69
? `${ featureDirectory } /${ featureFolderName } `
62
70
: featureFolderName ;
63
71
64
- const featureDirectoryAndFolderNameDasherized = `${ featureDirectoryAndFolderName } `
65
- . split ( '/' )
66
- . join ( '-' ) ;
72
+ const featureDirectoryAndFolderNameDasherized =
73
+ `${ featureDirectoryAndFolderName } ` . split ( '/' ) . join ( '-' ) ;
67
74
68
75
const featureLibFolderPath = `${ domainNameAndDirectoryPath } /${ featureDirectoryAndFolderName } /src/lib` ;
69
76
const featureModuleFilepath = `${ featureLibFolderPath } /${ domainNameAndDirectoryDasherized } -${ featureDirectoryAndFolderNameDasherized } .module.ts` ;
@@ -79,10 +86,10 @@ export default async function (tree: Tree, options: FeatureOptions) {
79
86
) ;
80
87
const appModulePath = `apps/${ appDirectoryAndName } /src/app/app.module.ts` ;
81
88
82
- const requiredAppModulePath = `apps/${ appDirectoryAndName } /src/app/app.module .ts` ;
83
- if ( ! options . noApp && ! tree . exists ( requiredAppModulePath ) ) {
89
+ const requiredAppCompPath = `apps/${ appDirectoryAndName } /src/app/app.component .ts` ;
90
+ if ( ! options . noApp && ! tree . exists ( requiredAppCompPath ) ) {
84
91
throw new Error (
85
- `Specified app ${ options . app } does not exist: ${ requiredAppModulePath } expected!`
92
+ `Specified app ${ options . app } does not exist: ${ requiredAppCompPath } expected!`
86
93
) ;
87
94
}
88
95
@@ -92,8 +99,6 @@ export default async function (tree: Tree, options: FeatureOptions) {
92
99
) ;
93
100
}
94
101
95
- // let updatedEntityNameOptions = Object.assign({}, options);
96
-
97
102
await libraryGenerator ( tree , {
98
103
name : featureFolderName ,
99
104
directory : featureDirectory
@@ -103,45 +108,35 @@ export default async function (tree: Tree, options: FeatureOptions) {
103
108
prefix : domainNameAndDirectoryDasherized ,
104
109
publishable : options . type === 'publishable' ,
105
110
buildable : options . type === 'buildable' ,
106
- importPath : options . importPath
111
+ importPath : options . importPath ,
112
+ skipModule : options . standalone ,
107
113
} ) ;
108
114
109
- addImportToNgModule ( tree , {
110
- filePath : featureModuleFilepath ,
111
- importClassName : domainModuleClassName ,
112
- importPath : domainImportPath
113
- } ) ;
114
-
115
- if ( ! options . noApp && ! options . lazy && tree . exists ( appModulePath ) ) {
116
- addImportToNgModule ( tree , {
117
- filePath : appModulePath ,
118
- importClassName : featureModuleClassName ,
119
- importPath : featureImportPath
115
+ if ( ! options . standalone ) {
116
+ wireUpNgModules ( tree , {
117
+ featureModuleFilepath,
118
+ domainModuleClassName,
119
+ domainImportPath,
120
+ options,
121
+ appModulePath,
122
+ featureModuleClassName,
123
+ featureImportPath,
120
124
} ) ;
121
-
122
- const contains = fileContains ( tree , appModulePath , 'HttpClientModule' ) ;
123
- if ( ! contains ) {
124
- addImportToNgModule ( tree , {
125
- filePath : appModulePath ,
126
- importClassName : 'HttpClientModule' ,
127
- importPath : '@angular/common/http'
128
- } ) ;
129
- }
130
125
}
131
126
132
127
generate ( tree , {
133
128
options,
134
129
entityName,
135
130
domainLibFolderPath,
136
131
workspaceName,
137
- featureLibFolderPath
132
+ featureLibFolderPath,
138
133
} ) ;
139
134
140
135
if ( entityName ) {
141
136
addTsExport ( tree , domainIndexPath , [
142
137
`./lib/entities/${ entityName } ` ,
143
138
`./lib/infrastructure/${ entityName } .data.service` ,
144
- ] )
139
+ ] ) ;
145
140
}
146
141
147
142
if ( options . ngrx && entityName && tree . exists ( domainModuleFilepath ) ) {
@@ -159,19 +154,80 @@ export default async function (tree: Tree, options: FeatureOptions) {
159
154
`./lib/${ featureDirectoryAndNameDasherized } .component` ,
160
155
] ) ;
161
156
162
- addDeclarationWithExportToNgModule ( tree , {
163
- filePath : featureModuleFilepath ,
164
- importClassName : featureComponentClassName ,
165
- importPath : featureComponentImportPath
166
- } ) ;
157
+ if ( ! options . standalone ) {
158
+ addDeclarationWithExportToNgModule ( tree , {
159
+ filePath : featureModuleFilepath ,
160
+ importClassName : featureComponentClassName ,
161
+ importPath : featureComponentImportPath ,
162
+ } ) ;
163
+ }
167
164
168
165
await formatFiles ( tree ) ;
169
166
return ( ) => {
170
167
installPackagesTask ( tree ) ;
171
168
} ;
172
169
}
173
170
174
- function generate ( tree : Tree , { options, entityName, domainLibFolderPath, workspaceName, featureLibFolderPath } : { options : FeatureOptions ; entityName : string ; domainLibFolderPath : string ; workspaceName : string ; featureLibFolderPath : string ; } ) {
171
+ function wireUpNgModules (
172
+ tree : Tree ,
173
+ {
174
+ featureModuleFilepath,
175
+ domainModuleClassName,
176
+ domainImportPath,
177
+ options,
178
+ appModulePath,
179
+ featureModuleClassName,
180
+ featureImportPath,
181
+ } : {
182
+ featureModuleFilepath : string ;
183
+ domainModuleClassName : string ;
184
+ domainImportPath : string ;
185
+ options : FeatureOptions ;
186
+ appModulePath : string ;
187
+ featureModuleClassName : string ;
188
+ featureImportPath : string ;
189
+ }
190
+ ) {
191
+ addImportToNgModule ( tree , {
192
+ filePath : featureModuleFilepath ,
193
+ importClassName : domainModuleClassName ,
194
+ importPath : domainImportPath ,
195
+ } ) ;
196
+
197
+ if ( ! options . noApp && ! options . lazy && tree . exists ( appModulePath ) ) {
198
+ addImportToNgModule ( tree , {
199
+ filePath : appModulePath ,
200
+ importClassName : featureModuleClassName ,
201
+ importPath : featureImportPath ,
202
+ } ) ;
203
+
204
+ const contains = fileContains ( tree , appModulePath , 'HttpClientModule' ) ;
205
+ if ( ! contains ) {
206
+ addImportToNgModule ( tree , {
207
+ filePath : appModulePath ,
208
+ importClassName : 'HttpClientModule' ,
209
+ importPath : '@angular/common/http' ,
210
+ } ) ;
211
+ }
212
+ }
213
+ }
214
+
215
+ function generate (
216
+ tree : Tree ,
217
+ {
218
+ options,
219
+ entityName,
220
+ domainLibFolderPath,
221
+ workspaceName,
222
+ featureLibFolderPath,
223
+ } : {
224
+ options : FeatureOptions ;
225
+ entityName : string ;
226
+ domainLibFolderPath : string ;
227
+ workspaceName : string ;
228
+ featureLibFolderPath : string ;
229
+ }
230
+ ) {
175
231
const tmpl = '' ;
176
232
const params = {
177
233
...strings ,
@@ -182,7 +238,7 @@ function generate(tree: Tree, { options, entityName, domainLibFolderPath, worksp
182
238
entityName,
183
239
domainLibFolderPath,
184
240
featureLibFolderPath,
185
- tmpl
241
+ tmpl,
186
242
} ;
187
243
188
244
if ( options . ngrx && entityName ) {
@@ -192,16 +248,14 @@ function generate(tree: Tree, { options, entityName, domainLibFolderPath, worksp
192
248
domainLibFolderPath ,
193
249
params
194
250
) ;
195
- }
196
- else if ( ! options . ngrx && entityName ) {
251
+ } else if ( ! options . ngrx && entityName ) {
197
252
generateFiles (
198
253
tree ,
199
254
joinPathFragments ( __dirname , './files/forDomain' ) ,
200
255
domainLibFolderPath ,
201
256
params
202
257
) ;
203
- }
204
- else if ( ! options . ngrx && ! entityName ) {
258
+ } else if ( ! options . ngrx && ! entityName ) {
205
259
generateFiles (
206
260
tree ,
207
261
joinPathFragments ( __dirname , './files/forDomain/application' ) ,
@@ -217,8 +271,7 @@ function generate(tree: Tree, { options, entityName, domainLibFolderPath, worksp
217
271
featureLibFolderPath ,
218
272
params
219
273
) ;
220
- }
221
- else if ( ! options . ngrx ) {
274
+ } else if ( ! options . ngrx ) {
222
275
generateFiles (
223
276
tree ,
224
277
joinPathFragments ( __dirname , './files/forFeature' ) ,
0 commit comments