@hey-api/openapi-ts
Version:
🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.
1 lines • 9.91 kB
Source Map (JSON)
{"version":3,"file":"run.cjs","names":["Command","pkg.bin","pkg.version","userConfig: Record<string, unknown>","createClient"],"sources":["../package.json","../src/cli.ts","../src/run.ts"],"sourcesContent":["{\n \"name\": \"@hey-api/openapi-ts\",\n \"version\": \"0.86.11\",\n \"description\": \"🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more.\",\n \"homepage\": \"https://heyapi.dev/\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/hey-api/openapi-ts.git\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/hey-api/openapi-ts/issues\"\n },\n \"license\": \"MIT\",\n \"author\": {\n \"email\": \"lubos@heyapi.dev\",\n \"name\": \"Hey API\",\n \"url\": \"https://heyapi.dev\"\n },\n \"funding\": \"https://github.com/sponsors/hey-api\",\n \"keywords\": [\n \"angular\",\n \"axios\",\n \"codegen\",\n \"fetch\",\n \"generator\",\n \"http\",\n \"javascript\",\n \"json\",\n \"next\",\n \"next.js\",\n \"node\",\n \"nuxt\",\n \"ofetch\",\n \"openapi\",\n \"rest\",\n \"swagger\",\n \"typescript\",\n \"xhr\",\n \"yaml\"\n ],\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.cts\",\n \"default\": \"./dist/index.cjs\"\n }\n },\n \"./internal\": {\n \"import\": {\n \"types\": \"./dist/internal.d.ts\",\n \"default\": \"./dist/internal.js\"\n },\n \"require\": {\n \"types\": \"./dist/internal.d.cts\",\n \"default\": \"./dist/internal.cjs\"\n }\n },\n \"./package.json\": \"./package.json\"\n },\n \"bin\": {\n \"openapi-ts\": \"./bin/run.js\"\n },\n \"files\": [\n \"bin\",\n \"dist\",\n \"LICENSE.md\",\n \"README.md\"\n ],\n \"scripts\": {\n \"build\": \"tsdown && pnpm check-exports\",\n \"check-exports\": \"attw --pack . --profile node16\",\n \"dev\": \"tsdown --watch\",\n \"handlebars\": \"node src/legacy/handlebars/handlebars.cjs\",\n \"prepublishOnly\": \"pnpm build\",\n \"test:coverage\": \"vitest run --coverage\",\n \"test:update\": \"vitest watch --update\",\n \"test:watch\": \"vitest watch\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"engines\": {\n \"node\": \">=20.19.0\"\n },\n \"dependencies\": {\n \"@hey-api/codegen-core\": \"workspace:^0.3.2\",\n \"@hey-api/json-schema-ref-parser\": \"1.2.1\",\n \"ansi-colors\": \"4.1.3\",\n \"c12\": \"3.3.1\",\n \"color-support\": \"1.1.3\",\n \"commander\": \"14.0.1\",\n \"handlebars\": \"4.7.8\",\n \"open\": \"10.2.0\",\n \"semver\": \"7.7.2\"\n },\n \"peerDependencies\": {\n \"typescript\": \">=5.5.3\"\n },\n \"devDependencies\": {\n \"@angular/common\": \"19.2.15\",\n \"@angular/compiler\": \"19.2.15\",\n \"@angular/compiler-cli\": \"19.2.15\",\n \"@angular/core\": \"19.2.15\",\n \"@angular/platform-browser\": \"19.2.15\",\n \"@angular/platform-browser-dynamic\": \"19.2.15\",\n \"@angular/router\": \"19.2.15\",\n \"@config/vite-base\": \"workspace:*\",\n \"@types/bun\": \"1.3.1\",\n \"@types/cross-spawn\": \"6.0.6\",\n \"@types/semver\": \"7.7.1\",\n \"axios\": \"1.8.2\",\n \"cross-spawn\": \"7.0.6\",\n \"eslint\": \"9.17.0\",\n \"glob\": \"11.0.3\",\n \"nuxt\": \"3.14.1592\",\n \"ofetch\": \"1.4.1\",\n \"prettier\": \"3.4.2\",\n \"rxjs\": \"7.8.2\",\n \"typescript\": \"5.9.3\",\n \"vue\": \"3.5.13\",\n \"yaml\": \"2.8.0\",\n \"zone.js\": \"0.15.1\"\n }\n}\n","import type { OptionValues } from 'commander';\nimport { Command } from 'commander';\n\nimport { createClient } from '~/index';\n\nimport pkg from '../package.json' assert { type: 'json' };\n\nconst stringToBoolean = (\n value: string | undefined,\n): boolean | string | undefined => {\n if (value === 'true') return true;\n if (value === 'false') return false;\n return value;\n};\n\nconst processParams = (\n obj: OptionValues,\n booleanKeys: ReadonlyArray<string>,\n): OptionValues => {\n for (const key of booleanKeys) {\n const value = obj[key];\n if (typeof value === 'string') {\n const parsedValue = stringToBoolean(value);\n delete obj[key];\n obj[key] = parsedValue;\n }\n }\n return obj;\n};\n\nexport const runCli = async (): Promise<void> => {\n const params = new Command()\n .name(Object.keys(pkg.bin)[0]!)\n .usage('[options]')\n .version(pkg.version)\n .option(\n '-c, --client <value>',\n '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]',\n )\n .option('-d, --debug', 'Set log level to debug')\n .option('--dry-run [value]', 'Skip writing files to disk?')\n .option(\n '-e, --experimental-parser [value]',\n 'Opt-in to the experimental parser?',\n )\n .option('-f, --file [value]', 'Path to the config file')\n .option(\n '-i, --input <value>',\n 'OpenAPI specification (path, url, or string content)',\n )\n .option('-l, --logs [value]', 'Logs folder')\n .option('-o, --output <value>', 'Output folder')\n .option('-p, --plugins [value...]', \"List of plugins you'd like to use\")\n .option(\n '--base [value]',\n 'DEPRECATED. Manually set base in OpenAPI config instead of inferring from server value',\n )\n .option('-s, --silent', 'Set log level to silent')\n .option(\n '--no-log-file',\n 'Disable writing a log file. Works like --silent but without suppressing console output',\n )\n .option(\n '-w, --watch [value]',\n 'Regenerate the client when the input file changes?',\n )\n .option('--exportCore [value]', 'DEPRECATED. Write core files to disk')\n .option('--name <value>', 'DEPRECATED. Custom client class name')\n .option('--request <value>', 'DEPRECATED. Path to custom request file')\n .option(\n '--useOptions [value]',\n 'DEPRECATED. Use options instead of arguments?',\n )\n .parse(process.argv)\n .opts();\n\n let userConfig: Record<string, unknown>;\n\n try {\n userConfig = processParams(params, [\n 'dryRun',\n 'experimentalParser',\n 'exportCore',\n 'logFile',\n 'useOptions',\n ]);\n\n if (userConfig.file) {\n userConfig.configFile = userConfig.file;\n delete userConfig.file;\n }\n\n if (params.plugins === true) {\n userConfig.plugins = [];\n } else if (params.plugins) {\n userConfig.plugins = params.plugins;\n } else if (userConfig.client) {\n userConfig.plugins = ['@hey-api/typescript', '@hey-api/sdk'];\n }\n\n if (userConfig.client) {\n (userConfig.plugins as Array<string>).push(userConfig.client as string);\n delete userConfig.client;\n }\n\n userConfig.logs = userConfig.logs\n ? {\n path: userConfig.logs,\n }\n : {};\n\n if (userConfig.debug || stringToBoolean(process.env.DEBUG)) {\n (userConfig.logs as Record<string, unknown>).level = 'debug';\n delete userConfig.debug;\n } else if (userConfig.silent) {\n (userConfig.logs as Record<string, unknown>).level = 'silent';\n delete userConfig.silent;\n }\n\n (userConfig.logs as Record<string, unknown>).file = userConfig.logFile;\n delete userConfig.logFile;\n\n if (typeof params.watch === 'string') {\n userConfig.watch = Number.parseInt(params.watch, 10);\n }\n\n if (!Object.keys(userConfig.logs as Record<string, unknown>).length) {\n delete userConfig.logs;\n }\n\n const context = await createClient(\n userConfig as unknown as Required<Parameters<typeof createClient>>[0],\n );\n if (\n !context[0]?.config.input.some(\n (input) => input.watch && input.watch.enabled,\n )\n ) {\n process.exit(0);\n }\n } catch {\n process.exit(1);\n }\n};\n","#!/usr/bin/env node\n\nimport { runCli } from '~/cli';\n\nrunCli();\n"],"mappings":";oHAEa,YAiEJ,CACL,aAAc,eACf,CC9DH,MAAM,EACJ,GAEI,IAAU,OAAe,GACzB,IAAU,QAAgB,GACvB,EAGH,GACJ,EACA,IACiB,CACjB,IAAK,IAAM,KAAO,EAAa,CAC7B,IAAM,EAAQ,EAAI,GAClB,GAAI,OAAO,GAAU,SAAU,CAC7B,IAAM,EAAc,EAAgB,EAAM,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