UNPKG

@hey-api/openapi-ts

Version:

🌀 OpenAPI to TypeScript codegen. Production-grade SDKs, Zod schemas, TanStack Query hooks, and 20+ plugins. Used by Vercel, OpenCode, and PayPal.

1 lines • 5.19 kB
{"version":3,"file":"run.mjs","names":["pkg.bin","pkg.version"],"sources":["../package.json","../src/cli/adapter.ts","../src/cli/index.ts","../src/run.ts"],"sourcesContent":["","import type { ToArray } from '@hey-api/types';\n\nimport type { UserConfig } from '../config/types';\nimport type { CliOptions } from './schema';\n\nexport function cliToConfig(cli: CliOptions): Partial<UserConfig> {\n const config: Partial<UserConfig> = {};\n\n if (cli.input) config.input = cli.input;\n if (cli.output) config.output = cli.output;\n if (cli.file) config.configFile = cli.file;\n if (cli.dryRun !== undefined) config.dryRun = cli.dryRun;\n\n const plugins: ToArray<UserConfig['plugins']> = [];\n if (cli.plugins instanceof Array && cli.plugins.length) {\n plugins.push(...cli.plugins);\n }\n if (cli.client) plugins.push(cli.client);\n if (plugins.length) config.plugins = plugins;\n\n if (cli.debug || cli.silent || cli.logs || cli.logFile === false) {\n config.logs = {\n ...(cli.logs && { path: cli.logs }),\n ...(cli.debug && { level: 'debug' as const }),\n ...(cli.silent && { level: 'silent' as const }),\n ...(cli.logFile === false && { file: false }),\n };\n }\n\n if (cli.watch !== undefined) {\n if (typeof cli.watch === 'string') {\n config.watch = Number.parseInt(cli.watch, 10);\n } else {\n config.watch = cli.watch;\n }\n }\n\n return config;\n}\n","import { isEnvironment } from '@hey-api/shared';\nimport { Command, CommanderError } from 'commander';\n\nimport pkg from '../../package.json';\nimport { createClient } from '../index';\nimport { cliToConfig } from './adapter';\n\nconst binName = Object.keys(pkg.bin)[0]!;\n\nconst program = new Command()\n .name(binName)\n .description('Generate TypeScript code from OpenAPI specifications')\n .version(isEnvironment('development') ? '[DEVELOPMENT]' : pkg.version);\n\nprogram\n .option('-i, --input <path...>', 'OpenAPI specification (path, URL, or string)')\n .option('-o, --output <path...>', 'Output folder(s)')\n .option('-c, --client <name>', 'HTTP client to generate')\n .option('-p, --plugins [names...]', 'Plugins to use')\n .option('-f, --file <path>', 'Path to config file')\n .option('-d, --debug', 'Enable debug logging')\n .option('-s, --silent', 'Suppress all output')\n .option('-l, --logs <path>', 'Logs folder path')\n .option('--no-log-file', 'Disable log file output')\n .option('--dry-run', 'Skip writing files')\n .option('-w, --watch [interval]', 'Watch for changes')\n .action(async (options) => {\n const config = cliToConfig(options);\n\n const context = await createClient(config as Parameters<typeof createClient>[0]);\n\n const hasActiveWatch = context[0]?.config.input.some((input) => input.watch?.enabled);\n\n if (!hasActiveWatch) {\n process.exit(0);\n }\n });\n\nexport async function runCli(): Promise<void> {\n try {\n await program.parseAsync(process.argv);\n } catch (error) {\n if (error instanceof CommanderError && 'code' in error) {\n if (error.code === 'commander.optionMissingArgument') {\n console.error(`\\nMissing required argument. Run '${binName} --help' for usage.\\n`);\n } else if (error.code === 'commander.unknownOption') {\n console.error(`\\nUnknown option. Run '${binName} --help' for available options.\\n`);\n }\n\n process.exit(error.exitCode);\n }\n\n console.error('Unexpected error:', error);\n process.exit(1);\n }\n}\n","#!/usr/bin/env node\n\nimport { runCli } from './cli';\n\nrunCli();\n"],"mappings":";;;;;;;;;ACKA,SAAgB,YAAY,KAAsC;CAChE,MAAM,SAA8B,CAAC;CAErC,IAAI,IAAI,OAAO,OAAO,QAAQ,IAAI;CAClC,IAAI,IAAI,QAAQ,OAAO,SAAS,IAAI;CACpC,IAAI,IAAI,MAAM,OAAO,aAAa,IAAI;CACtC,IAAI,IAAI,WAAW,KAAA,GAAW,OAAO,SAAS,IAAI;CAElD,MAAM,UAA0C,CAAC;CACjD,IAAI,IAAI,mBAAmB,SAAS,IAAI,QAAQ,QAC9C,QAAQ,KAAK,GAAG,IAAI,OAAO;CAE7B,IAAI,IAAI,QAAQ,QAAQ,KAAK,IAAI,MAAM;CACvC,IAAI,QAAQ,QAAQ,OAAO,UAAU;CAErC,IAAI,IAAI,SAAS,IAAI,UAAU,IAAI,QAAQ,IAAI,YA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