fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: add types to cli

Lubos bf567577 d12e1991

+404 -446
-368
packages/openapi-ts-tests/main/test/bin.test.ts
··· 1 - import path from 'node:path'; 2 - 3 - import { sync } from 'cross-spawn'; 4 - import { describe, expect, it } from 'vitest'; 5 - 6 - import { getSpecsPath } from '../../utils'; 7 - 8 - describe('bin', () => { 9 - it('supports required parameters', () => { 10 - const result = sync('node', [ 11 - path.resolve( 12 - __dirname, 13 - '..', 14 - '..', 15 - '..', 16 - 'openapi-ts', 17 - 'bin', 18 - 'index.cjs', 19 - ), 20 - '--input', 21 - path.resolve(getSpecsPath(), 'v3.json'), 22 - '--output', 23 - path.resolve(__dirname, 'generated', 'bin'), 24 - '--client', 25 - '@hey-api/client-fetch', 26 - '--dry-run', 27 - 'true', 28 - ]); 29 - expect(result.error).toBeFalsy(); 30 - expect(result.status).toBe(0); 31 - }); 32 - 33 - it('generates angular client', () => { 34 - const result = sync('node', [ 35 - path.resolve( 36 - __dirname, 37 - '..', 38 - '..', 39 - '..', 40 - 'openapi-ts', 41 - 'bin', 42 - 'index.cjs', 43 - ), 44 - '--input', 45 - path.resolve(getSpecsPath(), 'v3.json'), 46 - '--output', 47 - path.resolve(__dirname, 'generated', 'bin'), 48 - '--client', 49 - 'legacy/angular', 50 - '--dry-run', 51 - 'true', 52 - ]); 53 - expect(result.error).toBeFalsy(); 54 - expect(result.status).toBe(0); 55 - }); 56 - 57 - it('generates axios client', () => { 58 - const result = sync('node', [ 59 - path.resolve( 60 - __dirname, 61 - '..', 62 - '..', 63 - '..', 64 - 'openapi-ts', 65 - 'bin', 66 - 'index.cjs', 67 - ), 68 - '--input', 69 - path.resolve(getSpecsPath(), 'v3.json'), 70 - '--output', 71 - path.resolve(__dirname, 'generated', 'bin'), 72 - '--client', 73 - 'legacy/axios', 74 - '--dry-run', 75 - 'true', 76 - ]); 77 - expect(result.error).toBeFalsy(); 78 - expect(result.status).toBe(0); 79 - }); 80 - 81 - it('generates fetch client', () => { 82 - const result = sync('node', [ 83 - path.resolve( 84 - __dirname, 85 - '..', 86 - '..', 87 - '..', 88 - 'openapi-ts', 89 - 'bin', 90 - 'index.cjs', 91 - ), 92 - '--input', 93 - path.resolve(getSpecsPath(), 'v3.json'), 94 - '--output', 95 - path.resolve(__dirname, 'generated', 'bin'), 96 - '--client', 97 - 'legacy/fetch', 98 - '--dry-run', 99 - 'true', 100 - ]); 101 - expect(result.error).toBeFalsy(); 102 - expect(result.status).toBe(0); 103 - }); 104 - 105 - it('generates node client', () => { 106 - const result = sync('node', [ 107 - path.resolve( 108 - __dirname, 109 - '..', 110 - '..', 111 - '..', 112 - 'openapi-ts', 113 - 'bin', 114 - 'index.cjs', 115 - ), 116 - '--input', 117 - path.resolve(getSpecsPath(), 'v3.json'), 118 - '--output', 119 - path.resolve(__dirname, 'generated', 'bin'), 120 - '--client', 121 - 'legacy/node', 122 - '--dry-run', 123 - 'true', 124 - ]); 125 - expect(result.error).toBeFalsy(); 126 - expect(result.status).toBe(0); 127 - }); 128 - 129 - it('generates xhr client', () => { 130 - const result = sync('node', [ 131 - path.resolve( 132 - __dirname, 133 - '..', 134 - '..', 135 - '..', 136 - 'openapi-ts', 137 - 'bin', 138 - 'index.cjs', 139 - ), 140 - '--input', 141 - path.resolve(getSpecsPath(), 'v3.json'), 142 - '--output', 143 - path.resolve(__dirname, 'generated', 'bin'), 144 - '--client', 145 - 'legacy/xhr', 146 - '--dry-run', 147 - 'true', 148 - ]); 149 - expect(result.error).toBeFalsy(); 150 - expect(result.status).toBe(0); 151 - }); 152 - 153 - it('supports all parameters', () => { 154 - const result = sync('node', [ 155 - path.resolve( 156 - __dirname, 157 - '..', 158 - '..', 159 - '..', 160 - 'openapi-ts', 161 - 'bin', 162 - 'index.cjs', 163 - ), 164 - '--input', 165 - path.resolve(getSpecsPath(), 'v3.json'), 166 - '--output', 167 - path.resolve(__dirname, 'generated', 'bin'), 168 - '--client', 169 - 'legacy/fetch', 170 - '--useOptions', 171 - '--exportCore', 172 - 'true', 173 - '--plugins', 174 - '@hey-api/schemas', 175 - '@hey-api/sdk', 176 - '@hey-api/typescript', 177 - '--dry-run', 178 - 'true', 179 - ]); 180 - expect(result.error).toBeFalsy(); 181 - expect(result.status).toBe(0); 182 - }); 183 - 184 - it('throws error without input', () => { 185 - const result = sync('node', [ 186 - path.resolve( 187 - __dirname, 188 - '..', 189 - '..', 190 - '..', 191 - 'openapi-ts', 192 - 'bin', 193 - 'index.cjs', 194 - ), 195 - '--dry-run', 196 - 'true', 197 - ]); 198 - expect(result.stderr.toString()).toContain('missing input'); 199 - }); 200 - 201 - it('throws error without output', () => { 202 - const result = sync('node', [ 203 - path.resolve( 204 - __dirname, 205 - '..', 206 - '..', 207 - '..', 208 - 'openapi-ts', 209 - 'bin', 210 - 'index.cjs', 211 - ), 212 - '--input', 213 - path.resolve(getSpecsPath(), 'v3.json'), 214 - '--dry-run', 215 - 'true', 216 - ]); 217 - expect(result.stderr.toString()).toContain('missing output'); 218 - }); 219 - 220 - it('throws error with wrong parameters', () => { 221 - const result = sync('node', [ 222 - path.resolve( 223 - __dirname, 224 - '..', 225 - '..', 226 - '..', 227 - 'openapi-ts', 228 - 'bin', 229 - 'index.cjs', 230 - ), 231 - '--input', 232 - path.resolve(getSpecsPath(), 'v3.json'), 233 - '--output', 234 - path.resolve(__dirname, 'generated', 'bin'), 235 - '--unknown', 236 - '--dry-run', 237 - 'true', 238 - ]); 239 - expect(result.stderr.toString()).toContain( 240 - `error: unknown option '--unknown'`, 241 - ); 242 - }); 243 - 244 - it('displays help', () => { 245 - const result = sync('node', [ 246 - path.resolve( 247 - __dirname, 248 - '..', 249 - '..', 250 - '..', 251 - 'openapi-ts', 252 - 'bin', 253 - 'index.cjs', 254 - ), 255 - '--help', 256 - '--dry-run', 257 - 'true', 258 - ]); 259 - expect(result.stdout.toString()).toContain(`Usage: openapi-ts [options]`); 260 - expect(result.stdout.toString()).toContain(`-i, --input <value>`); 261 - expect(result.stdout.toString()).toContain(`-o, --output <value>`); 262 - expect(result.stderr.toString()).toBe(''); 263 - }); 264 - }); 265 - 266 - describe('cli', () => { 267 - it('handles false booleans', () => { 268 - const result = sync('node', [ 269 - path.resolve( 270 - __dirname, 271 - '..', 272 - '..', 273 - '..', 274 - 'openapi-ts', 275 - 'bin', 276 - 'index.cjs', 277 - ), 278 - '--input', 279 - path.resolve(getSpecsPath(), 'v3.json'), 280 - '--output', 281 - path.resolve(__dirname, 'generated', 'bin'), 282 - '--debug', 283 - '--plugins', 284 - '--useOptions', 285 - 'false', 286 - '--dry-run', 287 - 'true', 288 - ]); 289 - const stderr = result.stderr.toString(); 290 - expect(stderr).toMatch(/level: 'debug'/); 291 - expect(stderr).toMatch(/dryRun: true/); 292 - expect(stderr).not.toMatch(/@hey-api\/schemas/); 293 - expect(stderr).not.toMatch(/@hey-api\/sdk/); 294 - expect(stderr).not.toMatch(/@hey-api\/typescript/); 295 - expect(stderr).toMatch(/useOptions: false/); 296 - }); 297 - 298 - it('handles true booleans', () => { 299 - const result = sync('node', [ 300 - path.resolve( 301 - __dirname, 302 - '..', 303 - '..', 304 - '..', 305 - 'openapi-ts', 306 - 'bin', 307 - 'index.cjs', 308 - ), 309 - '--input', 310 - path.resolve(getSpecsPath(), 'v3.json'), 311 - '--output', 312 - path.resolve(__dirname, 'generated', 'bin'), 313 - '--client', 314 - '@hey-api/client-fetch', 315 - '--debug', 316 - '--plugins', 317 - '@hey-api/schemas', 318 - '@hey-api/sdk', 319 - '@hey-api/typescript', 320 - '--useOptions', 321 - 'true', 322 - '--dry-run', 323 - 'true', 324 - ]); 325 - const stderr = result.stderr.toString(); 326 - expect(stderr).toMatch(/level: 'debug'/); 327 - expect(stderr).toMatch(/dryRun: true/); 328 - expect(stderr).toMatch(/@hey-api\/schemas/); 329 - expect(stderr).toMatch(/@hey-api\/sdk/); 330 - expect(stderr).toMatch(/@hey-api\/typescript/); 331 - expect(stderr).toMatch(/useOptions: true/); 332 - }); 333 - 334 - it('handles optional booleans', () => { 335 - const result = sync('node', [ 336 - path.resolve( 337 - __dirname, 338 - '..', 339 - '..', 340 - '..', 341 - 'openapi-ts', 342 - 'bin', 343 - 'index.cjs', 344 - ), 345 - '--input', 346 - path.resolve(getSpecsPath(), 'v3.json'), 347 - '--output', 348 - path.resolve(__dirname, 'generated', 'bin'), 349 - '--client', 350 - '@hey-api/client-fetch', 351 - '--debug', 352 - '--plugins', 353 - '@hey-api/schemas', 354 - '@hey-api/sdk', 355 - '@hey-api/typescript', 356 - '--useOptions', 357 - '--dry-run', 358 - 'true', 359 - ]); 360 - const stderr = result.stderr.toString(); 361 - expect(stderr).toMatch(/level: 'debug'/); 362 - expect(stderr).toMatch(/dryRun: true/); 363 - expect(stderr).toMatch(/@hey-api\/schemas/); 364 - expect(stderr).toMatch(/@hey-api\/sdk/); 365 - expect(stderr).toMatch(/@hey-api\/typescript/); 366 - expect(stderr).toMatch(/useOptions: true/); 367 - }); 368 - });
+23
packages/openapi-ts-tests/main/test/cli.test.ts
··· 1 + import path from 'node:path'; 2 + 3 + import { sync } from 'cross-spawn'; 4 + import { describe, expect, it } from 'vitest'; 5 + 6 + import { getSpecsPath } from '../../utils'; 7 + 8 + const specs = getSpecsPath(); 9 + 10 + describe('bin', () => { 11 + it('openapi-ts works', () => { 12 + const result = sync('openapi-ts', [ 13 + '--input', 14 + path.resolve(specs, 'v3.json'), 15 + '--output', 16 + path.resolve(__dirname, '.gen'), 17 + '--dry-run', 18 + 'true', 19 + ]); 20 + expect(result.error).toBeFalsy(); 21 + expect(result.status).toBe(0); 22 + }); 23 + });
packages/openapi-ts-tests/main/test/hey-api.ts dev/hey-api.ts
+1 -2
packages/openapi-ts/package.json
··· 66 66 "./package.json": "./package.json" 67 67 }, 68 68 "bin": { 69 - "openapi-ts": "./dist/cli.cjs" 69 + "openapi-ts": "./dist/run.cjs" 70 70 }, 71 71 "files": [ 72 - "bin", 73 72 "dist", 74 73 "LICENSE.md", 75 74 "README.md"
+292
packages/openapi-ts/src/__tests__/cli.test.ts
··· 1 + import type { Mock } from 'vitest'; 2 + import { beforeEach, describe, expect, it, vi } from 'vitest'; 3 + 4 + import { runCli } from '~/cli'; 5 + import { createClient } from '~/index'; 6 + 7 + vi.mock('~/index', () => { 8 + const result: Awaited<ReturnType<typeof createClient>> = []; 9 + return { 10 + createClient: vi.fn().mockResolvedValue(result), 11 + }; 12 + }); 13 + const spyExit = vi 14 + .spyOn(process, 'exit') 15 + .mockImplementation(() => ({}) as never); 16 + 17 + const spy = createClient as Mock; 18 + 19 + describe('cli', () => { 20 + beforeEach(() => { 21 + spy.mockClear(); 22 + spyExit.mockClear(); 23 + }); 24 + 25 + it('with default options', async () => { 26 + const originalArgv = process.argv.slice(); 27 + try { 28 + process.argv = [String(process.argv[0]), String(process.argv[1])]; 29 + await runCli(); 30 + } finally { 31 + process.argv = originalArgv; 32 + } 33 + expect(spy).toHaveBeenCalledWith({ 34 + logs: { 35 + file: true, 36 + }, 37 + }); 38 + }); 39 + 40 + it('with minimal options', async () => { 41 + const originalArgv = process.argv.slice(); 42 + try { 43 + process.argv = [ 44 + String(process.argv[0]), 45 + String(process.argv[1]), 46 + '--input', 47 + 'foo.json', 48 + '--output', 49 + 'bar', 50 + ]; 51 + await runCli(); 52 + } finally { 53 + process.argv = originalArgv; 54 + } 55 + expect(spy).toHaveBeenCalledWith({ 56 + input: 'foo.json', 57 + logs: { 58 + file: true, 59 + }, 60 + output: 'bar', 61 + }); 62 + }); 63 + 64 + it('with no plugins', async () => { 65 + const originalArgv = process.argv.slice(); 66 + try { 67 + process.argv = [ 68 + String(process.argv[0]), 69 + String(process.argv[1]), 70 + '--plugins', 71 + ]; 72 + await runCli(); 73 + } finally { 74 + process.argv = originalArgv; 75 + } 76 + expect(spy).toHaveBeenCalledWith({ 77 + logs: { 78 + file: true, 79 + }, 80 + plugins: [], 81 + }); 82 + }); 83 + 84 + it('with plugins', async () => { 85 + const originalArgv = process.argv.slice(); 86 + try { 87 + process.argv = [ 88 + String(process.argv[0]), 89 + String(process.argv[1]), 90 + '--plugins', 91 + 'foo', 92 + ]; 93 + await runCli(); 94 + } finally { 95 + process.argv = originalArgv; 96 + } 97 + expect(spy).toHaveBeenCalledWith({ 98 + logs: { 99 + file: true, 100 + }, 101 + plugins: ['foo'], 102 + }); 103 + }); 104 + 105 + it('with default plugins', async () => { 106 + const originalArgv = process.argv.slice(); 107 + try { 108 + process.argv = [ 109 + String(process.argv[0]), 110 + String(process.argv[1]), 111 + '--client', 112 + 'foo', 113 + ]; 114 + await runCli(); 115 + } finally { 116 + process.argv = originalArgv; 117 + } 118 + expect(spy).toHaveBeenCalledWith({ 119 + logs: { 120 + file: true, 121 + }, 122 + plugins: ['@hey-api/typescript', '@hey-api/sdk', 'foo'], 123 + }); 124 + }); 125 + 126 + describe('logs', () => { 127 + it('debug', async () => { 128 + const originalArgv = process.argv.slice(); 129 + try { 130 + process.argv = [ 131 + String(process.argv[0]), 132 + String(process.argv[1]), 133 + '--debug', 134 + ]; 135 + await runCli(); 136 + } finally { 137 + process.argv = originalArgv; 138 + } 139 + expect(spy).toHaveBeenCalledWith({ 140 + logs: { 141 + file: true, 142 + level: 'debug', 143 + }, 144 + }); 145 + }); 146 + 147 + it('silent', async () => { 148 + const originalArgv = process.argv.slice(); 149 + try { 150 + process.argv = [ 151 + String(process.argv[0]), 152 + String(process.argv[1]), 153 + '--silent', 154 + ]; 155 + await runCli(); 156 + } finally { 157 + process.argv = originalArgv; 158 + } 159 + expect(spy).toHaveBeenCalledWith({ 160 + logs: { 161 + file: true, 162 + level: 'silent', 163 + }, 164 + }); 165 + }); 166 + 167 + it('no log file', async () => { 168 + const originalArgv = process.argv.slice(); 169 + try { 170 + process.argv = [ 171 + String(process.argv[0]), 172 + String(process.argv[1]), 173 + '--no-log-file', 174 + ]; 175 + await runCli(); 176 + } finally { 177 + process.argv = originalArgv; 178 + } 179 + expect(spy).toHaveBeenCalledWith({ 180 + logs: { 181 + file: false, 182 + }, 183 + }); 184 + }); 185 + }); 186 + 187 + it('with all options', async () => { 188 + const originalArgv = process.argv.slice(); 189 + try { 190 + process.argv = [ 191 + String(process.argv[0]), 192 + String(process.argv[1]), 193 + '--client', 194 + 'foo', 195 + '--dry-run', 196 + 'true', 197 + '--experimental-parser', 198 + 'true', 199 + '--file', 200 + 'bar', 201 + '--input', 202 + 'baz', 203 + '--logs', 204 + 'qux', 205 + '--output', 206 + 'quux', 207 + '--plugins', 208 + '--watch', 209 + '--useOptions', 210 + '--exportCore', 211 + ]; 212 + await runCli(); 213 + } finally { 214 + process.argv = originalArgv; 215 + } 216 + expect(spy).toHaveBeenCalledWith({ 217 + configFile: 'bar', 218 + dryRun: true, 219 + experimentalParser: true, 220 + exportCore: true, 221 + input: 'baz', 222 + logs: { 223 + file: true, 224 + path: 'qux', 225 + }, 226 + output: 'quux', 227 + plugins: ['foo'], 228 + useOptions: true, 229 + watch: true, 230 + }); 231 + }); 232 + 233 + it('with false booleans', async () => { 234 + const originalArgv = process.argv.slice(); 235 + try { 236 + process.argv = [ 237 + String(process.argv[0]), 238 + String(process.argv[1]), 239 + '--useOptions', 240 + 'false', 241 + ]; 242 + await runCli(); 243 + } finally { 244 + process.argv = originalArgv; 245 + } 246 + expect(spy).toHaveBeenCalledWith({ 247 + logs: { 248 + file: true, 249 + }, 250 + useOptions: false, 251 + }); 252 + }); 253 + 254 + it('exits when not in watch mode', async () => { 255 + const originalArgv = process.argv.slice(); 256 + try { 257 + process.argv = [String(process.argv[0]), String(process.argv[1])]; 258 + await runCli(); 259 + } finally { 260 + process.argv = originalArgv; 261 + } 262 + expect(spyExit).toHaveBeenCalledWith(0); 263 + }); 264 + 265 + it('does not exit in watch mode', async () => { 266 + spy.mockResolvedValueOnce([ 267 + { 268 + config: { input: [{ watch: { enabled: true } }] }, 269 + }, 270 + ]); 271 + const originalArgv = process.argv.slice(); 272 + try { 273 + process.argv = [String(process.argv[0]), String(process.argv[1])]; 274 + await runCli(); 275 + } finally { 276 + process.argv = originalArgv; 277 + } 278 + expect(spyExit).not.toHaveBeenCalled(); 279 + }); 280 + 281 + it('exits with error code on error', async () => { 282 + spy.mockRejectedValueOnce('Some error'); 283 + const originalArgv = process.argv.slice(); 284 + try { 285 + process.argv = [String(process.argv[0]), String(process.argv[1])]; 286 + await runCli(); 287 + } finally { 288 + process.argv = originalArgv; 289 + } 290 + expect(spyExit).toHaveBeenCalledWith(1); 291 + }); 292 + });
+75 -73
packages/openapi-ts/src/cli.ts
··· 1 - #!/usr/bin/env node 2 - 3 - 'use strict'; 4 - 5 - import { program } from 'commander'; 1 + import type { OptionValues } from 'commander'; 2 + import { Command } from 'commander'; 6 3 7 4 import { createClient } from '~/index'; 8 5 9 6 import pkg from '../package.json' assert { type: 'json' }; 10 7 11 - const params = program 12 - .name(Object.keys(pkg.bin)[0]!) 13 - .usage('[options]') 14 - .version(pkg.version) 15 - .option( 16 - '-c, --client <value>', 17 - 'HTTP client to generate [@hey-api/client-axios, @hey-api/client-fetch, @hey-api/client-next, @hey-api/client-nuxt, legacy/angular, legacy/axios, legacy/fetch, legacy/node, legacy/xhr]', 18 - ) 19 - .option('-d, --debug', 'Set log level to debug') 20 - .option('--dry-run [value]', 'Skip writing files to disk?') 21 - .option( 22 - '-e, --experimental-parser [value]', 23 - 'Opt-in to the experimental parser?', 24 - ) 25 - .option('-f, --file [value]', 'Path to the config file') 26 - .option( 27 - '-i, --input <value>', 28 - 'OpenAPI specification (path, url, or string content)', 29 - ) 30 - .option('-l, --logs [value]', 'Logs folder') 31 - .option('-o, --output <value>', 'Output folder') 32 - .option('-p, --plugins [value...]', "List of plugins you'd like to use") 33 - .option( 34 - '--base [value]', 35 - 'DEPRECATED. Manually set base in OpenAPI config instead of inferring from server value', 36 - ) 37 - .option('-s, --silent', 'Set log level to silent') 38 - .option( 39 - '--no-log-file', 40 - 'Disable writing a log file. Works like --silent but without suppressing console output', 41 - ) 42 - .option( 43 - '-w, --watch [value]', 44 - 'Regenerate the client when the input file changes?', 45 - ) 46 - .option('--exportCore [value]', 'DEPRECATED. Write core files to disk') 47 - .option('--name <value>', 'DEPRECATED. Custom client class name') 48 - .option('--request <value>', 'DEPRECATED. Path to custom request file') 49 - .option( 50 - '--useOptions [value]', 51 - 'DEPRECATED. Use options instead of arguments?', 52 - ) 53 - .parse(process.argv) 54 - .opts(); 55 - 56 - const stringToBoolean = (value: any) => { 57 - if (value === 'true') { 58 - return true; 59 - } 60 - if (value === 'false') { 61 - return false; 62 - } 8 + const stringToBoolean = ( 9 + value: string | undefined, 10 + ): boolean | string | undefined => { 11 + if (value === 'true') return true; 12 + if (value === 'false') return false; 63 13 return value; 64 14 }; 65 15 66 - const processParams = (obj: any, booleanKeys: any) => { 16 + const processParams = ( 17 + obj: OptionValues, 18 + booleanKeys: ReadonlyArray<string>, 19 + ): OptionValues => { 67 20 for (const key of booleanKeys) { 68 21 const value = obj[key]; 69 22 if (typeof value === 'string') { ··· 72 25 obj[key] = parsedValue; 73 26 } 74 27 } 75 - if (obj.file) { 76 - obj.configFile = obj.file; 77 - } 78 28 return obj; 79 29 }; 80 30 81 - async function start() { 82 - let userConfig; 31 + export const runCli = async (): Promise<void> => { 32 + const params = new Command() 33 + .name(Object.keys(pkg.bin)[0]!) 34 + .usage('[options]') 35 + .version(pkg.version) 36 + .option( 37 + '-c, --client <value>', 38 + 'HTTP client to generate [@hey-api/client-axios, @hey-api/client-fetch, @hey-api/client-next, @hey-api/client-nuxt, legacy/angular, legacy/axios, legacy/fetch, legacy/node, legacy/xhr]', 39 + ) 40 + .option('-d, --debug', 'Set log level to debug') 41 + .option('--dry-run [value]', 'Skip writing files to disk?') 42 + .option( 43 + '-e, --experimental-parser [value]', 44 + 'Opt-in to the experimental parser?', 45 + ) 46 + .option('-f, --file [value]', 'Path to the config file') 47 + .option( 48 + '-i, --input <value>', 49 + 'OpenAPI specification (path, url, or string content)', 50 + ) 51 + .option('-l, --logs [value]', 'Logs folder') 52 + .option('-o, --output <value>', 'Output folder') 53 + .option('-p, --plugins [value...]', "List of plugins you'd like to use") 54 + .option( 55 + '--base [value]', 56 + 'DEPRECATED. Manually set base in OpenAPI config instead of inferring from server value', 57 + ) 58 + .option('-s, --silent', 'Set log level to silent') 59 + .option( 60 + '--no-log-file', 61 + 'Disable writing a log file. Works like --silent but without suppressing console output', 62 + ) 63 + .option( 64 + '-w, --watch [value]', 65 + 'Regenerate the client when the input file changes?', 66 + ) 67 + .option('--exportCore [value]', 'DEPRECATED. Write core files to disk') 68 + .option('--name <value>', 'DEPRECATED. Custom client class name') 69 + .option('--request <value>', 'DEPRECATED. Path to custom request file') 70 + .option( 71 + '--useOptions [value]', 72 + 'DEPRECATED. Use options instead of arguments?', 73 + ) 74 + .parse(process.argv) 75 + .opts(); 76 + 77 + let userConfig: Record<string, unknown>; 83 78 84 79 try { 85 80 userConfig = processParams(params, [ 86 81 'dryRun', 87 - 'logFile', 88 82 'experimentalParser', 89 83 'exportCore', 84 + 'logFile', 90 85 'useOptions', 91 86 ]); 92 87 88 + if (userConfig.file) { 89 + userConfig.configFile = userConfig.file; 90 + delete userConfig.file; 91 + } 92 + 93 93 if (params.plugins === true) { 94 94 userConfig.plugins = []; 95 95 } else if (params.plugins) { ··· 99 99 } 100 100 101 101 if (userConfig.client) { 102 - userConfig.plugins.push(userConfig.client); 102 + (userConfig.plugins as Array<string>).push(userConfig.client as string); 103 103 delete userConfig.client; 104 104 } 105 105 ··· 110 110 : {}; 111 111 112 112 if (userConfig.debug || stringToBoolean(process.env.DEBUG)) { 113 - userConfig.logs.level = 'debug'; 113 + (userConfig.logs as Record<string, unknown>).level = 'debug'; 114 + delete userConfig.debug; 114 115 } else if (userConfig.silent) { 115 - userConfig.logs.level = 'silent'; 116 + (userConfig.logs as Record<string, unknown>).level = 'silent'; 117 + delete userConfig.silent; 116 118 } 117 119 118 - userConfig.logs.file = userConfig.logFile; 120 + (userConfig.logs as Record<string, unknown>).file = userConfig.logFile; 119 121 delete userConfig.logFile; 120 122 121 123 if (typeof params.watch === 'string') { 122 124 userConfig.watch = Number.parseInt(params.watch, 10); 123 125 } 124 126 125 - if (!Object.keys(userConfig.logs).length) { 127 + if (!Object.keys(userConfig.logs as Record<string, unknown>).length) { 126 128 delete userConfig.logs; 127 129 } 128 130 129 - const context = await createClient(userConfig); 131 + const context = await createClient( 132 + userConfig as unknown as Required<Parameters<typeof createClient>>[0], 133 + ); 130 134 if ( 131 135 !context[0]?.config.input.some( 132 136 (input) => input.watch && input.watch.enabled, ··· 137 141 } catch { 138 142 process.exit(1); 139 143 } 140 - } 141 - 142 - start(); 144 + };
+2 -1
packages/openapi-ts/src/generate/legacy/output.ts
··· 65 65 if ( 66 66 !isLegacyClient(config) && 67 67 'bundle' in clientPlugin.config && 68 - clientPlugin.config.bundle 68 + clientPlugin.config.bundle && 69 + !config.dryRun 69 70 ) { 70 71 const meta: ProjectRenderMeta = { 71 72 importFileExtension: config.output.importFileExtension,
+5 -1
packages/openapi-ts/src/generate/output.ts
··· 21 21 }; 22 22 23 23 const client = getClientPlugin(context.config); 24 - if ('bundle' in client.config && client.config.bundle) { 24 + if ( 25 + 'bundle' in client.config && 26 + client.config.bundle && 27 + !context.config.dryRun 28 + ) { 25 29 // not proud of this one 26 30 // @ts-expect-error 27 31 context.config._FRAGILE_CLIENT_BUNDLE_RENAMED = generateClientBundle({
+5
packages/openapi-ts/src/run.ts
··· 1 + #!/usr/bin/env node 2 + 3 + import { runCli } from '~/cli'; 4 + 5 + runCli();
+1 -1
packages/openapi-ts/tsdown.config.ts
··· 29 29 }, 30 30 clean: true, 31 31 dts: true, 32 - entry: ['./src/{index,internal,cli}.ts'], 32 + entry: ['./src/{index,internal,run}.ts'], 33 33 format: ['cjs', 'esm'], 34 34 minify: !options.watch, 35 35 onSuccess: async () => {