@@ -6,13 +6,17 @@ import {
66 joinPathFragments ,
77 ProjectConfiguration ,
88 readProjectConfiguration ,
9- readWorkspaceConfiguration ,
9+ readNxJson ,
1010 Tree ,
1111 updateProjectConfiguration ,
12- updateWorkspaceConfiguration ,
12+ updateNxJson ,
13+ addDependenciesToPackageJson ,
1314} from '@nrwl/devkit' ;
1415import { libraryGenerator } from '@nrwl/js/src/generators/library/library' ;
1516
17+ import type NxPluginOpenAPILibGenerator = require( '@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator' ) ;
18+ import type NxPluginOpenAPIInitGenerator = require( '@trumbitta/nx-plugin-openapi/src/generators/init/generator' ) ;
19+
1620import { getSwaggerExecutorConfiguration } from '../../models/swagger-executor-configuration' ;
1721import { AddSwaggerJsonExecutorSchema } from './schema' ;
1822
@@ -118,14 +122,21 @@ async function generateCodegenProject(
118122 const nameWithDirectory = `generated-${ options . codegenProject } ` ;
119123 if ( options . useNxPluginOpenAPI ) {
120124 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+ ) ;
121132 const {
122133 default : nxPluginOpenAPIGenerator ,
123134 } : // eslint-disable-next-line @typescript-eslint/no-var-requires
124- typeof import ( '@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator' ) = require ( '@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator' ) ;
135+ typeof NxPluginOpenAPILibGenerator = require ( '@trumbitta/nx-plugin-openapi/src/generators/api-lib/generator' ) ;
125136 const {
126137 default : nxPluginOpenAPIInitGenerator ,
127138 } : // eslint-disable-next-line @typescript-eslint/no-var-requires
128- typeof import ( '@trumbitta/nx-plugin-openapi/src/generators/init/generator' ) = require ( '@trumbitta/nx-plugin-openapi/src/generators/init/generator' ) ;
139+ typeof NxPluginOpenAPIInitGenerator = require ( '@trumbitta/nx-plugin-openapi/src/generators/init/generator' ) ;
129140
130141 tasks . push ( await nxPluginOpenAPIInitGenerator ( host ) ) ;
131142
@@ -176,7 +187,19 @@ async function generateCodegenProject(
176187 ) ;
177188 }
178189
179- const wc = readWorkspaceConfiguration ( host ) ;
190+ updateNxJsonForCodegenTargets ( host , options ) ;
191+
192+ return tasks ;
193+ }
194+ function updateNxJsonForCodegenTargets (
195+ host : Tree ,
196+ options : AddSwaggerJsonExecutorSchema ,
197+ ) {
198+ const wc = readNxJson ( host ) ;
199+
200+ if ( ! wc ) {
201+ return ;
202+ }
180203
181204 const cacheableOperations : string [ ] | null =
182205 wc . tasksRunnerOptions ?. default ?. options ?. cacheableOperations ;
@@ -190,7 +213,5 @@ async function generateCodegenProject(
190213 wc . targetDefaults [ 'build' ] . dependsOn ??= [ ] ;
191214 wc . targetDefaults [ 'build' ] . dependsOn . push ( ...newBuildDeps ) ;
192215
193- updateWorkspaceConfiguration ( host , wc ) ;
194-
195- return tasks ;
216+ updateNxJson ( host , wc ) ;
196217}
0 commit comments