@hey-api/openapi-ts
Version:
🌀 OpenAPI to TypeScript codegen. Production-ready SDKs, Zod schemas, TanStack Query hooks, and 20+ plugins. Used by Vercel, OpenCode, and PayPal.
69 lines (63 loc) • 2.83 kB
JavaScript
const require_openApi = require('./openApi-BwUPqtP_.cjs');
const require_src = require('./src-hU76ergi.cjs');
let commander = require("commander");
//#region package.json
var version = "0.90.2";
var bin = { "openapi-ts": "./bin/run.js" };
//#endregion
//#region src/cli.ts
const stringToBoolean = (value) => {
if (value === "true") return true;
if (value === "false") return false;
return value;
};
const processParams = (obj, booleanKeys) => {
for (const key of booleanKeys) {
const value = obj[key];
if (typeof value === "string") {
const parsedValue = stringToBoolean(value);
delete obj[key];
obj[key] = parsedValue;
}
}
return obj;
};
const runCli = async () => {
const params = new commander.Command().name(Object.keys(bin)[0]).usage("[options]").version(version).option("-c, --client <value>", "HTTP client to generate").option("-d, --debug", "Set log level to debug").option("--dry-run [value]", "Skip writing files to disk?").option("-f, --file [value]", "Path to the config file").option("-i, --input <value>", "OpenAPI specification (path, url, or string content)").option("-l, --logs [value]", "Logs folder").option("-o, --output <value>", "Output folder").option("-p, --plugins [value...]", "List of plugins you'd like to use").option("-s, --silent", "Set log level to silent").option("--no-log-file", "Disable writing a log file. Works like --silent but without suppressing console output").option("-w, --watch [value]", "Regenerate the client when the input file changes?").parse(process.argv).opts();
let userConfig;
try {
userConfig = processParams(params, ["dryRun", "logFile"]);
if (userConfig.file) {
userConfig.configFile = userConfig.file;
delete userConfig.file;
}
if (params.plugins === true) userConfig.plugins = [];
else if (params.plugins) userConfig.plugins = params.plugins;
else if (userConfig.client) userConfig.plugins = ["@hey-api/typescript", "@hey-api/sdk"];
if (userConfig.client) {
userConfig.plugins.push(userConfig.client);
delete userConfig.client;
}
userConfig.logs = userConfig.logs ? { path: userConfig.logs } : {};
if (userConfig.debug) {
userConfig.logs.level = "debug";
delete userConfig.debug;
} else if (userConfig.silent) {
userConfig.logs.level = "silent";
delete userConfig.silent;
}
userConfig.logs.file = userConfig.logFile;
delete userConfig.logFile;
if (typeof params.watch === "string") userConfig.watch = Number.parseInt(params.watch, 10);
if (!Object.keys(userConfig.logs).length) delete userConfig.logs;
if (!(await require_src.createClient(userConfig))[0]?.config.input.some((input) => input.watch && input.watch.enabled)) process.exit(0);
} catch {
process.exit(1);
}
};
//#endregion
//#region src/run.ts
runCli();
//#endregion
//# sourceMappingURL=run.cjs.map