@@ -12,7 +12,7 @@ import {
1212 updateNxJson ,
1313 addDependenciesToPackageJson ,
1414} from '@nrwl/devkit' ;
15- import { libraryGenerator } from '@nrwl/js/src/generators/library/library' ;
15+ import type JsLibraryGenerator = require ( '@nrwl/js/src/generators/library/library' ) ;
1616
1717import type NxPluginOpenAPILibGenerator = require( '@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator' ) ;
1818import type NxPluginOpenAPIInitGenerator = require( '@trumbitta/nx-plugin-openapi/src/generators/init/generator' ) ;
@@ -121,76 +121,99 @@ async function generateCodegenProject(
121121 const tasks : GeneratorCallback [ ] = [ ] ;
122122 const nameWithDirectory = `generated-${ options . codegenProject } ` ;
123123 if ( options . useNxPluginOpenAPI ) {
124- ensurePackage ( host , '@trumbitta/nx-plugin-openapi' , '^1.12.1' ) ;
125- tasks . push (
126- addDependenciesToPackageJson (
127- host ,
128- { } ,
129- { '@trumbitta/nx-plugin-openapi' : '^1.12.1' } ,
130- ) ,
131- ) ;
132- const {
133- default : nxPluginOpenAPIGenerator ,
134- } : // eslint-disable-next-line @typescript-eslint/no-var-requires
135- typeof NxPluginOpenAPILibGenerator = require ( '@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator' ) ;
136- const {
137- default : nxPluginOpenAPIInitGenerator ,
138- } : // eslint-disable-next-line @typescript-eslint/no-var-requires
139- typeof NxPluginOpenAPIInitGenerator = require ( '@trumbitta/nx-plugin-openapi/src/generators/init/generator' ) ;
140-
141- tasks . push ( await nxPluginOpenAPIInitGenerator ( host ) ) ;
142-
143- tasks . push (
144- await nxPluginOpenAPIGenerator ( host , {
145- isRemoteSpec : false ,
146- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
147- name : options . codegenProject ! ,
148- directory : 'generated' ,
149- generator : 'typescript-fetch' ,
150- sourceSpecLib : options . swaggerProject ,
151- } ) ,
152- ) ;
153-
154- const configuration = readProjectConfiguration ( host , nameWithDirectory ) ;
155- configuration . targets ??= { } ;
156- const targetConfiguration = configuration . targets ?. [ 'generate-sources' ] ;
157- targetConfiguration . options [ 'sourceSpecPathOrUrl' ] = joinPathFragments (
158- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
159- readProjectConfiguration ( host , options . swaggerProject ! ) . root ,
160- 'swagger.json' ,
161- ) ;
162- targetConfiguration . dependsOn = [ '^swagger' ] ;
163- configuration . targets [ 'codegen' ] = targetConfiguration ;
164- delete configuration . targets [ 'generate-sources' ] ;
165- updateProjectConfiguration ( host , nameWithDirectory , configuration ) ;
124+ await setupOpenAPICodegen ( host , tasks , options , nameWithDirectory ) ;
166125 } else {
167- tasks . push (
168- await libraryGenerator ( host , {
169- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
170- name : options . codegenProject ! ,
171- directory : 'generated' ,
172- buildable : true ,
173- } ) ,
174- ) ;
175- const codegenProjectConfiguration = readProjectConfiguration (
176- host ,
177- nameWithDirectory ,
178- ) ;
179- codegenProjectConfiguration . implicitDependencies ??= [ ] ;
180- codegenProjectConfiguration . implicitDependencies . push (
181- options . swaggerProject ? options . swaggerProject : options . project ,
182- ) ;
183- updateProjectConfiguration (
184- host ,
185- nameWithDirectory ,
186- codegenProjectConfiguration ,
187- ) ;
126+ await setupNxNETCodegen ( tasks , host , options , nameWithDirectory ) ;
188127 }
189128
190129 updateNxJsonForCodegenTargets ( host , options ) ;
191130
192131 return tasks ;
193132}
133+
134+ async function setupOpenAPICodegen (
135+ host : Tree ,
136+ tasks : GeneratorCallback [ ] ,
137+ options : AddSwaggerJsonExecutorSchema ,
138+ nameWithDirectory : string ,
139+ ) {
140+ ensurePackage ( host , '@trumbitta/nx-plugin-openapi' , '^1.12.1' ) ;
141+ tasks . push (
142+ addDependenciesToPackageJson (
143+ host ,
144+ { } ,
145+ { '@trumbitta/nx-plugin-openapi' : '^1.12.1' } ,
146+ ) ,
147+ ) ;
148+ const {
149+ default : nxPluginOpenAPIGenerator ,
150+ } : // eslint-disable-next-line @typescript-eslint/no-var-requires
151+ typeof NxPluginOpenAPILibGenerator = require ( '@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator' ) ;
152+ const {
153+ default : nxPluginOpenAPIInitGenerator ,
154+ } : // eslint-disable-next-line @typescript-eslint/no-var-requires
155+ typeof NxPluginOpenAPIInitGenerator = require ( '@trumbitta/nx-plugin-openapi/src/generators/init/generator' ) ;
156+
157+ tasks . push ( await nxPluginOpenAPIInitGenerator ( host ) ) ;
158+
159+ tasks . push (
160+ await nxPluginOpenAPIGenerator ( host , {
161+ isRemoteSpec : false ,
162+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
163+ name : options . codegenProject ! ,
164+ directory : 'generated' ,
165+ generator : 'typescript-fetch' ,
166+ sourceSpecLib : options . swaggerProject ,
167+ } ) ,
168+ ) ;
169+
170+ const configuration = readProjectConfiguration ( host , nameWithDirectory ) ;
171+ configuration . targets ??= { } ;
172+ const targetConfiguration = configuration . targets ?. [ 'generate-sources' ] ;
173+ targetConfiguration . options [ 'sourceSpecPathOrUrl' ] = joinPathFragments (
174+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
175+ readProjectConfiguration ( host , options . swaggerProject ! ) . root ,
176+ 'swagger.json' ,
177+ ) ;
178+ targetConfiguration . dependsOn = [ '^swagger' ] ;
179+ configuration . targets [ 'codegen' ] = targetConfiguration ;
180+ delete configuration . targets [ 'generate-sources' ] ;
181+ updateProjectConfiguration ( host , nameWithDirectory , configuration ) ;
182+ }
183+
184+ async function setupNxNETCodegen (
185+ tasks : GeneratorCallback [ ] ,
186+ host : Tree ,
187+ options : AddSwaggerJsonExecutorSchema ,
188+ nameWithDirectory : string ,
189+ ) {
190+ const {
191+ libraryGenerator,
192+ } : // eslint-disable-next-line @typescript-eslint/no-var-requires
193+ typeof JsLibraryGenerator = require ( '@nrwl/js/src/generators/library/library' ) ;
194+ tasks . push (
195+ await libraryGenerator ( host , {
196+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
197+ name : options . codegenProject ! ,
198+ directory : 'generated' ,
199+ buildable : true ,
200+ } ) ,
201+ ) ;
202+ const codegenProjectConfiguration = readProjectConfiguration (
203+ host ,
204+ nameWithDirectory ,
205+ ) ;
206+ codegenProjectConfiguration . implicitDependencies ??= [ ] ;
207+ codegenProjectConfiguration . implicitDependencies . push (
208+ options . swaggerProject ? options . swaggerProject : options . project ,
209+ ) ;
210+ updateProjectConfiguration (
211+ host ,
212+ nameWithDirectory ,
213+ codegenProjectConfiguration ,
214+ ) ;
215+ }
216+
194217function updateNxJsonForCodegenTargets (
195218 host : Tree ,
196219 options : AddSwaggerJsonExecutorSchema ,
0 commit comments