UNPKG

@kubb/cli

Version:

Command-line interface for Kubb, enabling easy generation of TypeScript, React-Query, Zod, and other code from OpenAPI specifications.

125 lines (123 loc) 4.43 kB
const require_chunk = require('./chunk-CNbaEX1y.cjs'); let citty = require("citty"); let node_child_process = require("node:child_process"); let node_path = require("node:path"); node_path = require_chunk.__toESM(node_path); let node_process = require("node:process"); node_process = require_chunk.__toESM(node_process); let node_url = require("node:url"); let node_util = require("node:util"); let _clack_prompts = require("@clack/prompts"); _clack_prompts = require_chunk.__toESM(_clack_prompts); //#region src/commands/agent/start.ts const args = { config: { type: "string", description: "Path to the Kubb config", alias: "c" }, port: { type: "string", description: "Port for the server. If not specified, an available port is automatically selected.", alias: "p" }, host: { type: "string", description: "Host for the server", default: "localhost" }, "no-cache": { type: "boolean", description: "Disable session caching", default: false }, "allow-write": { type: "boolean", description: "Allow writing generated files to the filesystem. When not set, no files are written and the config patch is not persisted.", default: false }, "allow-all": { type: "boolean", description: "Grant all permissions (implies --allow-write).", default: false } }; async function startServer({ port, host, configPath, noCache, allowWrite, allowAll }) { try { try { node_process.loadEnvFile(); } catch {} const agentPkgPath = (0, node_url.fileURLToPath)({}.resolve("@kubb/agent/package.json")); const agentDir = node_path.default.dirname(agentPkgPath); const serverPath = node_path.default.join(agentDir, ".output", "server", "index.mjs"); const PORT = node_process.env.PORT || (port === 0 ? "3000" : String(port)); const HOST = node_process.env.HOST || host || "0.0.0.0"; const KUBB_AGENT_ROOT = node_process.env.KUBB_AGENT_ROOT || node_process.cwd(); const KUBB_AGENT_CONFIG = node_process.env.KUBB_AGENT_CONFIG || configPath || "kubb.config.ts"; const KUBB_AGENT_NO_CACHE = noCache ? "true" : "false"; const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? "true" : node_process.env.KUBB_AGENT_ALLOW_WRITE ?? "false"; const KUBB_AGENT_ALLOW_ALL = allowAll ? "true" : node_process.env.KUBB_AGENT_ALLOW_ALL ?? "false"; const env = { PORT, HOST, KUBB_AGENT_ROOT, KUBB_AGENT_CONFIG, KUBB_AGENT_NO_CACHE, KUBB_AGENT_ALLOW_WRITE, KUBB_AGENT_ALLOW_ALL, KUBB_AGENT_TOKEN: node_process.env.KUBB_AGENT_TOKEN, KUBB_AGENT_RETRY_TIMEOUT: node_process.env.KUBB_AGENT_RETRY_TIMEOUT || "30000", KUBB_STUDIO_URL: node_process.env.KUBB_STUDIO_URL || "https://studio.kubb.dev" }; _clack_prompts.log.step((0, node_util.styleText)("cyan", "Starting agent server...")); _clack_prompts.log.info((0, node_util.styleText)("dim", `Config: ${KUBB_AGENT_CONFIG}`)); _clack_prompts.log.info((0, node_util.styleText)("dim", `Host: ${HOST}`)); _clack_prompts.log.info((0, node_util.styleText)("dim", `Port: ${PORT}`)); if (noCache) _clack_prompts.log.info((0, node_util.styleText)("dim", "Session caching: disabled")); if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) _clack_prompts.log.warn((0, node_util.styleText)("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable.")); (0, node_child_process.spawn)("node", [serverPath], { env: { ...node_process.env, ...env }, stdio: "inherit", cwd: node_process.cwd() }); } catch (error) { console.error("Failed to start agent server:", error); node_process.exit(1); } } const command = (0, citty.defineCommand)({ meta: { name: "start", description: "Start the Agent server" }, args, async run(commandContext) { const { args } = commandContext; try { const configPath = node_path.default.resolve(node_process.cwd(), args.config || "kubb.config.ts"); const port = args.port ? Number.parseInt(args.port, 10) : 0; const host = args.host; const noCache = args["no-cache"]; const allowWrite = args["allow-write"]; const allowAll = args["allow-all"]; await startServer({ port, host, configPath, noCache, allowWrite, allowAll }); } catch (error) { _clack_prompts.log.error((0, node_util.styleText)("red", "Failed to start agent server")); console.error(error); node_process.exit(1); } } }); //#endregion exports.default = command; //# sourceMappingURL=start-lrn1-P52.cjs.map