UNPKG

@kubb/cli

Version:

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

122 lines (120 loc) 3.96 kB
import { t as __name } from "./chunk-DKWOrOAv.js"; import { defineCommand } from "citty"; import { spawn } from "node:child_process"; import path from "node:path"; import * as process$1 from "node:process"; import { fileURLToPath } from "node:url"; import { styleText } from "node:util"; import * as clack from "@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 { process$1.loadEnvFile(); } catch {} const agentPkgPath = fileURLToPath(import.meta.resolve("@kubb/agent/package.json")); const agentDir = path.dirname(agentPkgPath); const serverPath = path.join(agentDir, ".output", "server", "index.mjs"); const PORT = process$1.env.PORT || (port === 0 ? "3000" : String(port)); const HOST = process$1.env.HOST || host || "0.0.0.0"; const KUBB_AGENT_ROOT = process$1.env.KUBB_AGENT_ROOT || process$1.cwd(); const KUBB_AGENT_CONFIG = process$1.env.KUBB_AGENT_CONFIG || configPath || "kubb.config.ts"; const KUBB_AGENT_NO_CACHE = noCache ? "true" : "false"; const KUBB_AGENT_ALLOW_WRITE = allowAll || allowWrite ? "true" : process$1.env.KUBB_AGENT_ALLOW_WRITE ?? "false"; const KUBB_AGENT_ALLOW_ALL = allowAll ? "true" : process$1.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: process$1.env.KUBB_AGENT_TOKEN, KUBB_AGENT_RETRY_TIMEOUT: process$1.env.KUBB_AGENT_RETRY_TIMEOUT || "30000", KUBB_STUDIO_URL: process$1.env.KUBB_STUDIO_URL || "https://studio.kubb.dev" }; clack.log.step(styleText("cyan", "Starting agent server...")); clack.log.info(styleText("dim", `Config: ${KUBB_AGENT_CONFIG}`)); clack.log.info(styleText("dim", `Host: ${HOST}`)); clack.log.info(styleText("dim", `Port: ${PORT}`)); if (noCache) clack.log.info(styleText("dim", "Session caching: disabled")); if (!KUBB_AGENT_ALLOW_WRITE && !KUBB_AGENT_ALLOW_ALL) clack.log.warn(styleText("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable.")); spawn("node", [serverPath], { env: { ...process$1.env, ...env }, stdio: "inherit", cwd: process$1.cwd() }); } catch (error) { console.error("Failed to start agent server:", error); process$1.exit(1); } } const command = defineCommand({ meta: { name: "start", description: "Start the Agent server" }, args, async run(commandContext) { const { args } = commandContext; try { const configPath = path.resolve(process$1.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.log.error(styleText("red", "Failed to start agent server")); console.error(error); process$1.exit(1); } } }); //#endregion export { command as default }; //# sourceMappingURL=start-CYuU23PX.js.map