Skip to content

Commit 99c2351

Browse files
committed
feat(custom generators): added '-custom-generator' parameter fixes OpenAPITools#237
1 parent c733631 commit 99c2351

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

apps/generator-cli/src/app/services/pass-trough.service.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,24 @@ describe('PassTroughService', () => {
175175
)
176176
})
177177

178+
it('can delegate with custom jar', () => {
179+
delete process.env['JAVA_OPTS']
180+
const newCmdMock = {...cmdMock};
181+
const args = [...newCmdMock.args];
182+
newCmdMock.args = [...newCmdMock.args, '-custom-generator=../some/custom.jar'];
183+
commandMock.commands[cmd].action(newCmdMock)
184+
const cpDelimiter = process.platform === "win32" ? ';' : ':';
185+
expect(childProcess.spawn).toHaveBeenNthCalledWith(
186+
1,
187+
`java -cp "${['../some/custom.jar', '/some/path/to/4.2.1.jar'].join(cpDelimiter)}" org.openapitools.codegen.OpenAPIGenerator`,
188+
[cmd, ...args],
189+
{
190+
stdio: 'inherit',
191+
shell: true
192+
}
193+
)
194+
})
195+
178196
if (cmd === 'help') {
179197
it('prints the help info and does not delegate, if args length = 0', () => {
180198
childProcess.spawn.mockReset()

apps/generator-cli/src/app/services/pass-trough.service.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ export class PassTroughService {
4949

5050
}
5151

52-
public passTrough = (args: string[] = []) => spawn(this.cmd(), args, {
52+
public passTrough = (args: string[] = []) => spawn(this.cmd(this.processCustomJarParam(args)), args, {
5353
stdio: 'inherit',
5454
shell: true
5555
}).on('exit', process.exit);
5656

57+
private processCustomJarParam = (args: string[]): string => {
58+
const jarOptionIndex = args.findIndex(e => e.startsWith('-custom-generator'));
59+
return jarOptionIndex < 0 ? '' : args.splice(jarOptionIndex, 1)[0].split('=')[1];
60+
}
61+
5762
private getCommands = async (): Promise<[string, string | undefined][]> => {
5863

5964
const [help, completion] = (await Promise.all([
@@ -85,8 +90,13 @@ export class PassTroughService {
8590
});
8691
});
8792

88-
private cmd() {
89-
return ['java', process.env['JAVA_OPTS'], `-jar "${this.versionManager.filePath()}"`].filter(isString).join(' ');
93+
private cmd(customJarPath: string = '') {
94+
const cliPath = this.versionManager.filePath();
95+
const cpDelimiter = process.platform === "win32" ? ';' : ':';
96+
const subCmd = customJarPath
97+
? `-cp "${[customJarPath, cliPath].join(cpDelimiter)}" org.openapitools.codegen.OpenAPIGenerator`
98+
: `-jar "${cliPath}"`;
99+
return ['java', process.env['JAVA_OPTS'], subCmd].filter(isString).join(' ');
90100
}
91101

92102
}

0 commit comments

Comments
 (0)