@@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
22import chalk from 'chalk' ;
33import { exec , spawn } from 'child_process' ;
44import { Command } from 'commander' ;
5+ import * as fs from 'fs' ;
56import { COMMANDER_PROGRAM , LOGGER } from '../constants' ;
67import { GeneratorService } from './generator.service' ;
78import { VersionManagerService } from './version-manager.service' ;
@@ -139,14 +140,21 @@ export class PassThroughService {
139140 ] . join ( ' ' ) ;
140141 }
141142
142- const customGenerator = this . program . opts ( ) ?. customGenerator ;
143+ const customGenerator =
144+ this . program . opts ( ) ?. customGenerator ||
145+ this . getCustomGeneratorFromArgs ( ) ;
143146 const cliPath = this . versionManager . filePath ( ) ;
144147
145- const subCmd = customGenerator
146- ? `-cp "${ [ cliPath , customGenerator ] . join (
147- this . isWin ( ) ? ';' : ':'
148- ) } " org.openapitools.codegen.OpenAPIGenerator`
149- : `-jar "${ cliPath } "` ;
148+ let subCmd : string ;
149+ if ( customGenerator ) {
150+ subCmd = fs . existsSync ( cliPath )
151+ ? `-cp "${ [ cliPath , customGenerator ] . join (
152+ this . isWin ( ) ? ';' : ':'
153+ ) } " org.openapitools.codegen.OpenAPIGenerator`
154+ : `-jar "${ customGenerator } "` ;
155+ } else {
156+ subCmd = `-jar "${ cliPath } "` ;
157+ }
150158
151159 return [ 'java' , process . env [ 'JAVA_OPTS' ] , subCmd ]
152160 . filter ( ( str ) : str is string => str != null && typeof str === 'string' )
@@ -157,5 +165,18 @@ export class PassThroughService {
157165 console . log ( chalk . cyanBright ( cmd . helpInformation ( ) ) ) ;
158166 }
159167
168+ private getCustomGeneratorFromArgs ( ) : string | undefined {
169+ for ( let i = 0 ; i < process . argv . length ; i ++ ) {
170+ const arg = process . argv [ i ] ;
171+ if ( arg === '--custom-generator' && i + 1 < process . argv . length ) {
172+ return process . argv [ i + 1 ] ;
173+ }
174+ if ( arg . startsWith ( '--custom-generator=' ) ) {
175+ return arg . substring ( '--custom-generator=' . length ) ;
176+ }
177+ }
178+ return undefined ;
179+ }
180+
160181 private isWin = ( ) => process . platform === 'win32' ;
161182}
0 commit comments