@kubb/cli 5.0.0-alpha.36 → 5.0.0-alpha.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/kubb.js +6 -0
- package/dist/{agent-D1I8zBrQ.js → agent-C5JBC9Q9.js} +3 -3
- package/dist/{agent-D1I8zBrQ.js.map → agent-C5JBC9Q9.js.map} +1 -1
- package/dist/{agent-CRQdwSar.cjs → agent-CWitLsL9.cjs} +47 -29
- package/dist/agent-CWitLsL9.cjs.map +1 -0
- package/dist/{agent-yOLMZKYB.cjs → agent-DLmDQD0F.cjs} +3 -3
- package/dist/{agent-yOLMZKYB.cjs.map → agent-DLmDQD0F.cjs.map} +1 -1
- package/dist/agent-poGbscec.js +105 -0
- package/dist/agent-poGbscec.js.map +1 -0
- package/dist/errors-CLCjoSg0.cjs.map +1 -1
- package/dist/errors-CjPmyZHy.js.map +1 -1
- package/dist/{generate-BqY9Y4hu.js → generate-D2Hks9WU.js} +2 -2
- package/dist/{generate-BqY9Y4hu.js.map → generate-D2Hks9WU.js.map} +1 -1
- package/dist/{generate-Cf1qSeSJ.cjs → generate-DFLmItdl.cjs} +132 -7
- package/dist/generate-DFLmItdl.cjs.map +1 -0
- package/dist/{generate-tDgmJWNE.js → generate-DKDEIomA.js} +129 -4
- package/dist/generate-DKDEIomA.js.map +1 -0
- package/dist/{generate-DLF8yBO-.cjs → generate-igqqE8kf.cjs} +2 -2
- package/dist/{generate-DLF8yBO-.cjs.map → generate-igqqE8kf.cjs.map} +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.js +6 -6
- package/dist/{init-DsJPxNVQ.js → init-COdIsFXI.js} +2 -2
- package/dist/{init-DsJPxNVQ.js.map → init-COdIsFXI.js.map} +1 -1
- package/dist/{init-COClpOHO.cjs → init-SDK46-nF.cjs} +2 -2
- package/dist/{init-COClpOHO.cjs.map → init-SDK46-nF.cjs.map} +1 -1
- package/dist/init-cAbMOLut.cjs.map +1 -1
- package/dist/init-hcm7zvPn.js.map +1 -1
- package/dist/{mcp-BCpQsb0N.js → mcp-BWcUd86Y.js} +3 -3
- package/dist/{mcp-BCpQsb0N.js.map → mcp-BWcUd86Y.js.map} +1 -1
- package/dist/{mcp-CxuctqmK.js → mcp-B_FoDCTh.js} +9 -2
- package/dist/mcp-B_FoDCTh.js.map +1 -0
- package/dist/{mcp-9yURBP26.cjs → mcp-STc97s14.cjs} +9 -3
- package/dist/mcp-STc97s14.cjs.map +1 -0
- package/dist/{mcp-SALpMGkp.cjs → mcp-aRv8LwaD.cjs} +3 -3
- package/dist/{mcp-SALpMGkp.cjs.map → mcp-aRv8LwaD.cjs.map} +1 -1
- package/dist/package-B8NEPBIS.js +6 -0
- package/dist/package-B8NEPBIS.js.map +1 -0
- package/dist/{package-_aRwmOp5.cjs → package-Dd9j6cPm.cjs} +2 -2
- package/dist/package-Dd9j6cPm.cjs.map +1 -0
- package/dist/{validate-DPTV1XRk.cjs → validate-B3kTGFEl.cjs} +3 -3
- package/dist/{validate-DPTV1XRk.cjs.map → validate-B3kTGFEl.cjs.map} +1 -1
- package/dist/{validate-BLlD33VV.js → validate-COWutx4Y.js} +3 -3
- package/dist/{validate-BLlD33VV.js.map → validate-COWutx4Y.js.map} +1 -1
- package/dist/{validate-DIKeUU8K.cjs → validate-CqwT945Z.cjs} +3 -11
- package/dist/validate-CqwT945Z.cjs.map +1 -0
- package/dist/{validate-CIS8nJdd.js → validate-NZ0mduJ3.js} +3 -11
- package/dist/validate-NZ0mduJ3.js.map +1 -0
- package/package.json +6 -7
- package/src/runners/agent.ts +54 -29
- package/src/runners/generate.ts +1 -5
- package/src/runners/validate.ts +3 -13
- package/src/utils/getSummary.ts +1 -1
- package/bin/kubb.cjs +0 -18
- package/dist/agent-B_THuM3X.js +0 -87
- package/dist/agent-B_THuM3X.js.map +0 -1
- package/dist/agent-CRQdwSar.cjs.map +0 -1
- package/dist/generate-Cf1qSeSJ.cjs.map +0 -1
- package/dist/generate-tDgmJWNE.js.map +0 -1
- package/dist/jiti-Cd3S0xwr.cjs +0 -16
- package/dist/jiti-Cd3S0xwr.cjs.map +0 -1
- package/dist/jiti-e08mD2Ph.js +0 -11
- package/dist/jiti-e08mD2Ph.js.map +0 -1
- package/dist/mcp-9yURBP26.cjs.map +0 -1
- package/dist/mcp-CxuctqmK.js.map +0 -1
- package/dist/package-Cx_eJU6W.js +0 -6
- package/dist/package-Cx_eJU6W.js.map +0 -1
- package/dist/package-_aRwmOp5.cjs.map +0 -1
- package/dist/validate-CIS8nJdd.js.map +0 -1
- package/dist/validate-DIKeUU8K.cjs.map +0 -1
package/bin/kubb.js
ADDED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
2
|
import { n as defineCommand } from "./define-Ctii4bel.js";
|
|
3
|
-
import { t as version } from "./package-
|
|
3
|
+
import { t as version } from "./package-B8NEPBIS.js";
|
|
4
4
|
import { o as agentDefaults } from "./constants-DJM9zCXm.js";
|
|
5
5
|
//#endregion
|
|
6
6
|
//#region src/commands/agent.ts
|
|
@@ -38,7 +38,7 @@ const command = defineCommand({
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
async run({ values }) {
|
|
41
|
-
const { runAgentStart } = await import("./agent-
|
|
41
|
+
const { runAgentStart } = await import("./agent-poGbscec.js");
|
|
42
42
|
await runAgentStart({
|
|
43
43
|
port: values.port !== void 0 ? values.port : void 0,
|
|
44
44
|
host: values.host,
|
|
@@ -53,4 +53,4 @@ const command = defineCommand({
|
|
|
53
53
|
//#endregion
|
|
54
54
|
export { command };
|
|
55
55
|
|
|
56
|
-
//# sourceMappingURL=agent-
|
|
56
|
+
//# sourceMappingURL=agent-C5JBC9Q9.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-
|
|
1
|
+
{"version":3,"file":"agent-C5JBC9Q9.js","names":["command","startCommand"],"sources":["../src/commands/agent/start.ts","../src/commands/agent.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../../package.json'\nimport { agentDefaults } from '../../constants.ts'\n\nexport const command = defineCommand({\n name: 'start',\n description: 'Start the Agent server',\n options: {\n config: { type: 'string', description: 'Path to the Kubb config', short: 'c' },\n port: { type: 'string', description: `Port for the server (default: ${agentDefaults.port})`, short: 'p' },\n host: { type: 'string', description: 'Host for the server', default: agentDefaults.host },\n 'allow-write': {\n type: 'boolean',\n description: 'Allow writing generated files to the filesystem. When not set, no files are written and the config patch is not persisted.',\n default: false,\n },\n 'allow-all': { type: 'boolean', description: 'Grant all permissions (implies --allow-write).', default: false },\n },\n async run({ values }) {\n const { runAgentStart } = await import('../../runners/agent.ts')\n\n await runAgentStart({\n port: values.port !== undefined ? values.port : undefined,\n host: values.host,\n configPath: values.config,\n allowWrite: values['allow-write'],\n allowAll: values['allow-all'],\n version,\n })\n },\n})\n","import { defineCommand } from '@internals/utils'\nimport { command as startCommand } from './agent/start.ts'\n\nexport const command = defineCommand({\n name: 'agent',\n description: 'Manage the Kubb Agent server',\n subCommands: [startCommand],\n})\n"],"mappings":";;;;;;ACGA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,aAAa;CACb,aAAa,CDFQ,cAAc;EACnC,MAAM;EACN,aAAa;EACb,SAAS;GACP,QAAQ;IAAE,MAAM;IAAU,aAAa;IAA2B,OAAO;IAAK;GAC9E,MAAM;IAAE,MAAM;IAAU,aAAa,iCAAiC,cAAc,KAAK;IAAI,OAAO;IAAK;GACzG,MAAM;IAAE,MAAM;IAAU,aAAa;IAAuB,SAAS,cAAc;IAAM;GACzF,eAAe;IACb,MAAM;IACN,aAAa;IACb,SAAS;IACV;GACD,aAAa;IAAE,MAAM;IAAW,aAAa;IAAkD,SAAS;IAAO;GAChH;EACD,MAAM,IAAI,EAAE,UAAU;GACpB,MAAM,EAAE,kBAAkB,MAAM,OAAO;AAEvC,SAAM,cAAc;IAClB,MAAM,OAAO,SAAS,KAAA,IAAY,OAAO,OAAO,KAAA;IAChD,MAAM,OAAO;IACb,YAAY,OAAO;IACnB,YAAY,OAAO;IACnB,UAAU,OAAO;IACjB;IACD,CAAC;;EAEL,CAAC,CCxB2B;CAC5B,CAAC"}
|
|
@@ -13,6 +13,36 @@ let node_url = require("node:url");
|
|
|
13
13
|
let _clack_prompts = require("@clack/prompts");
|
|
14
14
|
_clack_prompts = require_chunk.__toESM(_clack_prompts, 1);
|
|
15
15
|
//#region src/runners/agent.ts
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
|
|
18
|
+
*/
|
|
19
|
+
function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }) {
|
|
20
|
+
const resolvedPort = port ?? node_process.env.PORT ?? require_constants.agentDefaults.port;
|
|
21
|
+
const resolvedHost = host !== require_constants.agentDefaults.host ? host : node_process.env.HOST ?? require_constants.agentDefaults.host;
|
|
22
|
+
const resolvedAllowAll = allowAll || node_process.env.KUBB_AGENT_ALLOW_ALL === "true";
|
|
23
|
+
const resolvedAllowWrite = resolvedAllowAll || allowWrite || node_process.env.KUBB_AGENT_ALLOW_WRITE === "true";
|
|
24
|
+
const agentRoot = node_process.env.KUBB_AGENT_ROOT ?? node_process.cwd();
|
|
25
|
+
const agentConfigPath = node_path.default.resolve(node_process.cwd(), configPath || node_process.env.KUBB_AGENT_CONFIG || require_constants.agentDefaults.configFile);
|
|
26
|
+
return {
|
|
27
|
+
port: resolvedPort,
|
|
28
|
+
host: resolvedHost,
|
|
29
|
+
allowWrite: resolvedAllowWrite,
|
|
30
|
+
allowAll: resolvedAllowAll,
|
|
31
|
+
agentConfigPath,
|
|
32
|
+
env: {
|
|
33
|
+
...node_process.env,
|
|
34
|
+
PORT: resolvedPort,
|
|
35
|
+
HOST: resolvedHost,
|
|
36
|
+
KUBB_AGENT_ROOT: agentRoot,
|
|
37
|
+
KUBB_AGENT_CONFIG: agentConfigPath,
|
|
38
|
+
KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
|
|
39
|
+
KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
|
|
40
|
+
KUBB_AGENT_TOKEN: node_process.env.KUBB_AGENT_TOKEN,
|
|
41
|
+
KUBB_AGENT_RETRY_TIMEOUT: node_process.env.KUBB_AGENT_RETRY_TIMEOUT ?? require_constants.agentDefaults.retryTimeout,
|
|
42
|
+
KUBB_STUDIO_URL: node_process.env.KUBB_STUDIO_URL ?? require_constants.agentDefaults.studioUrl
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
16
46
|
function isPortAvailable(port, host) {
|
|
17
47
|
return new Promise((resolve) => {
|
|
18
48
|
const server = node_net.default.createServer();
|
|
@@ -33,38 +63,26 @@ async function runAgentStart({ port, host, configPath, allowWrite, allowAll, ver
|
|
|
33
63
|
const agentPkgPath = (0, node_url.fileURLToPath)({}.resolve("@kubb/agent/package.json"));
|
|
34
64
|
const agentDir = node_path.default.dirname(agentPkgPath);
|
|
35
65
|
const serverPath = node_path.default.join(agentDir, require_constants.agentDefaults.serverEntryPath);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const env = {
|
|
46
|
-
...node_process.env,
|
|
47
|
-
PORT,
|
|
48
|
-
HOST,
|
|
49
|
-
KUBB_AGENT_ROOT,
|
|
50
|
-
KUBB_AGENT_CONFIG,
|
|
51
|
-
KUBB_AGENT_ALLOW_WRITE,
|
|
52
|
-
KUBB_AGENT_ALLOW_ALL,
|
|
53
|
-
KUBB_AGENT_TOKEN,
|
|
54
|
-
KUBB_AGENT_RETRY_TIMEOUT,
|
|
55
|
-
KUBB_STUDIO_URL
|
|
56
|
-
};
|
|
66
|
+
const resolvedEnv = resolveAgentStartEnvironment({
|
|
67
|
+
port,
|
|
68
|
+
host,
|
|
69
|
+
configPath,
|
|
70
|
+
allowWrite,
|
|
71
|
+
allowAll
|
|
72
|
+
});
|
|
73
|
+
const numericPort = Number(resolvedEnv.port);
|
|
74
|
+
if (!Number.isInteger(numericPort) || numericPort <= 0) throw new Error(`Invalid port "${resolvedEnv.port}". Provide a positive integer with --port or PORT.`);
|
|
57
75
|
_clack_prompts.log.step((0, node_util.styleText)("cyan", "Starting agent server..."));
|
|
58
|
-
_clack_prompts.log.info((0, node_util.styleText)("dim", `Config: ${
|
|
59
|
-
_clack_prompts.log.info((0, node_util.styleText)("dim", `Host: ${
|
|
60
|
-
_clack_prompts.log.info((0, node_util.styleText)("dim", `Port: ${
|
|
61
|
-
if (!
|
|
62
|
-
if (!await isPortAvailable(
|
|
63
|
-
_clack_prompts.log.error((0, node_util.styleText)("red", `Port ${
|
|
76
|
+
_clack_prompts.log.info((0, node_util.styleText)("dim", `Config: ${resolvedEnv.agentConfigPath}`));
|
|
77
|
+
_clack_prompts.log.info((0, node_util.styleText)("dim", `Host: ${resolvedEnv.host}`));
|
|
78
|
+
_clack_prompts.log.info((0, node_util.styleText)("dim", `Port: ${resolvedEnv.port}`));
|
|
79
|
+
if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) _clack_prompts.log.warn((0, node_util.styleText)("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
|
|
80
|
+
if (!await isPortAvailable(numericPort, resolvedEnv.host)) {
|
|
81
|
+
_clack_prompts.log.error((0, node_util.styleText)("red", `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`));
|
|
64
82
|
node_process.exit(1);
|
|
65
83
|
}
|
|
66
84
|
await require_shell.spawnAsync("node", [serverPath], {
|
|
67
|
-
env,
|
|
85
|
+
env: resolvedEnv.env,
|
|
68
86
|
cwd: node_process.cwd()
|
|
69
87
|
});
|
|
70
88
|
await require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
|
|
@@ -88,4 +106,4 @@ async function runAgentStart({ port, host, configPath, allowWrite, allowAll, ver
|
|
|
88
106
|
//#endregion
|
|
89
107
|
exports.runAgentStart = runAgentStart;
|
|
90
108
|
|
|
91
|
-
//# sourceMappingURL=agent-
|
|
109
|
+
//# sourceMappingURL=agent-CWitLsL9.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-CWitLsL9.cjs","names":["process","agentDefaults","path","net","spawnAsync","sendTelemetry","buildTelemetryEvent"],"sources":["../src/runners/agent.ts"],"sourcesContent":["import net from 'node:net'\nimport path from 'node:path'\nimport * as process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { spawnAsync } from '@internals/utils'\nimport { agentDefaults } from '../constants.ts'\nimport { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'\n\ntype AgentStartOptions = {\n port: string | undefined\n host: string\n configPath: string | undefined\n allowWrite: boolean\n allowAll: boolean\n version: string\n}\n\ntype ResolvedAgentStartEnvironment = {\n port: string\n host: string\n allowWrite: boolean\n allowAll: boolean\n agentConfigPath: string\n env: NodeJS.ProcessEnv\n}\n\n/**\n * Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.\n */\nfunction resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: Omit<AgentStartOptions, 'version'>): ResolvedAgentStartEnvironment {\n const resolvedPort = port ?? process.env.PORT ?? agentDefaults.port\n const resolvedHost = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)\n const resolvedAllowAll = allowAll || process.env.KUBB_AGENT_ALLOW_ALL === 'true'\n const resolvedAllowWrite = resolvedAllowAll || allowWrite || process.env.KUBB_AGENT_ALLOW_WRITE === 'true'\n const agentRoot = process.env.KUBB_AGENT_ROOT ?? process.cwd()\n const agentConfigPath = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)\n\n return {\n port: resolvedPort,\n host: resolvedHost,\n allowWrite: resolvedAllowWrite,\n allowAll: resolvedAllowAll,\n agentConfigPath,\n env: {\n ...process.env,\n PORT: resolvedPort,\n HOST: resolvedHost,\n KUBB_AGENT_ROOT: agentRoot,\n KUBB_AGENT_CONFIG: agentConfigPath,\n KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),\n KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),\n KUBB_AGENT_TOKEN: process.env.KUBB_AGENT_TOKEN,\n KUBB_AGENT_RETRY_TIMEOUT: process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,\n KUBB_STUDIO_URL: process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl,\n },\n }\n}\n\nfunction isPortAvailable(port: number, host: string): Promise<boolean> {\n return new Promise((resolve) => {\n const server = net.createServer()\n server.once('error', () => resolve(false))\n server.once('listening', () => {\n server.close()\n resolve(true)\n })\n server.listen(port, host)\n })\n}\n\nexport async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {\n const hrStart = process.hrtime()\n\n try {\n // Load .env file into process.env using Node.js built-in (v20.12.0+)\n try {\n process.loadEnvFile()\n } catch {\n // .env file may not exist; ignore\n }\n\n // Resolve the @kubb/agent package path\n const agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')\n const agentPkgPath = fileURLToPath(agentPkgUrl)\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n const resolvedEnv = resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll })\n const numericPort = Number(resolvedEnv.port)\n\n if (!Number.isInteger(numericPort) || numericPort <= 0) {\n throw new Error(`Invalid port \"${resolvedEnv.port}\". Provide a positive integer with --port or PORT.`)\n }\n\n clack.log.step(styleText('cyan', 'Starting agent server...'))\n clack.log.info(styleText('dim', `Config: ${resolvedEnv.agentConfigPath}`))\n clack.log.info(styleText('dim', `Host: ${resolvedEnv.host}`))\n clack.log.info(styleText('dim', `Port: ${resolvedEnv.port}`))\n if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) {\n clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))\n }\n\n if (!(await isPortAvailable(numericPort, resolvedEnv.host))) {\n clack.log.error(\n styleText('red', `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`),\n )\n process.exit(1)\n }\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n await spawnAsync('node', [serverPath], {\n env: resolvedEnv.env,\n cwd: process.cwd(),\n })\n\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'success' }))\n } catch (error) {\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'failed' }))\n clack.log.error(styleText('red', 'Failed to start agent server'))\n console.error(error)\n process.exit(1)\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require("./chunk-ByKO4r7w.cjs");
|
|
2
2
|
const require_define = require("./define-Bdn8j5VM.cjs");
|
|
3
|
-
const require_package = require("./package-
|
|
3
|
+
const require_package = require("./package-Dd9j6cPm.cjs");
|
|
4
4
|
const require_constants = require("./constants-D0XHAHeZ.cjs");
|
|
5
5
|
//#region src/commands/agent/start.ts
|
|
6
6
|
const command$1 = require_define.defineCommand({
|
|
@@ -34,7 +34,7 @@ const command$1 = require_define.defineCommand({
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
async run({ values }) {
|
|
37
|
-
const { runAgentStart } = await Promise.resolve().then(() => require("./agent-
|
|
37
|
+
const { runAgentStart } = await Promise.resolve().then(() => require("./agent-CWitLsL9.cjs"));
|
|
38
38
|
await runAgentStart({
|
|
39
39
|
port: values.port !== void 0 ? values.port : void 0,
|
|
40
40
|
host: values.host,
|
|
@@ -55,4 +55,4 @@ const command = require_define.defineCommand({
|
|
|
55
55
|
//#endregion
|
|
56
56
|
exports.command = command;
|
|
57
57
|
|
|
58
|
-
//# sourceMappingURL=agent-
|
|
58
|
+
//# sourceMappingURL=agent-DLmDQD0F.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-
|
|
1
|
+
{"version":3,"file":"agent-DLmDQD0F.cjs","names":["command","defineCommand","agentDefaults","defineCommand","startCommand"],"sources":["../src/commands/agent/start.ts","../src/commands/agent.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\nimport { version } from '../../../package.json'\nimport { agentDefaults } from '../../constants.ts'\n\nexport const command = defineCommand({\n name: 'start',\n description: 'Start the Agent server',\n options: {\n config: { type: 'string', description: 'Path to the Kubb config', short: 'c' },\n port: { type: 'string', description: `Port for the server (default: ${agentDefaults.port})`, short: 'p' },\n host: { type: 'string', description: 'Host for the server', default: agentDefaults.host },\n 'allow-write': {\n type: 'boolean',\n description: 'Allow writing generated files to the filesystem. When not set, no files are written and the config patch is not persisted.',\n default: false,\n },\n 'allow-all': { type: 'boolean', description: 'Grant all permissions (implies --allow-write).', default: false },\n },\n async run({ values }) {\n const { runAgentStart } = await import('../../runners/agent.ts')\n\n await runAgentStart({\n port: values.port !== undefined ? values.port : undefined,\n host: values.host,\n configPath: values.config,\n allowWrite: values['allow-write'],\n allowAll: values['allow-all'],\n version,\n })\n },\n})\n","import { defineCommand } from '@internals/utils'\nimport { command as startCommand } from './agent/start.ts'\n\nexport const command = defineCommand({\n name: 'agent',\n description: 'Manage the Kubb Agent server',\n subCommands: [startCommand],\n})\n"],"mappings":";;;;;AAIA,MAAaA,YAAUC,eAAAA,cAAc;CACnC,MAAM;CACN,aAAa;CACb,SAAS;EACP,QAAQ;GAAE,MAAM;GAAU,aAAa;GAA2B,OAAO;GAAK;EAC9E,MAAM;GAAE,MAAM;GAAU,aAAa,iCAAiCC,kBAAAA,cAAc,KAAK;GAAI,OAAO;GAAK;EACzG,MAAM;GAAE,MAAM;GAAU,aAAa;GAAuB,SAASA,kBAAAA,cAAc;GAAM;EACzF,eAAe;GACb,MAAM;GACN,aAAa;GACb,SAAS;GACV;EACD,aAAa;GAAE,MAAM;GAAW,aAAa;GAAkD,SAAS;GAAO;EAChH;CACD,MAAM,IAAI,EAAE,UAAU;EACpB,MAAM,EAAE,kBAAkB,MAAA,QAAA,SAAA,CAAA,WAAA,QAAM,uBAAA,CAAA;AAEhC,QAAM,cAAc;GAClB,MAAM,OAAO,SAAS,KAAA,IAAY,OAAO,OAAO,KAAA;GAChD,MAAM,OAAO;GACb,YAAY,OAAO;GACnB,YAAY,OAAO;GACnB,UAAU,OAAO;GACjB,SAAA,gBAAA;GACD,CAAC;;CAEL,CAAC;;;AC3BF,MAAa,UAAUC,eAAAA,cAAc;CACnC,MAAM;CACN,aAAa;CACb,aAAa,CAACC,UAAa;CAC5B,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import "./chunk--u3MIqq1.js";
|
|
2
|
+
import { r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-CBISr5w4.js";
|
|
3
|
+
import { t as spawnAsync } from "./shell-DLzN4fRo.js";
|
|
4
|
+
import { o as agentDefaults } from "./constants-DJM9zCXm.js";
|
|
5
|
+
import { styleText } from "node:util";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import * as process$1 from "node:process";
|
|
8
|
+
import net from "node:net";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import * as clack from "@clack/prompts";
|
|
11
|
+
//#region src/runners/agent.ts
|
|
12
|
+
/**
|
|
13
|
+
* Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
|
|
14
|
+
*/
|
|
15
|
+
function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }) {
|
|
16
|
+
const resolvedPort = port ?? process$1.env.PORT ?? agentDefaults.port;
|
|
17
|
+
const resolvedHost = host !== agentDefaults.host ? host : process$1.env.HOST ?? agentDefaults.host;
|
|
18
|
+
const resolvedAllowAll = allowAll || process$1.env.KUBB_AGENT_ALLOW_ALL === "true";
|
|
19
|
+
const resolvedAllowWrite = resolvedAllowAll || allowWrite || process$1.env.KUBB_AGENT_ALLOW_WRITE === "true";
|
|
20
|
+
const agentRoot = process$1.env.KUBB_AGENT_ROOT ?? process$1.cwd();
|
|
21
|
+
const agentConfigPath = path.resolve(process$1.cwd(), configPath || process$1.env.KUBB_AGENT_CONFIG || agentDefaults.configFile);
|
|
22
|
+
return {
|
|
23
|
+
port: resolvedPort,
|
|
24
|
+
host: resolvedHost,
|
|
25
|
+
allowWrite: resolvedAllowWrite,
|
|
26
|
+
allowAll: resolvedAllowAll,
|
|
27
|
+
agentConfigPath,
|
|
28
|
+
env: {
|
|
29
|
+
...process$1.env,
|
|
30
|
+
PORT: resolvedPort,
|
|
31
|
+
HOST: resolvedHost,
|
|
32
|
+
KUBB_AGENT_ROOT: agentRoot,
|
|
33
|
+
KUBB_AGENT_CONFIG: agentConfigPath,
|
|
34
|
+
KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
|
|
35
|
+
KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
|
|
36
|
+
KUBB_AGENT_TOKEN: process$1.env.KUBB_AGENT_TOKEN,
|
|
37
|
+
KUBB_AGENT_RETRY_TIMEOUT: process$1.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,
|
|
38
|
+
KUBB_STUDIO_URL: process$1.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function isPortAvailable(port, host) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
const server = net.createServer();
|
|
45
|
+
server.once("error", () => resolve(false));
|
|
46
|
+
server.once("listening", () => {
|
|
47
|
+
server.close();
|
|
48
|
+
resolve(true);
|
|
49
|
+
});
|
|
50
|
+
server.listen(port, host);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }) {
|
|
54
|
+
const hrStart = process$1.hrtime();
|
|
55
|
+
try {
|
|
56
|
+
try {
|
|
57
|
+
process$1.loadEnvFile();
|
|
58
|
+
} catch {}
|
|
59
|
+
const agentPkgPath = fileURLToPath(import.meta.resolve("@kubb/agent/package.json"));
|
|
60
|
+
const agentDir = path.dirname(agentPkgPath);
|
|
61
|
+
const serverPath = path.join(agentDir, agentDefaults.serverEntryPath);
|
|
62
|
+
const resolvedEnv = resolveAgentStartEnvironment({
|
|
63
|
+
port,
|
|
64
|
+
host,
|
|
65
|
+
configPath,
|
|
66
|
+
allowWrite,
|
|
67
|
+
allowAll
|
|
68
|
+
});
|
|
69
|
+
const numericPort = Number(resolvedEnv.port);
|
|
70
|
+
if (!Number.isInteger(numericPort) || numericPort <= 0) throw new Error(`Invalid port "${resolvedEnv.port}". Provide a positive integer with --port or PORT.`);
|
|
71
|
+
clack.log.step(styleText("cyan", "Starting agent server..."));
|
|
72
|
+
clack.log.info(styleText("dim", `Config: ${resolvedEnv.agentConfigPath}`));
|
|
73
|
+
clack.log.info(styleText("dim", `Host: ${resolvedEnv.host}`));
|
|
74
|
+
clack.log.info(styleText("dim", `Port: ${resolvedEnv.port}`));
|
|
75
|
+
if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) clack.log.warn(styleText("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
|
|
76
|
+
if (!await isPortAvailable(numericPort, resolvedEnv.host)) {
|
|
77
|
+
clack.log.error(styleText("red", `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`));
|
|
78
|
+
process$1.exit(1);
|
|
79
|
+
}
|
|
80
|
+
await spawnAsync("node", [serverPath], {
|
|
81
|
+
env: resolvedEnv.env,
|
|
82
|
+
cwd: process$1.cwd()
|
|
83
|
+
});
|
|
84
|
+
await sendTelemetry(buildTelemetryEvent({
|
|
85
|
+
command: "agent",
|
|
86
|
+
kubbVersion: version,
|
|
87
|
+
hrStart,
|
|
88
|
+
status: "success"
|
|
89
|
+
}));
|
|
90
|
+
} catch (error) {
|
|
91
|
+
await sendTelemetry(buildTelemetryEvent({
|
|
92
|
+
command: "agent",
|
|
93
|
+
kubbVersion: version,
|
|
94
|
+
hrStart,
|
|
95
|
+
status: "failed"
|
|
96
|
+
}));
|
|
97
|
+
clack.log.error(styleText("red", "Failed to start agent server"));
|
|
98
|
+
console.error(error);
|
|
99
|
+
process$1.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { runAgentStart };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=agent-poGbscec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-poGbscec.js","names":["process"],"sources":["../src/runners/agent.ts"],"sourcesContent":["import net from 'node:net'\nimport path from 'node:path'\nimport * as process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { spawnAsync } from '@internals/utils'\nimport { agentDefaults } from '../constants.ts'\nimport { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'\n\ntype AgentStartOptions = {\n port: string | undefined\n host: string\n configPath: string | undefined\n allowWrite: boolean\n allowAll: boolean\n version: string\n}\n\ntype ResolvedAgentStartEnvironment = {\n port: string\n host: string\n allowWrite: boolean\n allowAll: boolean\n agentConfigPath: string\n env: NodeJS.ProcessEnv\n}\n\n/**\n * Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.\n */\nfunction resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: Omit<AgentStartOptions, 'version'>): ResolvedAgentStartEnvironment {\n const resolvedPort = port ?? process.env.PORT ?? agentDefaults.port\n const resolvedHost = host !== agentDefaults.host ? host : (process.env.HOST ?? agentDefaults.host)\n const resolvedAllowAll = allowAll || process.env.KUBB_AGENT_ALLOW_ALL === 'true'\n const resolvedAllowWrite = resolvedAllowAll || allowWrite || process.env.KUBB_AGENT_ALLOW_WRITE === 'true'\n const agentRoot = process.env.KUBB_AGENT_ROOT ?? process.cwd()\n const agentConfigPath = path.resolve(process.cwd(), configPath || process.env.KUBB_AGENT_CONFIG || agentDefaults.configFile)\n\n return {\n port: resolvedPort,\n host: resolvedHost,\n allowWrite: resolvedAllowWrite,\n allowAll: resolvedAllowAll,\n agentConfigPath,\n env: {\n ...process.env,\n PORT: resolvedPort,\n HOST: resolvedHost,\n KUBB_AGENT_ROOT: agentRoot,\n KUBB_AGENT_CONFIG: agentConfigPath,\n KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),\n KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),\n KUBB_AGENT_TOKEN: process.env.KUBB_AGENT_TOKEN,\n KUBB_AGENT_RETRY_TIMEOUT: process.env.KUBB_AGENT_RETRY_TIMEOUT ?? agentDefaults.retryTimeout,\n KUBB_STUDIO_URL: process.env.KUBB_STUDIO_URL ?? agentDefaults.studioUrl,\n },\n }\n}\n\nfunction isPortAvailable(port: number, host: string): Promise<boolean> {\n return new Promise((resolve) => {\n const server = net.createServer()\n server.once('error', () => resolve(false))\n server.once('listening', () => {\n server.close()\n resolve(true)\n })\n server.listen(port, host)\n })\n}\n\nexport async function runAgentStart({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {\n const hrStart = process.hrtime()\n\n try {\n // Load .env file into process.env using Node.js built-in (v20.12.0+)\n try {\n process.loadEnvFile()\n } catch {\n // .env file may not exist; ignore\n }\n\n // Resolve the @kubb/agent package path\n const agentPkgUrl = import.meta.resolve('@kubb/agent/package.json')\n const agentPkgPath = fileURLToPath(agentPkgUrl)\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n const resolvedEnv = resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll })\n const numericPort = Number(resolvedEnv.port)\n\n if (!Number.isInteger(numericPort) || numericPort <= 0) {\n throw new Error(`Invalid port \"${resolvedEnv.port}\". Provide a positive integer with --port or PORT.`)\n }\n\n clack.log.step(styleText('cyan', 'Starting agent server...'))\n clack.log.info(styleText('dim', `Config: ${resolvedEnv.agentConfigPath}`))\n clack.log.info(styleText('dim', `Host: ${resolvedEnv.host}`))\n clack.log.info(styleText('dim', `Port: ${resolvedEnv.port}`))\n if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) {\n clack.log.warn(styleText('yellow', 'Filesystem writes disabled. Use --allow-write or --allow-all to enable.'))\n }\n\n if (!(await isPortAvailable(numericPort, resolvedEnv.host))) {\n clack.log.error(\n styleText('red', `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`),\n )\n process.exit(1)\n }\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n await spawnAsync('node', [serverPath], {\n env: resolvedEnv.env,\n cwd: process.cwd(),\n })\n\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'success' }))\n } catch (error) {\n await sendTelemetry(buildTelemetryEvent({ command: 'agent', kubbVersion: version, hrStart, status: 'failed' }))\n clack.log.error(styleText('red', 'Failed to start agent server'))\n console.error(error)\n process.exit(1)\n }\n}\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-CLCjoSg0.cjs","names":[],"sources":["../../../internals/utils/src/errors.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"errors-CLCjoSg0.cjs","names":[],"sources":["../../../internals/utils/src/errors.ts"],"sourcesContent":["/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgB,QAAQ,OAAuB;AAC7C,QAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;;;AAYlE,SAAgB,gBAAgB,OAAwB;AACtD,QAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;;;;;;;;;;AAW/D,SAAgB,QAAQ,OAAiC;AACvD,QAAO,MAAM,iBAAiB,QAAQ,MAAM,QAAQ,KAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-CjPmyZHy.js","names":[],"sources":["../../../internals/utils/src/errors.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"errors-CjPmyZHy.js","names":[],"sources":["../../../internals/utils/src/errors.ts"],"sourcesContent":["/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgB,QAAQ,OAAuB;AAC7C,QAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;;;AAYlE,SAAgB,gBAAgB,OAAwB;AACtD,QAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;;;;;;;;;;AAW/D,SAAgB,QAAQ,OAAiC;AACvD,QAAO,MAAM,iBAAiB,QAAQ,MAAM,QAAQ,KAAA"}
|
|
@@ -51,7 +51,7 @@ const command = defineCommand({
|
|
|
51
51
|
},
|
|
52
52
|
async run({ values, positionals }) {
|
|
53
53
|
const logLevel = values.debug ? "debug" : values.verbose ? "verbose" : values.silent ? "silent" : values.logLevel;
|
|
54
|
-
const { runGenerateCommand } = await import("./generate-
|
|
54
|
+
const { runGenerateCommand } = await import("./generate-DKDEIomA.js");
|
|
55
55
|
await runGenerateCommand({
|
|
56
56
|
input: positionals[0],
|
|
57
57
|
configPath: values.config,
|
|
@@ -63,4 +63,4 @@ const command = defineCommand({
|
|
|
63
63
|
//#endregion
|
|
64
64
|
export { command };
|
|
65
65
|
|
|
66
|
-
//# sourceMappingURL=generate-
|
|
66
|
+
//# sourceMappingURL=generate-D2Hks9WU.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-
|
|
1
|
+
{"version":3,"file":"generate-D2Hks9WU.js","names":[],"sources":["../src/commands/generate.ts"],"sourcesContent":["import { defineCommand } from '@internals/utils'\n\nexport const command = defineCommand({\n name: 'generate',\n description: \"[input] Generate files based on a 'kubb.config.ts' file\",\n arguments: ['[input]'],\n options: {\n config: { type: 'string', description: 'Path to the Kubb config', short: 'c' },\n logLevel: {\n type: 'string',\n description: 'Info, silent, verbose or debug',\n short: 'l',\n default: 'info',\n hint: 'silent|info|verbose|debug',\n enum: ['silent', 'info', 'verbose', 'debug'],\n },\n watch: { type: 'boolean', description: 'Watch mode based on the input file', short: 'w', default: false },\n debug: { type: 'boolean', description: 'Override logLevel to debug', short: 'd', default: false },\n verbose: { type: 'boolean', description: 'Override logLevel to verbose', short: 'v', default: false },\n silent: { type: 'boolean', description: 'Override logLevel to silent', short: 's', default: false },\n },\n async run({ values, positionals }) {\n const logLevel = values.debug ? 'debug' : values.verbose ? 'verbose' : values.silent ? 'silent' : values.logLevel\n const { runGenerateCommand } = await import('../runners/generate.ts')\n\n await runGenerateCommand({ input: positionals[0], configPath: values.config, logLevel, watch: values.watch })\n },\n})\n"],"mappings":";;;AAEA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,aAAa;CACb,WAAW,CAAC,UAAU;CACtB,SAAS;EACP,QAAQ;GAAE,MAAM;GAAU,aAAa;GAA2B,OAAO;GAAK;EAC9E,UAAU;GACR,MAAM;GACN,aAAa;GACb,OAAO;GACP,SAAS;GACT,MAAM;GACN,MAAM;IAAC;IAAU;IAAQ;IAAW;IAAQ;GAC7C;EACD,OAAO;GAAE,MAAM;GAAW,aAAa;GAAsC,OAAO;GAAK,SAAS;GAAO;EACzG,OAAO;GAAE,MAAM;GAAW,aAAa;GAA8B,OAAO;GAAK,SAAS;GAAO;EACjG,SAAS;GAAE,MAAM;GAAW,aAAa;GAAgC,OAAO;GAAK,SAAS;GAAO;EACrG,QAAQ;GAAE,MAAM;GAAW,aAAa;GAA+B,OAAO;GAAK,SAAS;GAAO;EACpG;CACD,MAAM,IAAI,EAAE,QAAQ,eAAe;EACjC,MAAM,WAAW,OAAO,QAAQ,UAAU,OAAO,UAAU,YAAY,OAAO,SAAS,WAAW,OAAO;EACzG,MAAM,EAAE,uBAAuB,MAAM,OAAO;AAE5C,QAAM,mBAAmB;GAAE,OAAO,YAAY;GAAI,YAAY,OAAO;GAAQ;GAAU,OAAO,OAAO;GAAO,CAAC;;CAEhH,CAAC"}
|
|
@@ -2,10 +2,11 @@ const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
|
2
2
|
const require_errors = require("./errors-CLCjoSg0.cjs");
|
|
3
3
|
const require_telemetry = require("./telemetry-D_Bi2E3I.cjs");
|
|
4
4
|
const require_shell = require("./shell-475fQKaX.cjs");
|
|
5
|
-
const require_package = require("./package-
|
|
5
|
+
const require_package = require("./package-Dd9j6cPm.cjs");
|
|
6
6
|
const require_constants = require("./constants-D0XHAHeZ.cjs");
|
|
7
7
|
let node_util = require("node:util");
|
|
8
8
|
let node_events = require("node:events");
|
|
9
|
+
let node_child_process = require("node:child_process");
|
|
9
10
|
let node_crypto = require("node:crypto");
|
|
10
11
|
require("node:fs");
|
|
11
12
|
let node_fs_promises = require("node:fs/promises");
|
|
@@ -127,6 +128,130 @@ var AsyncEventEmitter = class {
|
|
|
127
128
|
}
|
|
128
129
|
};
|
|
129
130
|
//#endregion
|
|
131
|
+
//#region ../../internals/utils/src/formatters.ts
|
|
132
|
+
/**
|
|
133
|
+
* CLI command descriptors for each supported code formatter.
|
|
134
|
+
*
|
|
135
|
+
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
136
|
+
* output path to the correct argument list, and an `errorMessage` shown when
|
|
137
|
+
* the formatter is not found.
|
|
138
|
+
*/
|
|
139
|
+
const formatters = {
|
|
140
|
+
prettier: {
|
|
141
|
+
command: "prettier",
|
|
142
|
+
args: (outputPath) => [
|
|
143
|
+
"--ignore-unknown",
|
|
144
|
+
"--write",
|
|
145
|
+
outputPath
|
|
146
|
+
],
|
|
147
|
+
errorMessage: "Prettier not found"
|
|
148
|
+
},
|
|
149
|
+
biome: {
|
|
150
|
+
command: "biome",
|
|
151
|
+
args: (outputPath) => [
|
|
152
|
+
"format",
|
|
153
|
+
"--write",
|
|
154
|
+
outputPath
|
|
155
|
+
],
|
|
156
|
+
errorMessage: "Biome not found"
|
|
157
|
+
},
|
|
158
|
+
oxfmt: {
|
|
159
|
+
command: "oxfmt",
|
|
160
|
+
args: (outputPath) => [outputPath],
|
|
161
|
+
errorMessage: "Oxfmt not found"
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
async function isFormatterAvailable(formatter) {
|
|
165
|
+
return new Promise((resolve) => {
|
|
166
|
+
const child = (0, node_child_process.spawn)(formatter, ["--version"], { stdio: "ignore" });
|
|
167
|
+
child.on("close", (code) => resolve(code === 0));
|
|
168
|
+
child.on("error", () => resolve(false));
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Detects the first available code formatter on the current system.
|
|
173
|
+
*
|
|
174
|
+
* - Checks in preference order: `biome`, `oxfmt`, `prettier`.
|
|
175
|
+
* - Returns `null` when none are found.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const formatter = await detectFormatter()
|
|
180
|
+
* if (formatter) {
|
|
181
|
+
* console.log(`Using ${formatter} for formatting`)
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
async function detectFormatter() {
|
|
186
|
+
const formatterNames = new Set([
|
|
187
|
+
"biome",
|
|
188
|
+
"oxfmt",
|
|
189
|
+
"prettier"
|
|
190
|
+
]);
|
|
191
|
+
for (const formatter of formatterNames) if (await isFormatterAvailable(formatter)) return formatter;
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region ../../internals/utils/src/linters.ts
|
|
196
|
+
/**
|
|
197
|
+
* CLI command descriptors for each supported linter.
|
|
198
|
+
*
|
|
199
|
+
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
200
|
+
* output path to the correct argument list, and an `errorMessage` shown when
|
|
201
|
+
* the linter is not found.
|
|
202
|
+
*/
|
|
203
|
+
const linters = {
|
|
204
|
+
eslint: {
|
|
205
|
+
command: "eslint",
|
|
206
|
+
args: (outputPath) => [outputPath, "--fix"],
|
|
207
|
+
errorMessage: "Eslint not found"
|
|
208
|
+
},
|
|
209
|
+
biome: {
|
|
210
|
+
command: "biome",
|
|
211
|
+
args: (outputPath) => [
|
|
212
|
+
"lint",
|
|
213
|
+
"--fix",
|
|
214
|
+
outputPath
|
|
215
|
+
],
|
|
216
|
+
errorMessage: "Biome not found"
|
|
217
|
+
},
|
|
218
|
+
oxlint: {
|
|
219
|
+
command: "oxlint",
|
|
220
|
+
args: (outputPath) => ["--fix", outputPath],
|
|
221
|
+
errorMessage: "Oxlint not found"
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
async function isLinterAvailable(linter) {
|
|
225
|
+
return new Promise((resolve) => {
|
|
226
|
+
const child = (0, node_child_process.spawn)(linter, ["--version"], { stdio: "ignore" });
|
|
227
|
+
child.on("close", (code) => resolve(code === 0));
|
|
228
|
+
child.on("error", () => resolve(false));
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Detects the first available linter on the current system.
|
|
233
|
+
*
|
|
234
|
+
* - Checks in preference order: `biome`, `oxlint`, `eslint`.
|
|
235
|
+
* - Returns `null` when none are found.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* const linter = await detectLinter()
|
|
240
|
+
* if (linter) {
|
|
241
|
+
* console.log(`Using ${linter} for linting`)
|
|
242
|
+
* }
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
async function detectLinter() {
|
|
246
|
+
const linterNames = new Set([
|
|
247
|
+
"biome",
|
|
248
|
+
"oxlint",
|
|
249
|
+
"eslint"
|
|
250
|
+
]);
|
|
251
|
+
for (const linter of linterNames) if (await isLinterAvailable(linter)) return linter;
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
//#endregion
|
|
130
255
|
//#region ../../internals/utils/src/time.ts
|
|
131
256
|
/**
|
|
132
257
|
* Calculates elapsed time in milliseconds from a high-resolution `process.hrtime` start time.
|
|
@@ -340,7 +465,7 @@ function getSummary({ failedPlugins, filesCreated, status, hrStart, config, plug
|
|
|
340
465
|
pluginsFailed: status === "failed" ? [...failedPlugins].map(({ plugin }) => randomCliColor(plugin.name)).join(", ") : void 0,
|
|
341
466
|
filesCreated,
|
|
342
467
|
time: (0, node_util.styleText)("green", duration),
|
|
343
|
-
output: node_path.default.
|
|
468
|
+
output: node_path.default.resolve(config.root, config.output.path)
|
|
344
469
|
};
|
|
345
470
|
const labels = {
|
|
346
471
|
plugins: "Plugins:",
|
|
@@ -1479,8 +1604,8 @@ async function generate(options) {
|
|
|
1479
1604
|
const outputPath = node_path.default.resolve(config.root, config.output.path);
|
|
1480
1605
|
if (config.output.format) await runToolPass({
|
|
1481
1606
|
toolValue: config.output.format,
|
|
1482
|
-
detect:
|
|
1483
|
-
toolMap:
|
|
1607
|
+
detect: detectFormatter,
|
|
1608
|
+
toolMap: formatters,
|
|
1484
1609
|
toolLabel: "formatter",
|
|
1485
1610
|
successPrefix: "Formatting",
|
|
1486
1611
|
noToolMessage: "No formatter found (biome, prettier, or oxfmt). Skipping formatting.",
|
|
@@ -1493,8 +1618,8 @@ async function generate(options) {
|
|
|
1493
1618
|
});
|
|
1494
1619
|
if (config.output.lint) await runToolPass({
|
|
1495
1620
|
toolValue: config.output.lint,
|
|
1496
|
-
detect:
|
|
1497
|
-
toolMap:
|
|
1621
|
+
detect: detectLinter,
|
|
1622
|
+
toolMap: linters,
|
|
1498
1623
|
toolLabel: "linter",
|
|
1499
1624
|
successPrefix: "Linting",
|
|
1500
1625
|
noToolMessage: "No linter found (biome, oxlint, or eslint). Skipping linting.",
|
|
@@ -1575,4 +1700,4 @@ async function runGenerateCommand({ input, configPath, logLevel: logLevelKey, wa
|
|
|
1575
1700
|
//#endregion
|
|
1576
1701
|
exports.runGenerateCommand = runGenerateCommand;
|
|
1577
1702
|
|
|
1578
|
-
//# sourceMappingURL=generate-
|
|
1703
|
+
//# sourceMappingURL=generate-DFLmItdl.cjs.map
|