@kubb/cli 5.0.0-beta.40 → 5.0.0-beta.42
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/README.md +11 -15
- package/dist/{agent-DQerNyd8.cjs → agent-BumEm07_.cjs} +3 -3
- package/dist/{agent-DQerNyd8.cjs.map → agent-BumEm07_.cjs.map} +1 -1
- package/dist/{agent-ZKJkTTGN.js → agent-gLdUEJW4.js} +3 -3
- package/dist/{agent-ZKJkTTGN.js.map → agent-gLdUEJW4.js.map} +1 -1
- package/dist/{generate-DQLvFw4z.cjs → generate-Bi4BSF56.cjs} +2 -2
- package/dist/{generate-DQLvFw4z.cjs.map → generate-Bi4BSF56.cjs.map} +1 -1
- package/dist/{generate-40x9PP4o.js → generate-CUxL5Jcs.js} +2 -2
- package/dist/{generate-40x9PP4o.js.map → generate-CUxL5Jcs.js.map} +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.js +6 -6
- package/dist/{init-CT9RChdK.js → init-3HTDWMFe.js} +3 -3
- package/dist/{init-CT9RChdK.js.map → init-3HTDWMFe.js.map} +1 -1
- package/dist/{init-sEaUN7Dj.cjs → init-C8CwBts1.cjs} +3 -3
- package/dist/{init-sEaUN7Dj.cjs.map → init-C8CwBts1.cjs.map} +1 -1
- package/dist/{mcp-Siyb6fTT.cjs → mcp-DbzlupRr.cjs} +2 -2
- package/dist/{mcp-Siyb6fTT.cjs.map → mcp-DbzlupRr.cjs.map} +1 -1
- package/dist/{mcp-cjPrOeot.js → mcp-fY6xSxpb.js} +2 -2
- package/dist/{mcp-cjPrOeot.js.map → mcp-fY6xSxpb.js.map} +1 -1
- package/dist/package-CXq9vu7l.js +6 -0
- package/dist/package-CXq9vu7l.js.map +1 -0
- package/dist/{package-BJ6qam2Y.cjs → package-DE-_IDOs.cjs} +2 -2
- package/dist/package-DE-_IDOs.cjs.map +1 -0
- package/dist/{run-C_NMctua.cjs → run-B1Bc6OVr.cjs} +2 -2
- package/dist/run-B1Bc6OVr.cjs.map +1 -0
- package/dist/{run-BQ3Qj0xB.js → run-Bm3WebIl.js} +2 -2
- package/dist/{run-BQ3Qj0xB.js.map → run-Bm3WebIl.js.map} +1 -1
- package/dist/{run-D-s2LdlW.cjs → run-CZC17tSi.cjs} +2 -2
- package/dist/{run-D-s2LdlW.cjs.map → run-CZC17tSi.cjs.map} +1 -1
- package/dist/{run-D8dCWepS.js → run-CvEVkbIx.js} +2 -2
- package/dist/run-CvEVkbIx.js.map +1 -0
- package/dist/{run-CcQawFNK.cjs → run-D4WAzrjB.cjs} +50 -298
- package/dist/run-D4WAzrjB.cjs.map +1 -0
- package/dist/{run-CHZKHTv0.js → run-DeQ7UlYB.js} +71 -319
- package/dist/run-DeQ7UlYB.js.map +1 -0
- package/dist/{validate-8pgfxUTy.js → validate-BO5yaxys.js} +2 -2
- package/dist/{validate-8pgfxUTy.js.map → validate-BO5yaxys.js.map} +1 -1
- package/dist/{validate-CstV7Pc2.cjs → validate-Uw_LUtUk.cjs} +2 -2
- package/dist/{validate-CstV7Pc2.cjs.map → validate-Uw_LUtUk.cjs.map} +1 -1
- package/package.json +6 -6
- package/src/loggers/clackLogger.ts +22 -25
- package/src/loggers/plainLogger.ts +3 -6
- package/src/loggers/types.ts +1 -2
- package/src/loggers/utils.ts +11 -68
- package/src/runners/agent/run.ts +3 -1
- package/src/runners/generate/run.ts +9 -16
- package/src/runners/generate/utils.ts +17 -20
- package/src/runners/init/run.ts +1 -1
- package/dist/package-BJ6qam2Y.cjs.map +0 -1
- package/dist/package-CR5vEK4K.js +0 -6
- package/dist/package-CR5vEK4K.js.map +0 -1
- package/dist/run-CHZKHTv0.js.map +0 -1
- package/dist/run-C_NMctua.cjs.map +0 -1
- package/dist/run-CcQawFNK.cjs.map +0 -1
- package/dist/run-D8dCWepS.js.map +0 -1
- package/src/loggers/githubActionsLogger.ts +0 -377
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-D-s2LdlW.cjs","names":["process","agentDefaults","path","net","process","Telemetry","path","agentDefaults","spawnAsync","getErrorMessage"],"sources":["../src/runners/agent/utils.ts","../src/runners/agent/run.ts"],"sourcesContent":["import net from 'node:net'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { agentDefaults } from '../../constants.ts'\n\ntype AgentStartEnvironmentInput = {\n /**\n * TCP port for the HTTP server. When `undefined`, falls back to `PORT` env var or the default (`3000`).\n */\n port: string | undefined\n /**\n * Hostname the HTTP server binds to.\n */\n host: string\n /**\n * Explicit path to the Kubb config file. When `undefined`, falls back to `KUBB_AGENT_CONFIG` or the default filename.\n */\n configPath: string | undefined\n /**\n * Grants the agent permission to write generated files to the filesystem.\n */\n allowWrite: boolean\n /**\n * Grants all agent permissions, including filesystem writes. Implies `allowWrite`.\n */\n allowAll: boolean\n}\n\ntype ResolvedAgentStartEnvironment = {\n /**\n * Final port string after merging CLI flag, `PORT` env var, and the default.\n */\n port: string\n /**\n * Final hostname after merging CLI flag, `HOST` env var, and the default.\n */\n host: string\n /**\n * Effective write-permission flag, accounting for `allowAll` and `KUBB_AGENT_ALLOW_WRITE`.\n */\n allowWrite: boolean\n /**\n * Effective all-permissions flag, accounting for `KUBB_AGENT_ALLOW_ALL`.\n */\n allowAll: boolean\n /**\n * Absolute path to the Kubb config file passed to the agent subprocess.\n */\n agentConfigPath: string\n /**\n * Merged `process.env` object with all resolved agent environment variables applied.\n */\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 */\nexport function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: AgentStartEnvironmentInput): 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\nexport function 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","import { createRequire } from 'node:module'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { spawnAsync, getErrorMessage } from '@internals/utils'\nimport { Telemetry } from '@kubb/core'\nimport { agentDefaults } from '../../constants.ts'\nimport { isPortAvailable, resolveAgentStartEnvironment } from './utils.ts'\n\ntype AgentStartOptions = {\n /**\n * TCP port for the HTTP server. When `undefined`, falls back to `PORT` env var or the default (`3000`).\n */\n port: string | undefined\n /**\n * Hostname the HTTP server binds to.\n *\n * @default 'localhost'\n */\n host: string\n /**\n * Explicit path to the Kubb config file. When `undefined`, falls back to `KUBB_AGENT_CONFIG` or the default filename.\n */\n configPath: string | undefined\n /**\n * Grants the agent permission to write generated files to the filesystem.\n */\n allowWrite: boolean\n /**\n * Grants all agent permissions, including filesystem writes. Implies `allowWrite`.\n */\n allowAll: boolean\n /**\n * Current `@kubb/cli` version string, used for the telemetry payload.\n */\n version: string\n}\n\n/**\n * Spawns the Kubb Agent HTTP server as a Node.js subprocess.\n * Resolves config from CLI flags and environment variables, validates the port, and exits with code 1 on failure.\n */\nexport async function run({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {\n const hrStart = process.hrtime()\n const report = (status: 'success' | 'failed') => Telemetry.send(Telemetry.build({ command: 'agent', kubbVersion: version, hrStart, status }))\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, createRequire is CJS/ESM compatible (import.meta.resolve is ESM-only)\n const require = createRequire(import.meta.url)\n let agentPkgPath: string\n try {\n agentPkgPath = require.resolve('@kubb/agent/package.json')\n } catch (_e) {\n console.error(styleText('red', 'The @kubb/agent package is not installed.'))\n console.error('')\n console.error('Install it with:')\n console.error(styleText('cyan', ' npm install @kubb/agent'))\n console.error(styleText('cyan', ' # or'))\n console.error(styleText('cyan', ' pnpm install @kubb/agent'))\n console.error('')\n process.exit(1)\n }\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n const resolvedEnv = resolveAgentStartEnvironment({\n port,\n host,\n configPath,\n allowWrite,\n allowAll,\n })\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(styleText('red', `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`))\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 report('success')\n } catch (error) {\n await report('failed')\n clack.log.error(styleText('red', 'Failed to start agent server'))\n clack.log.error(getErrorMessage(error))\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,6BAA6B,EAAE,MAAM,MAAM,YAAY,YAAY,YAAuE;CACxJ,MAAM,eAAe,QAAQA,aAAAA,QAAQ,IAAI,QAAQC,kBAAAA,cAAc;CAC/D,MAAM,eAAe,SAASA,kBAAAA,cAAc,OAAO,OAAQD,aAAAA,QAAQ,IAAI,QAAQC,kBAAAA,cAAc;CAC7F,MAAM,mBAAmB,YAAYD,aAAAA,QAAQ,IAAI,yBAAyB;CAC1E,MAAM,qBAAqB,oBAAoB,cAAcA,aAAAA,QAAQ,IAAI,2BAA2B;CACpG,MAAM,YAAYA,aAAAA,QAAQ,IAAI,mBAAmBA,aAAAA,QAAQ,IAAI;CAC7D,MAAM,kBAAkBE,UAAAA,QAAK,QAAQF,aAAAA,QAAQ,IAAI,GAAG,cAAcA,aAAAA,QAAQ,IAAI,qBAAqBC,kBAAAA,cAAc,UAAU;CAE3H,OAAO;EACL,MAAM;EACN,MAAM;EACN,YAAY;EACZ,UAAU;EACV;EACA,KAAK;GACH,GAAGD,aAAAA,QAAQ;GACX,MAAM;GACN,MAAM;GACN,iBAAiB;GACjB,mBAAmB;GACnB,wBAAwB,OAAO,kBAAkB;GACjD,sBAAsB,OAAO,gBAAgB;GAC7C,kBAAkBA,aAAAA,QAAQ,IAAI;GAC9B,0BAA0BA,aAAAA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cjs","names":["process","agentDefaults","path","net","process","Telemetry","path","agentDefaults","spawnAsync","getErrorMessage"],"sources":["../src/runners/agent/utils.ts","../src/runners/agent/run.ts"],"sourcesContent":["import net from 'node:net'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { agentDefaults } from '../../constants.ts'\n\ntype AgentStartEnvironmentInput = {\n /**\n * TCP port for the HTTP server. When `undefined`, falls back to `PORT` env var or the default (`3000`).\n */\n port: string | undefined\n /**\n * Hostname the HTTP server binds to.\n */\n host: string\n /**\n * Explicit path to the Kubb config file. When `undefined`, falls back to `KUBB_AGENT_CONFIG` or the default filename.\n */\n configPath: string | undefined\n /**\n * Grants the agent permission to write generated files to the filesystem.\n */\n allowWrite: boolean\n /**\n * Grants all agent permissions, including filesystem writes. Implies `allowWrite`.\n */\n allowAll: boolean\n}\n\ntype ResolvedAgentStartEnvironment = {\n /**\n * Final port string after merging CLI flag, `PORT` env var, and the default.\n */\n port: string\n /**\n * Final hostname after merging CLI flag, `HOST` env var, and the default.\n */\n host: string\n /**\n * Effective write-permission flag, accounting for `allowAll` and `KUBB_AGENT_ALLOW_WRITE`.\n */\n allowWrite: boolean\n /**\n * Effective all-permissions flag, accounting for `KUBB_AGENT_ALLOW_ALL`.\n */\n allowAll: boolean\n /**\n * Absolute path to the Kubb config file passed to the agent subprocess.\n */\n agentConfigPath: string\n /**\n * Merged `process.env` object with all resolved agent environment variables applied.\n */\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 */\nexport function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }: AgentStartEnvironmentInput): 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\nexport function 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","import { createRequire } from 'node:module'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { spawnAsync, getErrorMessage } from '@internals/utils'\nimport { Telemetry } from '@kubb/core'\nimport { agentDefaults } from '../../constants.ts'\nimport { isPortAvailable, resolveAgentStartEnvironment } from './utils.ts'\n\ntype AgentStartOptions = {\n /**\n * TCP port for the HTTP server. When `undefined`, falls back to `PORT` env var or the default (`3000`).\n */\n port: string | undefined\n /**\n * Hostname the HTTP server binds to.\n *\n * @default 'localhost'\n */\n host: string\n /**\n * Explicit path to the Kubb config file. When `undefined`, falls back to `KUBB_AGENT_CONFIG` or the default filename.\n */\n configPath: string | undefined\n /**\n * Grants the agent permission to write generated files to the filesystem.\n */\n allowWrite: boolean\n /**\n * Grants all agent permissions, including filesystem writes. Implies `allowWrite`.\n */\n allowAll: boolean\n /**\n * Current `@kubb/cli` version string, used for the telemetry payload.\n */\n version: string\n}\n\n/**\n * Spawns the Kubb Agent HTTP server as a Node.js subprocess.\n * Resolves config from CLI flags and environment variables, validates the port, and exits with code 1 on failure.\n */\nexport async function run({ port, host, configPath, allowWrite, allowAll, version }: AgentStartOptions): Promise<void> {\n const hrStart = process.hrtime()\n const report = (status: 'success' | 'failed') => Telemetry.send(Telemetry.build({ command: 'agent', kubbVersion: version, hrStart, status }))\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, createRequire is CJS/ESM compatible (import.meta.resolve is ESM-only)\n const require = createRequire(import.meta.url)\n let agentPkgPath: string\n try {\n agentPkgPath = require.resolve('@kubb/agent/package.json')\n } catch (_e) {\n console.error(styleText('red', 'The @kubb/agent package is not installed.'))\n console.error('')\n console.error('Install it with:')\n console.error(styleText('cyan', ' npm install @kubb/agent'))\n console.error(styleText('cyan', ' # or'))\n console.error(styleText('cyan', ' pnpm install @kubb/agent'))\n console.error('')\n process.exit(1)\n }\n const agentDir = path.dirname(agentPkgPath)\n const serverPath = path.join(agentDir, agentDefaults.serverEntryPath)\n\n const resolvedEnv = resolveAgentStartEnvironment({\n port,\n host,\n configPath,\n allowWrite,\n allowAll,\n })\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(styleText('red', `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`))\n process.exit(1)\n }\n\n // Spawns the server as a detached background process so the CLI can exit independently.\n // Reuse the runtime that launched the CLI (Bun or Node) via process.execPath so the\n // agent stays on the same runtime instead of forcing a `node` binary that may be absent.\n await spawnAsync(process.execPath, [serverPath], {\n env: resolvedEnv.env,\n cwd: process.cwd(),\n })\n\n await report('success')\n } catch (error) {\n await report('failed')\n clack.log.error(styleText('red', 'Failed to start agent server'))\n clack.log.error(getErrorMessage(error))\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,6BAA6B,EAAE,MAAM,MAAM,YAAY,YAAY,YAAuE;CACxJ,MAAM,eAAe,QAAQA,aAAAA,QAAQ,IAAI,QAAQC,kBAAAA,cAAc;CAC/D,MAAM,eAAe,SAASA,kBAAAA,cAAc,OAAO,OAAQD,aAAAA,QAAQ,IAAI,QAAQC,kBAAAA,cAAc;CAC7F,MAAM,mBAAmB,YAAYD,aAAAA,QAAQ,IAAI,yBAAyB;CAC1E,MAAM,qBAAqB,oBAAoB,cAAcA,aAAAA,QAAQ,IAAI,2BAA2B;CACpG,MAAM,YAAYA,aAAAA,QAAQ,IAAI,mBAAmBA,aAAAA,QAAQ,IAAI;CAC7D,MAAM,kBAAkBE,UAAAA,QAAK,QAAQF,aAAAA,QAAQ,IAAI,GAAG,cAAcA,aAAAA,QAAQ,IAAI,qBAAqBC,kBAAAA,cAAc,UAAU;CAE3H,OAAO;EACL,MAAM;EACN,MAAM;EACN,YAAY;EACZ,UAAU;EACV;EACA,KAAK;GACH,GAAGD,aAAAA,QAAQ;GACX,MAAM;GACN,MAAM;GACN,iBAAiB;GACjB,mBAAmB;GACnB,wBAAwB,OAAO,kBAA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eAAAA,gBAAgB,KAAK,CAAC;EACtC,aAAA,QAAQ,KAAK,CAAC;CAChB;AACF"}
|
|
@@ -111,7 +111,7 @@ async function installPackages(packages, packageManager, cwd = process$1.cwd())
|
|
|
111
111
|
}
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/runners/init/run.ts
|
|
114
|
-
function cancelAndExit(message = "Operation
|
|
114
|
+
function cancelAndExit(message = "Operation canceled.") {
|
|
115
115
|
clack.cancel(message);
|
|
116
116
|
process$1.exit(0);
|
|
117
117
|
}
|
|
@@ -244,4 +244,4 @@ async function run({ yes, version, input: inputFlag, output: outputFlag, plugins
|
|
|
244
244
|
//#endregion
|
|
245
245
|
export { run };
|
|
246
246
|
|
|
247
|
-
//# sourceMappingURL=run-
|
|
247
|
+
//# sourceMappingURL=run-CvEVkbIx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-CvEVkbIx.js","names":["process","process"],"sources":["../../../internals/utils/src/packageManager.ts","../../../internals/shared/src/init.ts","../src/runners/init/utils.ts","../src/runners/init/run.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { join } from 'node:path'\n\n/**\n * Supported package manager identifiers.\n *\n * @example\n * ```ts\n * const pm: PackageManagerName = 'pnpm'\n * ```\n */\nexport type PackageManagerName = 'npm' | 'pnpm' | 'yarn' | 'bun'\n\n/**\n * Metadata describing a package manager's lock file and install command.\n */\nexport interface PackageManagerInfo {\n /**\n * Identifier used in CLI commands, e.g. `pnpm`, `yarn`.\n */\n name: PackageManagerName\n /**\n * Lock file name that uniquely identifies this package manager in a project root.\n */\n lockFile: string\n /**\n * Subcommands passed to the package manager binary to install a dev dependency.\n */\n installCommand: ReadonlyArray<string>\n}\n/**\n * Metadata for each supported package manager, keyed by its short name.\n *\n * @example\n * ```ts\n * packageManagers.pnpm.installCommand // ['add', '-D']\n * packageManagers.npm.lockFile // 'package-lock.json'\n * ```\n */\nconst packageManagers: Record<PackageManagerName, PackageManagerInfo> = {\n pnpm: {\n name: 'pnpm',\n lockFile: 'pnpm-lock.yaml',\n installCommand: ['add', '-D'],\n },\n yarn: {\n name: 'yarn',\n lockFile: 'yarn.lock',\n installCommand: ['add', '-D'],\n },\n bun: {\n name: 'bun',\n lockFile: 'bun.lockb',\n installCommand: ['add', '-d'],\n },\n npm: {\n name: 'npm',\n lockFile: 'package-lock.json',\n installCommand: ['install', '--save-dev'],\n },\n}\n\n/**\n * Minimal shape of `package.json` fields read during detection.\n */\ntype PackageJson = {\n /**\n * The `packageManager` field from `package.json` (e.g. `\"pnpm@9.0.0\"`).\n */\n packageManager?: string\n}\n\n/**\n * Detects the active package manager for the given directory.\n * Resolution order: `packageManager` field in `package.json`, then presence of a lock file.\n * Falls back to `npm` when no signal is found.\n *\n * @example\n * ```ts\n * detectPackageManager('/my/project') // { name: 'pnpm', lockFile: 'pnpm-lock.yaml', ... }\n * detectPackageManager() // falls back to npm when no lock file is found\n * ```\n */\nexport function detectPackageManager(cwd: string = process.cwd()): PackageManagerInfo {\n const packageJsonPath = join(cwd, 'package.json')\n if (existsSync(packageJsonPath)) {\n try {\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as PackageJson\n const pmField = packageJson.packageManager\n if (typeof pmField === 'string') {\n const name = pmField.split('@')[0]\n if (name && name in packageManagers) {\n return packageManagers[name as PackageManagerName]\n }\n }\n } catch {\n // Continue to lock file detection\n }\n }\n\n for (const pm of Object.values(packageManagers)) {\n if (existsSync(join(cwd, pm.lockFile))) {\n return pm\n }\n }\n\n return packageManagers.npm\n}\n","import { pluginDefaultConfigs } from './constants.ts'\nimport type { PluginOption } from './types.ts'\n\nexport function generateConfigFile({\n selectedPlugins,\n inputPath,\n outputPath,\n}: {\n selectedPlugins: PluginOption[]\n inputPath: string\n outputPath: string\n}): string {\n const imports = selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`).join('\\n')\n\n const pluginConfigs = selectedPlugins\n .map((plugin) => {\n const config = (pluginDefaultConfigs as Record<string, string>)[plugin.value] ?? `${plugin.importName}()`\n return ` ${config},`\n })\n .join('\\n')\n\n return `import { defineConfig } from 'kubb'\n${imports}\n\nexport default defineConfig({\n root: '.',\n input: {\n path: '${inputPath}',\n },\n output: {\n path: '${outputPath}',\n clean: true,\n },\n plugins: [\n${pluginConfigs}\n ],\n})\n`\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport type { PackageManagerInfo, PackageManagerName } from '@internals/utils'\nimport { spawnAsync } from '@internals/utils'\n\n/**\n * Returns `true` when a `package.json` exists at `cwd`.\n */\nexport function hasPackageJson(cwd: string = process.cwd()): boolean {\n return fs.existsSync(path.join(cwd, 'package.json'))\n}\n\n/**\n * Initializes a new `package.json` at `cwd` using the detected package manager.\n */\nexport async function initPackageJson(cwd: string, packageManager: PackageManagerInfo): Promise<void> {\n const commands: Record<PackageManagerName, Array<string>> = {\n npm: ['init', '-y'],\n pnpm: ['init'],\n yarn: ['init', '-y'],\n bun: ['init', '-y'],\n }\n\n await spawnAsync(packageManager.name, commands[packageManager.name], { cwd })\n}\n\n/**\n * Installs the given packages at `cwd` using the detected package manager.\n */\nexport async function installPackages(packages: Array<string>, packageManager: PackageManagerInfo, cwd: string = process.cwd()): Promise<void> {\n await spawnAsync(packageManager.name, [...packageManager.installCommand, ...packages], { cwd })\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { detectPackageManager } from '@internals/utils'\nimport { availablePlugins, generateConfigFile, initDefaults, KUBB_CONFIG_FILENAME, type PluginOption } from '@internals/shared'\nimport { hasPackageJson, initPackageJson, installPackages } from './utils.ts'\n\nfunction cancelAndExit(message = 'Operation canceled.'): never {\n clack.cancel(message)\n process.exit(0)\n}\n\ntype InitOptions = {\n /**\n * When `true`, skips all interactive prompts and uses default values.\n */\n yes: boolean\n /**\n * Current `@kubb/cli` version string, shown in the outro and used for package installation.\n */\n version: string\n /**\n * Input path flag value from `--input`. When provided, skips the input prompt.\n */\n input?: string\n /**\n * Output directory flag value from `--output`. When provided, skips the output prompt.\n */\n output?: string\n /**\n * Comma-separated plugin list from `--plugins`, e.g. `'plugin-ts,plugin-zod'`. When provided, skips the plugin selection prompt.\n */\n plugins?: string\n}\n\n/**\n * Runs the interactive Kubb scaffolding wizard.\n * Detects the package manager, prompts for input/output paths and plugins, installs packages, and writes `kubb.config.ts`.\n * Pass `yes: true` to skip all prompts and use defaults.\n */\nexport async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag }: InitOptions): Promise<void> {\n const cwd = process.cwd()\n\n clack.intro(styleText('bgCyan', styleText('black', ' Kubb Init ')))\n\n /**\n * Returns `flag` when provided, the `defaultValue` when `yes` is set,\n * or calls `prompt()` for interactive input. Exits on cancellation.\n */\n async function resolveOrPrompt<T>(flag: T | undefined, defaultValue: T, logLabel: string, prompt: () => Promise<T | symbol>): Promise<T> {\n if (flag !== undefined) {\n clack.log.info(`${logLabel}: ${styleText('cyan', String(flag))}`)\n return flag\n }\n if (yes) {\n clack.log.info(`${logLabel}: ${styleText('cyan', String(defaultValue))}`)\n return defaultValue\n }\n const result = await prompt()\n if (clack.isCancel(result)) cancelAndExit()\n return result as T\n }\n\n try {\n // Check/create package.json, detect package manager once after the block\n if (!hasPackageJson(cwd)) {\n if (!yes) {\n const shouldInit = await clack.confirm({\n message: 'No package.json found. Would you like to create one?',\n initialValue: true,\n })\n\n if (clack.isCancel(shouldInit) || !shouldInit) {\n cancelAndExit()\n }\n }\n\n const packageManager = detectPackageManager(cwd)\n const spinner = clack.spinner()\n spinner.start(`Initializing package.json with ${packageManager.name}`)\n await initPackageJson(cwd, packageManager)\n spinner.stop(`Created package.json with ${packageManager.name}`)\n }\n\n const packageManager = detectPackageManager(cwd)\n if (hasPackageJson(cwd)) {\n clack.log.info(`Detected package manager: ${styleText('cyan', packageManager.name)}`)\n }\n\n // Prompt for OpenAPI spec path\n const inputPath = await resolveOrPrompt(inputFlag, initDefaults.inputPath, 'Using input path', () =>\n clack.text({\n message: 'Where is your OpenAPI specification located?',\n placeholder: initDefaults.inputPath,\n defaultValue: initDefaults.inputPath,\n validate: (value) => {\n if (!value) return 'Input path is required'\n },\n }),\n )\n\n // Prompt for output directory\n const outputPath = await resolveOrPrompt(outputFlag, initDefaults.outputPath, 'Using output path', () =>\n clack.text({\n message: 'Where should the generated files be output?',\n placeholder: initDefaults.outputPath,\n defaultValue: initDefaults.outputPath,\n validate: (value) => {\n if (!value) return 'Output path is required'\n },\n }),\n )\n\n // Plugin selection\n const defaultPlugins = availablePlugins.filter((p) => (initDefaults.plugins as ReadonlyArray<string>).includes(p.value))\n const pluginLabel = (plugins: Array<PluginOption>) => styleText('cyan', plugins.map((p) => p.label).join(', '))\n\n const selectedPlugins: Array<PluginOption> = await (async () => {\n if (pluginsFlag) {\n const requested = pluginsFlag\n .split(',')\n .map((v) => v.trim())\n .filter(Boolean)\n const plugins = availablePlugins.filter((p) => requested.includes(p.value))\n if (plugins.length === 0) {\n clack.log.warn(`No valid plugins found in --plugins value; falling back to default: ${pluginLabel(defaultPlugins)}`)\n return defaultPlugins\n }\n clack.log.info(`Using plugins: ${pluginLabel(plugins)}`)\n return plugins\n }\n if (yes) {\n clack.log.info(`Using plugins: ${pluginLabel(defaultPlugins)}`)\n return defaultPlugins\n }\n const values = await clack.multiselect({\n message: 'Select plugins to use:',\n options: availablePlugins.map(({ value, label, hint }) => ({ value, label, hint })),\n initialValues: [...initDefaults.plugins],\n required: true,\n })\n if (clack.isCancel(values)) cancelAndExit()\n return availablePlugins.filter((p) => (values as Array<string>).includes(p.value))\n })()\n\n // Install packages\n const packagesToInstall = ['kubb', ...selectedPlugins.map((p) => p.packageName)]\n\n const spinner = clack.spinner()\n spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`)\n\n try {\n await installPackages(packagesToInstall, packageManager, cwd)\n spinner.stop(`Installed ${packagesToInstall.length} packages`)\n } catch (error) {\n spinner.stop('Installation failed')\n throw error\n }\n\n // Generate config file\n const configSpinner = clack.spinner()\n configSpinner.start(`Creating ${KUBB_CONFIG_FILENAME}`)\n\n const configContent = generateConfigFile({ selectedPlugins, inputPath, outputPath })\n const configPath = path.join(cwd, KUBB_CONFIG_FILENAME)\n\n if (fs.existsSync(configPath)) {\n configSpinner.stop(`${KUBB_CONFIG_FILENAME} already exists`)\n\n if (!yes) {\n const shouldOverwrite = await clack.confirm({\n message: `${KUBB_CONFIG_FILENAME} already exists. Overwrite?`,\n initialValue: false,\n })\n\n if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) {\n cancelAndExit('Keeping existing configuration. Packages have been installed.')\n }\n }\n\n configSpinner.start(`Overwriting ${KUBB_CONFIG_FILENAME}`)\n }\n\n await fs.promises.writeFile(configPath, configContent, 'utf-8')\n\n configSpinner.stop(`Created ${KUBB_CONFIG_FILENAME}`)\n\n clack.outro(\n styleText('green', '✓ All set!') +\n '\\n\\n' +\n styleText('dim', 'Next steps:') +\n '\\n' +\n styleText('cyan', ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) +\n '\\n' +\n styleText('cyan', ' 2. Generate code with: npx kubb generate') +\n '\\n' +\n styleText('cyan', ' Or start a stream server with: npx kubb agent start') +\n '\\n' +\n styleText('cyan', ` 3. Find generated files in: ${outputPath}`) +\n '\\n\\n' +\n styleText('dim', `Using ${packageManager.name} • Kubb v${version}`),\n )\n } catch (error) {\n clack.log.error(styleText('red', 'An error occurred during initialization'))\n if (error instanceof Error) {\n clack.log.error(error.message)\n }\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuCA,MAAM,kBAAkE;CACtE,MAAM;EACJ,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OAAO,IAAI;CAC9B;CACA,MAAM;EACJ,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OAAO,IAAI;CAC9B;CACA,KAAK;EACH,MAAM;EACN,UAAU;EACV,gBAAgB,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,4CAA4C,IAC9D,OACA,UAAU,QAAQ,0DAA0D,IAC5E,OACA,UAAU,QAAQ,iCAAiC,YAAY,IAC/D,SACA,UAAU,OAAO,SAAS,eAAe,KAAK,WAAW,SAAS,CACtE;CACF,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,UAAU,OAAO,yCAAyC,CAAC;EAC3E,IAAI,iBAAiB,OACnB,MAAM,IAAI,MAAM,MAAM,OAAO;EAE/B,UAAQ,KAAK,CAAC;CAChB;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-Bx3C2hgW.cjs");
|
|
2
2
|
const require_errors = require("./errors-DykI11xo.cjs");
|
|
3
3
|
const require_shell = require("./shell-Lh-vLWwH.cjs");
|
|
4
|
-
const require_package = require("./package-
|
|
4
|
+
const require_package = require("./package-DE-_IDOs.cjs");
|
|
5
5
|
const require_constants = require("./constants-BtmponZ3.cjs");
|
|
6
6
|
let node_util = require("node:util");
|
|
7
7
|
let node_events = require("node:events");
|
|
@@ -306,19 +306,6 @@ function formatMsWithColor(ms) {
|
|
|
306
306
|
//#endregion
|
|
307
307
|
//#region ../../internals/utils/src/env.ts
|
|
308
308
|
/**
|
|
309
|
-
* Returns `true` when running inside a GitHub Actions workflow.
|
|
310
|
-
*
|
|
311
|
-
* @example
|
|
312
|
-
* ```ts
|
|
313
|
-
* if (isGitHubActions()) {
|
|
314
|
-
* core.setOutput('result', 'ok')
|
|
315
|
-
* }
|
|
316
|
-
* ```
|
|
317
|
-
*/
|
|
318
|
-
function isGitHubActions() {
|
|
319
|
-
return !!process.env.GITHUB_ACTIONS;
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
309
|
* Returns `true` when the process is running in a CI environment.
|
|
323
310
|
* Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,
|
|
324
311
|
* TeamCity, Buildkite, and Azure Pipelines.
|
|
@@ -766,8 +753,18 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
766
753
|
hrStart: node_process.default.hrtime()
|
|
767
754
|
});
|
|
768
755
|
});
|
|
769
|
-
context.on("kubb:hook:
|
|
770
|
-
|
|
756
|
+
if (logLevel > _kubb_core.logLevel.silent) context.on("kubb:hook:line", ({ id, line }) => {
|
|
757
|
+
state.activeHookLogs.get(id)?.taskLog.message((0, node_util.styleText)("dim", line));
|
|
758
|
+
});
|
|
759
|
+
context.on("kubb:hook:end", ({ id, command, args, success, error, stdout, stderr }) => {
|
|
760
|
+
if (!id) return;
|
|
761
|
+
if (logLevel <= _kubb_core.logLevel.silent) {
|
|
762
|
+
if (!success) {
|
|
763
|
+
if (stdout) console.log(stdout);
|
|
764
|
+
if (stderr) console.error(stderr);
|
|
765
|
+
}
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
771
768
|
const active = state.activeHookLogs.get(id);
|
|
772
769
|
if (!active) return;
|
|
773
770
|
state.activeHookLogs.delete(id);
|
|
@@ -782,233 +779,6 @@ Run \`npm install -g @kubb/cli\` to update`, "Update available for `Kubb`", {
|
|
|
782
779
|
context.on("kubb:lifecycle:end", () => {
|
|
783
780
|
reset();
|
|
784
781
|
});
|
|
785
|
-
return (_commandWithArgs, hookId) => {
|
|
786
|
-
if (logLevel <= _kubb_core.logLevel.silent) return {
|
|
787
|
-
onStdout: (s) => console.log(s),
|
|
788
|
-
onStderr: (s) => console.error(s)
|
|
789
|
-
};
|
|
790
|
-
const active = state.activeHookLogs.get(hookId);
|
|
791
|
-
if (!active) return null;
|
|
792
|
-
const { taskLog } = active;
|
|
793
|
-
return {
|
|
794
|
-
stream: true,
|
|
795
|
-
onLine: (line) => taskLog.message((0, node_util.styleText)("dim", line)),
|
|
796
|
-
onStdout: (s) => taskLog.message(s),
|
|
797
|
-
onStderr: (s) => taskLog.message((0, node_util.styleText)("red", s))
|
|
798
|
-
};
|
|
799
|
-
};
|
|
800
|
-
}
|
|
801
|
-
});
|
|
802
|
-
//#endregion
|
|
803
|
-
//#region src/loggers/githubActionsLogger.ts
|
|
804
|
-
/**
|
|
805
|
-
* GitHub Actions logger using group annotations for collapsible sections in CI.
|
|
806
|
-
*/
|
|
807
|
-
const githubActionsLogger = (0, _kubb_core.defineLogger)({
|
|
808
|
-
name: "github-actions",
|
|
809
|
-
install(context, options) {
|
|
810
|
-
const logLevel = options?.logLevel ?? _kubb_core.logLevel.info;
|
|
811
|
-
const state = {
|
|
812
|
-
...createProgressCounters(),
|
|
813
|
-
currentConfigs: [],
|
|
814
|
-
openGroupDepth: 0
|
|
815
|
-
};
|
|
816
|
-
const hookTimer = createHookTimer();
|
|
817
|
-
function reset() {
|
|
818
|
-
closeAllGroups();
|
|
819
|
-
resetProgressCounters(state);
|
|
820
|
-
state.currentConfigs = [];
|
|
821
|
-
hookTimer.clear();
|
|
822
|
-
}
|
|
823
|
-
function showProgressStep() {
|
|
824
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
825
|
-
const line = buildProgressLine(state);
|
|
826
|
-
if (line) console.log(getMessage(line));
|
|
827
|
-
}
|
|
828
|
-
function getMessage(message) {
|
|
829
|
-
return formatMessage(message, logLevel);
|
|
830
|
-
}
|
|
831
|
-
function openGroup(name) {
|
|
832
|
-
console.log(`::group::${name}`);
|
|
833
|
-
state.openGroupDepth++;
|
|
834
|
-
}
|
|
835
|
-
function closeGroup(_name) {
|
|
836
|
-
console.log("::endgroup::");
|
|
837
|
-
if (state.openGroupDepth > 0) state.openGroupDepth--;
|
|
838
|
-
}
|
|
839
|
-
function closeAllGroups() {
|
|
840
|
-
while (state.openGroupDepth > 0) {
|
|
841
|
-
console.log("::endgroup::");
|
|
842
|
-
state.openGroupDepth--;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
function onGroupStart(event, message, group) {
|
|
846
|
-
context.on(event, () => {
|
|
847
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
848
|
-
if (state.currentConfigs.length === 1) openGroup(group);
|
|
849
|
-
console.log(getMessage(message));
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
function onGroupEnd(event, message, group) {
|
|
853
|
-
context.on(event, () => {
|
|
854
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
855
|
-
console.log(getMessage(message));
|
|
856
|
-
if (state.currentConfigs.length === 1) closeGroup(group);
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
context.on("kubb:info", ({ message, info = "" }) => {
|
|
860
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
861
|
-
const text = getMessage([
|
|
862
|
-
(0, node_util.styleText)("blue", "ℹ"),
|
|
863
|
-
message,
|
|
864
|
-
(0, node_util.styleText)("dim", info)
|
|
865
|
-
].join(" "));
|
|
866
|
-
console.log(text);
|
|
867
|
-
});
|
|
868
|
-
context.on("kubb:success", ({ message, info = "" }) => {
|
|
869
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
870
|
-
const text = getMessage([
|
|
871
|
-
(0, node_util.styleText)("blue", "✓"),
|
|
872
|
-
message,
|
|
873
|
-
logLevel >= _kubb_core.logLevel.info ? (0, node_util.styleText)("dim", info) : void 0
|
|
874
|
-
].filter(Boolean).join(" "));
|
|
875
|
-
console.log(text);
|
|
876
|
-
});
|
|
877
|
-
context.on("kubb:warn", ({ message, info = "" }) => {
|
|
878
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
879
|
-
const text = getMessage([
|
|
880
|
-
(0, node_util.styleText)("yellow", "⚠"),
|
|
881
|
-
message,
|
|
882
|
-
logLevel >= _kubb_core.logLevel.info ? (0, node_util.styleText)("dim", info) : void 0
|
|
883
|
-
].filter(Boolean).join(" "));
|
|
884
|
-
console.warn(`::warning::${text}`);
|
|
885
|
-
});
|
|
886
|
-
context.on("kubb:error", ({ error }) => {
|
|
887
|
-
const caused = require_errors.toCause(error);
|
|
888
|
-
closeAllGroups();
|
|
889
|
-
const message = error.message || String(error);
|
|
890
|
-
console.error(`::error::${message}`);
|
|
891
|
-
if (logLevel >= _kubb_core.logLevel.verbose && error.stack) {
|
|
892
|
-
const frames = error.stack.split("\n").slice(1, 4);
|
|
893
|
-
for (const frame of frames) console.log(getMessage((0, node_util.styleText)("dim", frame.trim())));
|
|
894
|
-
if (caused?.stack) {
|
|
895
|
-
console.log((0, node_util.styleText)("dim", `└─ caused by ${caused.message}`));
|
|
896
|
-
const frames = caused.stack.split("\n").slice(1, 4);
|
|
897
|
-
for (const frame of frames) console.log(getMessage(` ${(0, node_util.styleText)("dim", frame.trim())}`));
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
context.on("kubb:diagnostic", ({ diagnostic }) => {
|
|
902
|
-
closeAllGroups();
|
|
903
|
-
if (logLevel <= _kubb_core.logLevel.silent && diagnostic.severity !== "error") return;
|
|
904
|
-
if (!_kubb_core.Diagnostics.isProblem(diagnostic)) {
|
|
905
|
-
console.log(`::notice::${diagnostic.message}`);
|
|
906
|
-
return;
|
|
907
|
-
}
|
|
908
|
-
const parts = [`${diagnostic.code} ${diagnostic.message}`];
|
|
909
|
-
if (diagnostic.location && "pointer" in diagnostic.location) parts.push(`(at ${diagnostic.location.pointer})`);
|
|
910
|
-
if (diagnostic.plugin) parts.push(`[plugin: ${diagnostic.plugin}]`);
|
|
911
|
-
if (diagnostic.help) parts.push(`help: ${diagnostic.help}`);
|
|
912
|
-
if (diagnostic.code !== _kubb_core.Diagnostics.code.unknown) parts.push(`docs: ${_kubb_core.Diagnostics.docsUrl(diagnostic.code)}`);
|
|
913
|
-
console.error(`::error::${parts.join(" ")}`);
|
|
914
|
-
});
|
|
915
|
-
context.on("kubb:lifecycle:start", ({ version }) => {
|
|
916
|
-
console.log((0, node_util.styleText)("yellow", `Kubb ${version} 🧩`));
|
|
917
|
-
reset();
|
|
918
|
-
});
|
|
919
|
-
context.on("kubb:config:start", () => {
|
|
920
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
921
|
-
const text = getMessage("Configuration started");
|
|
922
|
-
openGroup("Configuration");
|
|
923
|
-
console.log(text);
|
|
924
|
-
});
|
|
925
|
-
context.on("kubb:config:end", ({ configs }) => {
|
|
926
|
-
state.currentConfigs = configs;
|
|
927
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
928
|
-
const text = getMessage("Configuration completed");
|
|
929
|
-
console.log(text);
|
|
930
|
-
closeGroup("Configuration");
|
|
931
|
-
});
|
|
932
|
-
context.on("kubb:generation:start", ({ config }) => {
|
|
933
|
-
reset();
|
|
934
|
-
state.totalPlugins = config.plugins?.length ?? 0;
|
|
935
|
-
const text = config.name ? `Generation for ${(0, node_util.styleText)("bold", config.name)}` : "Generation";
|
|
936
|
-
if (state.currentConfigs.length > 1) openGroup(text);
|
|
937
|
-
if (state.currentConfigs.length === 1) console.log(getMessage(text));
|
|
938
|
-
});
|
|
939
|
-
context.on("kubb:plugin:start", ({ plugin }) => {
|
|
940
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
941
|
-
const text = getMessage(`Generating ${(0, node_util.styleText)("bold", plugin.name)}`);
|
|
942
|
-
if (state.currentConfigs.length === 1) openGroup(`Plugin: ${plugin.name}`);
|
|
943
|
-
console.log(text);
|
|
944
|
-
});
|
|
945
|
-
context.on("kubb:plugin:end", ({ plugin, duration, success }) => {
|
|
946
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
947
|
-
recordPluginResult(state, success);
|
|
948
|
-
const durationStr = formatMsWithColor(duration);
|
|
949
|
-
const text = getMessage(success ? `${(0, node_util.styleText)("bold", plugin.name)} completed in ${durationStr}` : `${(0, node_util.styleText)("bold", plugin.name)} failed in ${(0, node_util.styleText)("red", formatMs(duration))}`);
|
|
950
|
-
console.log(text);
|
|
951
|
-
if (state.currentConfigs.length > 1) console.log(" ");
|
|
952
|
-
if (state.currentConfigs.length === 1) closeGroup(`Plugin: ${plugin.name}`);
|
|
953
|
-
showProgressStep();
|
|
954
|
-
});
|
|
955
|
-
context.on("kubb:files:processing:start", ({ files }) => {
|
|
956
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
957
|
-
state.totalFiles = files.length;
|
|
958
|
-
state.processedFiles = 0;
|
|
959
|
-
if (state.currentConfigs.length === 1) openGroup("File Generation");
|
|
960
|
-
const text = getMessage(`Writing ${files.length} files`);
|
|
961
|
-
console.log(text);
|
|
962
|
-
});
|
|
963
|
-
context.on("kubb:files:processing:end", () => {
|
|
964
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
965
|
-
const text = getMessage("Files written successfully");
|
|
966
|
-
console.log(text);
|
|
967
|
-
if (state.currentConfigs.length === 1) closeGroup("File Generation");
|
|
968
|
-
showProgressStep();
|
|
969
|
-
});
|
|
970
|
-
context.on("kubb:files:processing:update", ({ files }) => {
|
|
971
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
972
|
-
state.processedFiles += files.length;
|
|
973
|
-
});
|
|
974
|
-
context.on("kubb:generation:end", ({ config }) => {
|
|
975
|
-
const text = getMessage(config.name ? `${(0, node_util.styleText)("blue", "✓")} Generation completed for ${(0, node_util.styleText)("dim", config.name)}` : `${(0, node_util.styleText)("blue", "✓")} Generation completed`);
|
|
976
|
-
console.log(text);
|
|
977
|
-
if (state.currentConfigs.length > 1) closeGroup(config.name ? `Generation for ${(0, node_util.styleText)("bold", config.name)}` : "Generation");
|
|
978
|
-
});
|
|
979
|
-
onGroupStart("kubb:format:start", "Format started", "Formatting");
|
|
980
|
-
onGroupEnd("kubb:format:end", "Format completed", "Formatting");
|
|
981
|
-
onGroupStart("kubb:lint:start", "Lint started", "Linting");
|
|
982
|
-
onGroupEnd("kubb:lint:end", "Lint completed", "Linting");
|
|
983
|
-
onGroupStart("kubb:hooks:start", "Hooks started", "Hooks");
|
|
984
|
-
onGroupEnd("kubb:hooks:end", "Hooks completed", "Hooks");
|
|
985
|
-
context.on("kubb:hook:start", ({ id, command, args }) => {
|
|
986
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
987
|
-
if (id) hookTimer.start(id);
|
|
988
|
-
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
989
|
-
const text = getMessage(`Hook ${(0, node_util.styleText)("dim", commandWithArgs)} started`);
|
|
990
|
-
if (state.currentConfigs.length === 1) openGroup(`Hook ${commandWithArgs}`);
|
|
991
|
-
console.log(text);
|
|
992
|
-
});
|
|
993
|
-
context.on("kubb:hook:end", ({ id, command, args, success, error }) => {
|
|
994
|
-
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
995
|
-
const ms = id ? hookTimer.end(id) : void 0;
|
|
996
|
-
const durationStr = ms !== void 0 ? ` in ${formatMsWithColor(ms)}` : "";
|
|
997
|
-
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
998
|
-
if (success) console.log(getMessage(`${(0, node_util.styleText)("green", "✓")} Hook ${(0, node_util.styleText)("dim", commandWithArgs)} completed${durationStr}`));
|
|
999
|
-
else {
|
|
1000
|
-
const reason = error?.message ? ` (${error.message})` : "";
|
|
1001
|
-
console.log(`::error::Hook ${commandWithArgs} failed${durationStr}${reason}`);
|
|
1002
|
-
}
|
|
1003
|
-
if (state.currentConfigs.length === 1) closeGroup(`Hook ${commandWithArgs}`);
|
|
1004
|
-
});
|
|
1005
|
-
context.on("kubb:lifecycle:end", () => {
|
|
1006
|
-
reset();
|
|
1007
|
-
});
|
|
1008
|
-
return (_commandWithArgs, _hookId) => ({
|
|
1009
|
-
onStdout: logLevel > _kubb_core.logLevel.silent ? (s) => console.log(s) : void 0,
|
|
1010
|
-
onStderr: logLevel > _kubb_core.logLevel.silent ? (s) => console.error(`::error::${s}`) : void 0
|
|
1011
|
-
});
|
|
1012
782
|
}
|
|
1013
783
|
});
|
|
1014
784
|
//#endregion
|
|
@@ -1125,21 +895,19 @@ const plainLogger = (0, _kubb_core.defineLogger)({
|
|
|
1125
895
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
1126
896
|
console.log(getMessage(`Hook ${commandWithArgs} started`));
|
|
1127
897
|
});
|
|
1128
|
-
context.on("kubb:hook:end", ({ id, command, args, success, error }) => {
|
|
898
|
+
context.on("kubb:hook:end", ({ id, command, args, success, error, stdout, stderr }) => {
|
|
1129
899
|
if (logLevel <= _kubb_core.logLevel.silent) return;
|
|
1130
900
|
const ms = id ? hookTimer.end(id) : void 0;
|
|
1131
901
|
const durationStr = ms !== void 0 ? ` in ${formatMs(ms)}` : "";
|
|
1132
902
|
const commandWithArgs = formatCommandWithArgs(command, args);
|
|
1133
903
|
if (success) console.log(getMessage(`✓ Hook ${commandWithArgs} completed${durationStr}`));
|
|
1134
904
|
else {
|
|
905
|
+
if (stdout) console.log(stdout);
|
|
906
|
+
if (stderr) console.error(stderr);
|
|
1135
907
|
const reason = error?.message ? ` (${error.message})` : "";
|
|
1136
908
|
console.log(getMessage(`✗ Hook ${commandWithArgs} failed${durationStr}${reason}`));
|
|
1137
909
|
}
|
|
1138
910
|
});
|
|
1139
|
-
return (_commandWithArgs, _hookId) => ({
|
|
1140
|
-
onStdout: logLevel > _kubb_core.logLevel.silent ? (s) => console.log(s) : void 0,
|
|
1141
|
-
onStderr: logLevel > _kubb_core.logLevel.silent ? (s) => console.error(s) : void 0
|
|
1142
|
-
});
|
|
1143
911
|
}
|
|
1144
912
|
});
|
|
1145
913
|
//#endregion
|
|
@@ -1158,7 +926,7 @@ function formatMessage(message, logLevel) {
|
|
|
1158
926
|
return message;
|
|
1159
927
|
}
|
|
1160
928
|
/**
|
|
1161
|
-
* Build the progress summary line
|
|
929
|
+
* Build the progress summary line shown by the clack logger.
|
|
1162
930
|
* Returns null when there is nothing to display.
|
|
1163
931
|
*/
|
|
1164
932
|
function buildProgressLine(state) {
|
|
@@ -1174,7 +942,7 @@ function buildProgressLine(state) {
|
|
|
1174
942
|
return parts.join((0, node_util.styleText)("dim", " | "));
|
|
1175
943
|
}
|
|
1176
944
|
/**
|
|
1177
|
-
* Creates the per-run progress counters
|
|
945
|
+
* Creates the per-run progress counters used by the clack logger.
|
|
1178
946
|
*/
|
|
1179
947
|
function createProgressCounters() {
|
|
1180
948
|
return {
|
|
@@ -1232,14 +1000,12 @@ function formatCommandWithArgs(command, args) {
|
|
|
1232
1000
|
return args?.length ? `${command} ${args.join(" ")}` : command;
|
|
1233
1001
|
}
|
|
1234
1002
|
function detectLogger() {
|
|
1235
|
-
if (isGitHubActions()) return "github-actions";
|
|
1236
1003
|
if (canUseTTY()) return "clack";
|
|
1237
1004
|
return "plain";
|
|
1238
1005
|
}
|
|
1239
1006
|
const logMapper = {
|
|
1240
1007
|
clack: clackLogger,
|
|
1241
|
-
plain: plainLogger
|
|
1242
|
-
"github-actions": githubActionsLogger
|
|
1008
|
+
plain: plainLogger
|
|
1243
1009
|
};
|
|
1244
1010
|
/**
|
|
1245
1011
|
* Bridges a {@link Reporter} onto the run's event emitter: calls `report` with each config's
|
|
@@ -1258,9 +1024,10 @@ function installReporter(context, reporter, ctx) {
|
|
|
1258
1024
|
if (reporter.drain) context.on("kubb:lifecycle:end", () => reporter.drain?.(ctx));
|
|
1259
1025
|
}
|
|
1260
1026
|
/**
|
|
1261
|
-
* Installs the live logger (the TUI view) and the given reporters (the output)
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
1027
|
+
* Installs the live logger (the TUI view) and the given reporters (the output). The reporters are
|
|
1028
|
+
* already selected by the caller (the CLI maps `--reporter` to names via `selectReporters`); this
|
|
1029
|
+
* only wires them. Loggers receive hook subprocess output through `kubb:hook:line` and the
|
|
1030
|
+
* `stdout`/`stderr` on `kubb:hook:end`, so nothing is returned here.
|
|
1264
1031
|
*
|
|
1265
1032
|
* Loggers and reporters are independent: the `cli` reporter also activates the env logger summary.
|
|
1266
1033
|
* The `json` reporter owns stdout, so the live logger and the `cli` summary are suppressed whenever
|
|
@@ -1269,19 +1036,16 @@ function installReporter(context, reporter, ctx) {
|
|
|
1269
1036
|
async function setupReporters(context, { logLevel, reporters }) {
|
|
1270
1037
|
const hasJson = reporters.some((reporter) => reporter.name === "json");
|
|
1271
1038
|
const ctx = { logLevel };
|
|
1272
|
-
let makeSink = null;
|
|
1273
1039
|
for (const reporter of reporters) {
|
|
1274
1040
|
if (reporter.name === "cli") {
|
|
1275
1041
|
if (hasJson) continue;
|
|
1276
1042
|
const type = detectLogger();
|
|
1277
1043
|
const logger = logMapper[type];
|
|
1278
1044
|
if (!logger) throw new Error(`Unknown adapter type: ${type}`);
|
|
1279
|
-
|
|
1280
|
-
makeSink = typeof sink === "function" ? sink : null;
|
|
1045
|
+
await logger.install(context, { logLevel });
|
|
1281
1046
|
}
|
|
1282
1047
|
installReporter(context, reporter, ctx);
|
|
1283
1048
|
}
|
|
1284
|
-
return makeSink;
|
|
1285
1049
|
}
|
|
1286
1050
|
//#endregion
|
|
1287
1051
|
//#region src/runners/generate/utils.ts
|
|
@@ -1362,48 +1126,46 @@ async function getConfigs({ configPath, input, watch, logLevel }) {
|
|
|
1362
1126
|
/**
|
|
1363
1127
|
* Runs the `done` hooks defined in a Kubb config in sequence.
|
|
1364
1128
|
*/
|
|
1365
|
-
async function executeHooks({ configHooks, hooks
|
|
1129
|
+
async function executeHooks({ configHooks, hooks }) {
|
|
1366
1130
|
const commands = Array.isArray(configHooks.done) ? configHooks.done : [configHooks.done].filter(Boolean);
|
|
1367
1131
|
for (const command of commands) {
|
|
1368
1132
|
const [cmd, ...args] = require_shell.tokenize(command);
|
|
1369
1133
|
if (!cmd) continue;
|
|
1370
|
-
const hookId = (0, node_crypto.
|
|
1134
|
+
const hookId = (0, node_crypto.hash)("sha256", command, "hex");
|
|
1371
1135
|
const commandWithArgs = [cmd, ...args].join(" ");
|
|
1372
1136
|
await hooks.emit("kubb:hook:start", {
|
|
1373
1137
|
id: hookId,
|
|
1374
1138
|
command: cmd,
|
|
1375
1139
|
args
|
|
1376
1140
|
});
|
|
1377
|
-
const { stream = false, onLine, onStdout, onStderr } = makeSink?.(commandWithArgs, hookId) ?? {};
|
|
1378
1141
|
await runHook({
|
|
1379
1142
|
id: hookId,
|
|
1380
1143
|
command: cmd,
|
|
1381
1144
|
args,
|
|
1382
1145
|
commandWithArgs,
|
|
1383
|
-
hooks
|
|
1384
|
-
stream,
|
|
1385
|
-
sink: {
|
|
1386
|
-
onLine,
|
|
1387
|
-
onStdout,
|
|
1388
|
-
onStderr
|
|
1389
|
-
}
|
|
1146
|
+
hooks
|
|
1390
1147
|
});
|
|
1391
1148
|
}
|
|
1392
1149
|
}
|
|
1393
|
-
async function runHook({ id, command, args, commandWithArgs, hooks
|
|
1394
|
-
const emitEnd = (success, error) => hooks.emit("kubb:hook:end", {
|
|
1150
|
+
async function runHook({ id, command, args, commandWithArgs, hooks }) {
|
|
1151
|
+
const emitEnd = (success, error, output) => hooks.emit("kubb:hook:end", {
|
|
1395
1152
|
command,
|
|
1396
1153
|
args,
|
|
1397
1154
|
id,
|
|
1398
1155
|
success,
|
|
1399
|
-
error
|
|
1156
|
+
error,
|
|
1157
|
+
...output
|
|
1400
1158
|
});
|
|
1159
|
+
const stream = hooks.listenerCount("kubb:hook:line") > 0;
|
|
1401
1160
|
try {
|
|
1402
1161
|
const proc = (0, tinyexec.x)(command, [...args ?? []], {
|
|
1403
1162
|
nodeOptions: { detached: process.platform !== "win32" },
|
|
1404
1163
|
throwOnError: true
|
|
1405
1164
|
});
|
|
1406
|
-
if (stream
|
|
1165
|
+
if (stream) for await (const line of proc) await hooks.emit("kubb:hook:line", {
|
|
1166
|
+
id,
|
|
1167
|
+
line
|
|
1168
|
+
});
|
|
1407
1169
|
await proc;
|
|
1408
1170
|
await hooks.emit("kubb:success", { message: `${(0, node_util.styleText)("dim", commandWithArgs)} successfully executed` });
|
|
1409
1171
|
await emitEnd(true, null);
|
|
@@ -1414,9 +1176,10 @@ async function runHook({ id, command, args, commandWithArgs, hooks, stream = fal
|
|
|
1414
1176
|
}
|
|
1415
1177
|
const stderr = err.output?.stderr ?? "";
|
|
1416
1178
|
const stdout = err.output?.stdout ?? "";
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1179
|
+
await emitEnd(false, /* @__PURE__ */ new Error(`Hook execute failed: ${commandWithArgs}`), {
|
|
1180
|
+
stdout,
|
|
1181
|
+
stderr
|
|
1182
|
+
});
|
|
1420
1183
|
}
|
|
1421
1184
|
}
|
|
1422
1185
|
/**
|
|
@@ -1467,7 +1230,7 @@ function waitForHookEnd(hooks, hookId, onSuccess, fallbackErrorMessage) {
|
|
|
1467
1230
|
hooks.on("kubb:hook:end", handler);
|
|
1468
1231
|
});
|
|
1469
1232
|
}
|
|
1470
|
-
async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel, hooks,
|
|
1233
|
+
async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefix, noToolMessage, configName, outputPath, logLevel, hooks, onStart, onEnd }) {
|
|
1471
1234
|
await onStart();
|
|
1472
1235
|
let resolvedTool = toolValue;
|
|
1473
1236
|
if (resolvedTool === "auto") {
|
|
@@ -1481,7 +1244,7 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
|
|
|
1481
1244
|
let toolError;
|
|
1482
1245
|
if (resolvedTool && resolvedTool !== "auto" && resolvedTool in toolMap && (0, node_fs.existsSync)(outputPath)) {
|
|
1483
1246
|
const toolConfig = toolMap[resolvedTool];
|
|
1484
|
-
const hookId = (0, node_crypto.
|
|
1247
|
+
const hookId = (0, node_crypto.hash)("sha256", [configName, resolvedTool].filter(Boolean).join("-"), "hex");
|
|
1485
1248
|
const successMessage = [
|
|
1486
1249
|
`${successPrefix} with ${(0, node_util.styleText)("dim", resolvedTool)}`,
|
|
1487
1250
|
logLevel >= _kubb_core.logLevel.info ? `on ${(0, node_util.styleText)("dim", outputPath)}` : void 0,
|
|
@@ -1496,19 +1259,12 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
|
|
|
1496
1259
|
command: toolConfig.command,
|
|
1497
1260
|
args: hookArgs
|
|
1498
1261
|
});
|
|
1499
|
-
const { stream = false, onLine, onStdout, onStderr } = makeSink?.(commandWithArgs, hookId) ?? {};
|
|
1500
1262
|
runHook({
|
|
1501
1263
|
id: hookId,
|
|
1502
1264
|
command: toolConfig.command,
|
|
1503
1265
|
args: hookArgs,
|
|
1504
1266
|
commandWithArgs,
|
|
1505
|
-
hooks
|
|
1506
|
-
stream,
|
|
1507
|
-
sink: {
|
|
1508
|
-
onLine,
|
|
1509
|
-
onStdout,
|
|
1510
|
-
onStderr
|
|
1511
|
-
}
|
|
1267
|
+
hooks
|
|
1512
1268
|
}).catch(() => {});
|
|
1513
1269
|
await hookEndPromise;
|
|
1514
1270
|
} catch (caughtError) {
|
|
@@ -1519,7 +1275,7 @@ async function runToolPass({ toolValue, detect, toolMap, toolLabel, successPrefi
|
|
|
1519
1275
|
if (toolError) throw toolError;
|
|
1520
1276
|
}
|
|
1521
1277
|
async function generate(options) {
|
|
1522
|
-
const { input, hooks, logLevel
|
|
1278
|
+
const { input, hooks, logLevel } = options;
|
|
1523
1279
|
const hrStart = node_process.default.hrtime();
|
|
1524
1280
|
const inputPath = input ?? (options.config.input && "path" in options.config.input ? options.config.input.path : void 0);
|
|
1525
1281
|
const config = {
|
|
@@ -1602,8 +1358,7 @@ async function generate(options) {
|
|
|
1602
1358
|
configName: config.name,
|
|
1603
1359
|
outputPath,
|
|
1604
1360
|
logLevel,
|
|
1605
|
-
hooks
|
|
1606
|
-
makeSink
|
|
1361
|
+
hooks
|
|
1607
1362
|
});
|
|
1608
1363
|
} catch (caughtError) {
|
|
1609
1364
|
const diagnostic = outputDiagnostic(code, pass.toolLabel, caughtError);
|
|
@@ -1620,8 +1375,7 @@ async function generate(options) {
|
|
|
1620
1375
|
try {
|
|
1621
1376
|
await executeHooks({
|
|
1622
1377
|
configHooks: config.hooks,
|
|
1623
|
-
hooks
|
|
1624
|
-
makeSink
|
|
1378
|
+
hooks
|
|
1625
1379
|
});
|
|
1626
1380
|
} finally {
|
|
1627
1381
|
hooks.off("kubb:hook:end", onHookEnd);
|
|
@@ -1703,7 +1457,7 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
1703
1457
|
node_process.default.exit(1);
|
|
1704
1458
|
}
|
|
1705
1459
|
const requestedNames = cliReporters?.length ? cliReporters : ["cli"];
|
|
1706
|
-
|
|
1460
|
+
await setupReporters(hooks, {
|
|
1707
1461
|
logLevel,
|
|
1708
1462
|
reporters: (0, _kubb_core.selectReporters)(configs[0]?.reporters ?? [], requestedNames)
|
|
1709
1463
|
});
|
|
@@ -1727,8 +1481,7 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
1727
1481
|
input,
|
|
1728
1482
|
config,
|
|
1729
1483
|
logLevel,
|
|
1730
|
-
hooks
|
|
1731
|
-
makeSink
|
|
1484
|
+
hooks
|
|
1732
1485
|
});
|
|
1733
1486
|
_clack_prompts.log.step((0, node_util.styleText)("yellow", `Watching for changes in ${paths.join(" and ")}`));
|
|
1734
1487
|
}, {
|
|
@@ -1740,8 +1493,7 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
1740
1493
|
input,
|
|
1741
1494
|
config,
|
|
1742
1495
|
logLevel,
|
|
1743
|
-
hooks
|
|
1744
|
-
makeSink
|
|
1496
|
+
hooks
|
|
1745
1497
|
})) anyFailed = true;
|
|
1746
1498
|
} catch (configError) {
|
|
1747
1499
|
await hooks.emit("kubb:error", { error: require_errors.toError(configError) });
|
|
@@ -1757,4 +1509,4 @@ async function run({ input, configPath, logLevel: logLevelKey, watch, reporters:
|
|
|
1757
1509
|
//#endregion
|
|
1758
1510
|
exports.run = run;
|
|
1759
1511
|
|
|
1760
|
-
//# sourceMappingURL=run-
|
|
1512
|
+
//# sourceMappingURL=run-D4WAzrjB.cjs.map
|