@kubb/cli 5.0.0-beta.75 → 5.0.0-beta.9
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 +177 -26
- package/dist/agent-C5F4itrc.js +68 -0
- package/dist/agent-C5F4itrc.js.map +1 -0
- package/dist/agent-d-lmeOr1.cjs +70 -0
- package/dist/agent-d-lmeOr1.cjs.map +1 -0
- package/dist/{chunk--u3MIqq1.js → chunk-BvFE5Tac.js} +1 -0
- package/dist/constants-B2JTeRBb.js +42 -0
- package/dist/constants-B2JTeRBb.js.map +1 -0
- package/dist/constants-BINTA5VZ.cjs +77 -0
- package/dist/constants-BINTA5VZ.cjs.map +1 -0
- package/dist/constants-BYGmiFs0.cjs +139 -0
- package/dist/constants-BYGmiFs0.cjs.map +1 -0
- package/dist/constants-DSJ-Xrbv.js +116 -0
- package/dist/constants-DSJ-Xrbv.js.map +1 -0
- package/dist/define-Bdn8j5VM.cjs.map +1 -1
- package/dist/{define-Ctii4bel.js → define-m_fp-Aqm.js} +2 -2
- package/dist/{define-Ctii4bel.js.map → define-m_fp-Aqm.js.map} +1 -1
- package/dist/{errors-CjPmyZHy.js → errors-CINO1EIv.js} +2 -2
- package/dist/{errors-CjPmyZHy.js.map → errors-CINO1EIv.js.map} +1 -1
- package/dist/errors-CLCjoSg0.cjs.map +1 -1
- package/dist/{generate-YPtfjsg4.js → generate-BhfRufgh.js} +12 -6
- package/dist/generate-BhfRufgh.js.map +1 -0
- package/dist/{generate-DDCwNQNo.cjs → generate-BvuSxNYj.cjs} +10 -4
- package/dist/generate-BvuSxNYj.cjs.map +1 -0
- package/dist/index.cjs +20 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -13
- package/dist/index.js.map +1 -1
- package/dist/init-DOSXtcyb.js +53 -0
- package/dist/init-DOSXtcyb.js.map +1 -0
- package/dist/init-bKtEOvhK.cjs +53 -0
- package/dist/init-bKtEOvhK.cjs.map +1 -0
- package/dist/mcp-CKkbG0kp.cjs +39 -0
- package/dist/mcp-CKkbG0kp.cjs.map +1 -0
- package/dist/mcp-DzOfqX_j.js +39 -0
- package/dist/mcp-DzOfqX_j.js.map +1 -0
- package/dist/package-BgAYWN7y.js +6 -0
- package/dist/package-BgAYWN7y.js.map +1 -0
- package/dist/{package-D5arPDnh.cjs → package-DHGhrRW-.cjs} +2 -2
- package/dist/package-DHGhrRW-.cjs.map +1 -0
- package/dist/{generate-K8MJ9aQF.cjs → run-BObDb2qe.cjs} +319 -334
- package/dist/run-BObDb2qe.cjs.map +1 -0
- package/dist/{agent-Ev5hU5hH.js → run-BzpYYOQs.js} +53 -44
- package/dist/run-BzpYYOQs.js.map +1 -0
- package/dist/run-CCZ24VKk.js +51 -0
- package/dist/run-CCZ24VKk.js.map +1 -0
- package/dist/{init-eNRlotJK.js → run-CF97BWVa.js} +102 -147
- package/dist/run-CF97BWVa.js.map +1 -0
- package/dist/run-CQbj3ley.cjs +52 -0
- package/dist/run-CQbj3ley.cjs.map +1 -0
- package/dist/run-D0hmRpHy.js +49 -0
- package/dist/run-D0hmRpHy.js.map +1 -0
- package/dist/{agent-B_pirbeB.cjs → run-DwdAwnLG.cjs} +51 -42
- package/dist/run-DwdAwnLG.cjs.map +1 -0
- package/dist/run-Lr0Ctnu0.cjs +50 -0
- package/dist/run-Lr0Ctnu0.cjs.map +1 -0
- package/dist/{generate-Cg8yufrw.js → run-P6D8TnXf.js} +322 -337
- package/dist/run-P6D8TnXf.js.map +1 -0
- package/dist/{init-CZ5Xq2Hd.cjs → run-YsoCk5we.cjs} +100 -145
- package/dist/run-YsoCk5we.cjs.map +1 -0
- package/dist/shell-475fQKaX.cjs.map +1 -1
- package/dist/{shell-DLzN4fRo.js → shell-CN6DNqeC.js} +2 -2
- package/dist/{shell-DLzN4fRo.js.map → shell-CN6DNqeC.js.map} +1 -1
- package/dist/{telemetry-DN95_2pF.cjs → telemetry-B2iWkY5e.cjs} +5 -7
- package/dist/telemetry-B2iWkY5e.cjs.map +1 -0
- package/dist/{telemetry-LgT_sdPe.js → telemetry-BkektVz6.js} +6 -8
- package/dist/telemetry-BkektVz6.js.map +1 -0
- package/dist/validate-Bj8vbvPt.cjs +26 -0
- package/dist/validate-Bj8vbvPt.cjs.map +1 -0
- package/dist/validate-bHUrnYBv.js +26 -0
- package/dist/validate-bHUrnYBv.js.map +1 -0
- package/package.json +22 -14
- package/src/commands/agent/start.ts +10 -7
- package/src/commands/agent.ts +3 -1
- package/src/commands/generate.ts +5 -3
- package/src/commands/init.ts +34 -3
- package/src/commands/mcp.ts +28 -4
- package/src/commands/validate.ts +6 -4
- package/src/constants.ts +2 -58
- package/src/index.ts +5 -3
- package/src/loggers/clackLogger.ts +45 -43
- package/src/loggers/fileSystemLogger.ts +26 -13
- package/src/loggers/githubActionsLogger.ts +13 -25
- package/src/loggers/plainLogger.ts +12 -23
- package/src/loggers/types.ts +6 -0
- package/src/loggers/utils.ts +155 -9
- package/src/runners/agent/run.ts +113 -0
- package/src/runners/agent/utils.ts +98 -0
- package/src/runners/generate/run.ts +276 -0
- package/src/runners/generate/utils.ts +209 -0
- package/src/runners/init/run.ts +211 -0
- package/src/{utils/packageManager.ts → runners/init/utils.ts} +10 -0
- package/src/runners/mcp/run.ts +55 -0
- package/src/runners/validate/run.ts +63 -0
- package/src/{utils/telemetry.ts → telemetry.ts} +12 -5
- package/dist/agent-BEgI2HXH.cjs +0 -58
- package/dist/agent-BEgI2HXH.cjs.map +0 -1
- package/dist/agent-B_pirbeB.cjs.map +0 -1
- package/dist/agent-CTdJEHEs.js +0 -56
- package/dist/agent-CTdJEHEs.js.map +0 -1
- package/dist/agent-Ev5hU5hH.js.map +0 -1
- package/dist/constants-CnDXa1R6.cjs +0 -148
- package/dist/constants-CnDXa1R6.cjs.map +0 -1
- package/dist/constants-aL3CP_Wq.js +0 -95
- package/dist/constants-aL3CP_Wq.js.map +0 -1
- package/dist/generate-Cg8yufrw.js.map +0 -1
- package/dist/generate-DDCwNQNo.cjs.map +0 -1
- package/dist/generate-K8MJ9aQF.cjs.map +0 -1
- package/dist/generate-YPtfjsg4.js.map +0 -1
- package/dist/init-Bu95ML_u.cjs +0 -25
- package/dist/init-Bu95ML_u.cjs.map +0 -1
- package/dist/init-CZ5Xq2Hd.cjs.map +0 -1
- package/dist/init-eNRlotJK.js.map +0 -1
- package/dist/init-ooJeOBGt.js +0 -25
- package/dist/init-ooJeOBGt.js.map +0 -1
- package/dist/mcp-C-d5N1wZ.js +0 -16
- package/dist/mcp-C-d5N1wZ.js.map +0 -1
- package/dist/mcp-CLcDV4Jm.cjs +0 -41
- package/dist/mcp-CLcDV4Jm.cjs.map +0 -1
- package/dist/mcp-D7EIR9fR.js +0 -40
- package/dist/mcp-D7EIR9fR.js.map +0 -1
- package/dist/mcp-Dpu8vzzj.cjs +0 -16
- package/dist/mcp-Dpu8vzzj.cjs.map +0 -1
- package/dist/package-D5arPDnh.cjs.map +0 -1
- package/dist/package-DqZsMLZ9.js +0 -6
- package/dist/package-DqZsMLZ9.js.map +0 -1
- package/dist/telemetry-DN95_2pF.cjs.map +0 -1
- package/dist/telemetry-LgT_sdPe.js.map +0 -1
- package/dist/validate-CIR3_lZI.js +0 -25
- package/dist/validate-CIR3_lZI.js.map +0 -1
- package/dist/validate-DcqUb4DM.cjs +0 -25
- package/dist/validate-DcqUb4DM.cjs.map +0 -1
- package/dist/validate-kLJoT_hi.js +0 -33
- package/dist/validate-kLJoT_hi.js.map +0 -1
- package/dist/validate-yKKzqEZ5.cjs +0 -34
- package/dist/validate-yKKzqEZ5.cjs.map +0 -1
- package/src/runners/agent.ts +0 -149
- package/src/runners/generate.ts +0 -333
- package/src/runners/init.ts +0 -296
- package/src/runners/mcp.ts +0 -45
- package/src/runners/validate.ts +0 -39
- package/src/types.ts +0 -11
- package/src/utils/Writables.ts +0 -17
- package/src/utils/executeHooks.ts +0 -45
- package/src/utils/flags.ts +0 -9
- package/src/utils/getConfig.ts +0 -10
- package/src/utils/getCosmiConfig.ts +0 -80
- package/src/utils/getSummary.ts +0 -68
- package/src/utils/runHook.ts +0 -91
- package/src/utils/watcher.ts +0 -19
package/src/runners/validate.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
|
-
import { getErrorMessage } from '@internals/utils'
|
|
3
|
-
import { parseDocument, validateDocument } from '@kubb/adapter-oas'
|
|
4
|
-
import { buildTelemetryEvent, sendTelemetry } from '../utils/telemetry.ts'
|
|
5
|
-
|
|
6
|
-
type ValidateOptions = {
|
|
7
|
-
input: string
|
|
8
|
-
version: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function runValidate({ input, version }: ValidateOptions): Promise<void> {
|
|
12
|
-
const hrStart = process.hrtime()
|
|
13
|
-
try {
|
|
14
|
-
const document = await parseDocument(input)
|
|
15
|
-
await validateDocument(document, { throwOnError: true })
|
|
16
|
-
|
|
17
|
-
await sendTelemetry(
|
|
18
|
-
buildTelemetryEvent({
|
|
19
|
-
command: 'validate',
|
|
20
|
-
kubbVersion: version,
|
|
21
|
-
hrStart,
|
|
22
|
-
status: 'success',
|
|
23
|
-
}),
|
|
24
|
-
)
|
|
25
|
-
console.log('✅ Validation success')
|
|
26
|
-
} catch (error) {
|
|
27
|
-
await sendTelemetry(
|
|
28
|
-
buildTelemetryEvent({
|
|
29
|
-
command: 'validate',
|
|
30
|
-
kubbVersion: version,
|
|
31
|
-
hrStart,
|
|
32
|
-
status: 'failed',
|
|
33
|
-
}),
|
|
34
|
-
)
|
|
35
|
-
console.error('❌ Validation failed')
|
|
36
|
-
console.error(getErrorMessage(error))
|
|
37
|
-
process.exit(1)
|
|
38
|
-
}
|
|
39
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type QuiteFlag = '--help' | '-h' | '--version' | '-v'
|
|
2
|
-
|
|
3
|
-
export type GenerateFlag = '--config' | '-c' | '--log-level' | '-l' | '--watch' | '-w' | '--debug' | '-d' | '--verbose' | '-v' | '--silent' | '-s'
|
|
4
|
-
|
|
5
|
-
export type ValidateFlag = '--input' | '-i'
|
|
6
|
-
|
|
7
|
-
export type InitFlag = '--yes' | '-y'
|
|
8
|
-
|
|
9
|
-
export type AgentStartFlag = '--config' | '-c' | '--port' | '-p' | '--host' | '--allow-write' | '--allow-all'
|
|
10
|
-
|
|
11
|
-
export type Arg = QuiteFlag | GenerateFlag | ValidateFlag | InitFlag | AgentStartFlag
|
package/src/utils/Writables.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { WritableOptions } from 'node:stream'
|
|
2
|
-
import { Writable } from 'node:stream'
|
|
3
|
-
import { styleText } from 'node:util'
|
|
4
|
-
import type * as clack from '@clack/prompts'
|
|
5
|
-
|
|
6
|
-
export class ClackWritable extends Writable {
|
|
7
|
-
taskLog: ReturnType<typeof clack.taskLog>
|
|
8
|
-
constructor(taskLog: ReturnType<typeof clack.taskLog>, opts?: WritableOptions) {
|
|
9
|
-
super(opts)
|
|
10
|
-
|
|
11
|
-
this.taskLog = taskLog
|
|
12
|
-
}
|
|
13
|
-
_write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
|
14
|
-
this.taskLog.message(`${styleText('dim', chunk.toString())}`)
|
|
15
|
-
callback()
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto'
|
|
2
|
-
import { styleText } from 'node:util'
|
|
3
|
-
import type { AsyncEventEmitter } from '@internals/utils'
|
|
4
|
-
import { tokenize } from '@internals/utils'
|
|
5
|
-
import type { Config, KubbHookEndContext, KubbHooks } from '@kubb/core'
|
|
6
|
-
|
|
7
|
-
type ExecutingHooksProps = {
|
|
8
|
-
configHooks: NonNullable<Config['hooks']>
|
|
9
|
-
hooks: AsyncEventEmitter<KubbHooks>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function executeHooks({ configHooks, hooks }: ExecutingHooksProps): Promise<void> {
|
|
13
|
-
const commands = Array.isArray(configHooks.done) ? configHooks.done : [configHooks.done].filter(Boolean)
|
|
14
|
-
|
|
15
|
-
for (const command of commands) {
|
|
16
|
-
const [cmd, ...args] = tokenize(command)
|
|
17
|
-
|
|
18
|
-
if (!cmd) {
|
|
19
|
-
continue
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const hookId = createHash('sha256').update(command).digest('hex')
|
|
23
|
-
|
|
24
|
-
// Wire up the hook:end listener BEFORE emitting hook:start to avoid the race condition
|
|
25
|
-
// where hook:end fires synchronously inside emit('kubb:hook:start') before the listener is registered.
|
|
26
|
-
const hookEndPromise = new Promise<void>((resolve, reject) => {
|
|
27
|
-
const handler = (ctx: KubbHookEndContext) => {
|
|
28
|
-
if (ctx.id !== hookId) return
|
|
29
|
-
hooks.off('kubb:hook:end', handler)
|
|
30
|
-
if (!ctx.success) {
|
|
31
|
-
reject(ctx.error ?? new Error(`Hook failed: ${command}`))
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
hooks
|
|
35
|
-
.emit('kubb:success', { message: `${styleText('dim', command)} successfully executed` })
|
|
36
|
-
.then(resolve)
|
|
37
|
-
.catch(reject)
|
|
38
|
-
}
|
|
39
|
-
hooks.on('kubb:hook:end', handler)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
await hooks.emit('kubb:hook:start', { id: hookId, command: cmd, args })
|
|
43
|
-
await hookEndPromise
|
|
44
|
-
}
|
|
45
|
-
}
|
package/src/utils/flags.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard that confirms `value` is a member of `set`. Avoids type assertions with `Set<T extends string>`.
|
|
3
|
-
*/
|
|
4
|
-
export function isFlag<T extends string>(set: ReadonlySet<T>, value: string): value is T {
|
|
5
|
-
for (const flag of set) {
|
|
6
|
-
if (flag === value) return true
|
|
7
|
-
}
|
|
8
|
-
return false
|
|
9
|
-
}
|
package/src/utils/getConfig.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { CLIOptions, Config, PossibleConfig } from '@kubb/core'
|
|
2
|
-
|
|
3
|
-
type ConfigInput = PossibleConfig<CLIOptions>
|
|
4
|
-
|
|
5
|
-
export async function getConfigs(config: ConfigInput, args: CLIOptions): Promise<Array<Config>> {
|
|
6
|
-
const resolved = await (typeof config === 'function' ? config(args as CLIOptions) : config)
|
|
7
|
-
const userConfigs = Array.isArray(resolved) ? resolved : [resolved]
|
|
8
|
-
|
|
9
|
-
return userConfigs.map((item) => ({ ...item, plugins: item.plugins ?? [] }) as Config)
|
|
10
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { Config } from '@kubb/core'
|
|
2
|
-
import { cosmiconfig } from 'cosmiconfig'
|
|
3
|
-
import { unrun } from 'unrun'
|
|
4
|
-
|
|
5
|
-
type CosmiconfigResult = {
|
|
6
|
-
filepath: string
|
|
7
|
-
isEmpty?: boolean
|
|
8
|
-
config: Config
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const unrunInputOptions = {
|
|
12
|
-
transform: {
|
|
13
|
-
jsx: {
|
|
14
|
-
runtime: 'automatic' as const,
|
|
15
|
-
importSource: '@kubb/renderer-jsx',
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const tsLoader = async (configFile: string) => {
|
|
21
|
-
const { module } = await unrun({
|
|
22
|
-
path: configFile,
|
|
23
|
-
inputOptions: unrunInputOptions,
|
|
24
|
-
})
|
|
25
|
-
return module
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function getCosmiConfig(moduleName: string, config?: string): Promise<CosmiconfigResult> {
|
|
29
|
-
let result: CosmiconfigResult
|
|
30
|
-
const searchPlaces = [
|
|
31
|
-
'package.json',
|
|
32
|
-
`.${moduleName}rc`,
|
|
33
|
-
`.${moduleName}rc.json`,
|
|
34
|
-
`.${moduleName}rc.yaml`,
|
|
35
|
-
`.${moduleName}rc.yml`,
|
|
36
|
-
|
|
37
|
-
`.${moduleName}rc.ts`,
|
|
38
|
-
`.${moduleName}rc.mts`,
|
|
39
|
-
`.${moduleName}rc.cts`,
|
|
40
|
-
`.${moduleName}rc.js`,
|
|
41
|
-
`.${moduleName}rc.mjs`,
|
|
42
|
-
`.${moduleName}rc.cjs`,
|
|
43
|
-
|
|
44
|
-
`${moduleName}.config.ts`,
|
|
45
|
-
`${moduleName}.config.mts`,
|
|
46
|
-
`${moduleName}.config.cts`,
|
|
47
|
-
`${moduleName}.config.js`,
|
|
48
|
-
`${moduleName}.config.mjs`,
|
|
49
|
-
`${moduleName}.config.cjs`,
|
|
50
|
-
]
|
|
51
|
-
const explorer = cosmiconfig(moduleName, {
|
|
52
|
-
cache: false,
|
|
53
|
-
searchPlaces: [
|
|
54
|
-
...searchPlaces.map((searchPlace) => {
|
|
55
|
-
return `.config/${searchPlace}`
|
|
56
|
-
}),
|
|
57
|
-
...searchPlaces.map((searchPlace) => {
|
|
58
|
-
return `configs/${searchPlace}`
|
|
59
|
-
}),
|
|
60
|
-
...searchPlaces,
|
|
61
|
-
],
|
|
62
|
-
loaders: {
|
|
63
|
-
'.ts': tsLoader,
|
|
64
|
-
'.mts': tsLoader,
|
|
65
|
-
'.cts': tsLoader,
|
|
66
|
-
},
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
result = config ? ((await explorer.load(config)) as CosmiconfigResult) : ((await explorer.search()) as CosmiconfigResult)
|
|
71
|
-
} catch (error) {
|
|
72
|
-
throw new Error('Config failed loading', { cause: error })
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (result?.isEmpty || !result || !result.config) {
|
|
76
|
-
throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return result as CosmiconfigResult
|
|
80
|
-
}
|
package/src/utils/getSummary.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { styleText } from 'node:util'
|
|
3
|
-
import { formatHrtime, randomCliColor } from '@internals/utils'
|
|
4
|
-
import type { Config, Plugin } from '@kubb/core'
|
|
5
|
-
import { SUMMARY_MAX_BAR_LENGTH, SUMMARY_TIME_SCALE_DIVISOR } from '../constants.ts'
|
|
6
|
-
|
|
7
|
-
type SummaryProps = {
|
|
8
|
-
failedPlugins: Set<{ plugin: Plugin; error: Error }>
|
|
9
|
-
status: 'success' | 'failed'
|
|
10
|
-
hrStart: [number, number]
|
|
11
|
-
filesCreated: number
|
|
12
|
-
config: Config
|
|
13
|
-
pluginTimings?: Map<string, number>
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function getSummary({ failedPlugins, filesCreated, status, hrStart, config, pluginTimings }: SummaryProps): string[] {
|
|
17
|
-
const duration = formatHrtime(hrStart)
|
|
18
|
-
|
|
19
|
-
const pluginsCount = config.plugins?.length ?? 0
|
|
20
|
-
const successCount = pluginsCount - failedPlugins.size
|
|
21
|
-
|
|
22
|
-
const meta = {
|
|
23
|
-
plugins:
|
|
24
|
-
status === 'success'
|
|
25
|
-
? `${styleText('green', `${successCount} successful`)}, ${pluginsCount} total`
|
|
26
|
-
: `${styleText('green', `${successCount} successful`)}, ${styleText('red', `${failedPlugins.size} failed`)}, ${pluginsCount} total`,
|
|
27
|
-
pluginsFailed: status === 'failed' ? [...failedPlugins].map(({ plugin }) => randomCliColor(plugin.name)).join(', ') : undefined,
|
|
28
|
-
filesCreated,
|
|
29
|
-
time: styleText('green', duration),
|
|
30
|
-
output: path.resolve(config.root, config.output.path),
|
|
31
|
-
} as const
|
|
32
|
-
|
|
33
|
-
const labels = {
|
|
34
|
-
plugins: 'Plugins:',
|
|
35
|
-
failed: 'Failed:',
|
|
36
|
-
generated: 'Generated:',
|
|
37
|
-
pluginTimings: 'Plugin Timings:',
|
|
38
|
-
output: 'Output:',
|
|
39
|
-
}
|
|
40
|
-
const maxLength = Math.max(0, ...[...Object.values(labels), ...(pluginTimings ? Array.from(pluginTimings.keys()) : [])].map((s) => s.length))
|
|
41
|
-
|
|
42
|
-
const summaryLines: string[] = []
|
|
43
|
-
summaryLines.push(`${labels.plugins.padEnd(maxLength + 2)} ${meta.plugins}`)
|
|
44
|
-
|
|
45
|
-
if (meta.pluginsFailed) {
|
|
46
|
-
summaryLines.push(`${labels.failed.padEnd(maxLength + 2)} ${meta.pluginsFailed}`)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
summaryLines.push(`${labels.generated.padEnd(maxLength + 2)} ${meta.filesCreated} files in ${meta.time}`)
|
|
50
|
-
|
|
51
|
-
if (pluginTimings && pluginTimings.size > 0) {
|
|
52
|
-
const sortedTimings = Array.from(pluginTimings.entries()).sort((a, b) => b[1] - a[1])
|
|
53
|
-
|
|
54
|
-
summaryLines.push(`${labels.pluginTimings}`)
|
|
55
|
-
|
|
56
|
-
sortedTimings.forEach(([name, time]) => {
|
|
57
|
-
const timeStr = time >= 1000 ? `${(time / 1000).toFixed(2)}s` : `${Math.round(time)}ms`
|
|
58
|
-
const barLength = Math.min(Math.ceil(time / SUMMARY_TIME_SCALE_DIVISOR), SUMMARY_MAX_BAR_LENGTH)
|
|
59
|
-
const bar = styleText('dim', '█'.repeat(barLength))
|
|
60
|
-
|
|
61
|
-
summaryLines.push(`${styleText('dim', '•')} ${name.padEnd(maxLength + 1)}${bar} ${timeStr}`)
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
summaryLines.push(`${labels.output.padEnd(maxLength + 2)} ${meta.output}`)
|
|
66
|
-
|
|
67
|
-
return summaryLines
|
|
68
|
-
}
|
package/src/utils/runHook.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { AsyncEventEmitter } from '@internals/utils'
|
|
2
|
-
import { toError } from '@internals/utils'
|
|
3
|
-
import type { KubbHooks } from '@kubb/core'
|
|
4
|
-
import { NonZeroExitError, x } from 'tinyexec'
|
|
5
|
-
|
|
6
|
-
type HookOutputSink = {
|
|
7
|
-
/** Called for each streamed stdout line while the hook runs (optional). */
|
|
8
|
-
onLine?: (line: string) => void
|
|
9
|
-
/** Called on stderr after failure (optional). */
|
|
10
|
-
onStderr?: (text: string) => void
|
|
11
|
-
/** Called on stdout after failure (optional). */
|
|
12
|
-
onStdout?: (text: string) => void
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type RunHookOptions = {
|
|
16
|
-
id: string
|
|
17
|
-
command: string
|
|
18
|
-
args?: readonly string[]
|
|
19
|
-
commandWithArgs: string
|
|
20
|
-
context: AsyncEventEmitter<KubbHooks>
|
|
21
|
-
/** When true the process output is streamed line-by-line via onLine. */
|
|
22
|
-
stream?: boolean
|
|
23
|
-
sink?: HookOutputSink
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Executes a hook command, emits debug and completion events, and forwards output to an optional sink.
|
|
28
|
-
*/
|
|
29
|
-
export async function runHook({ id, command, args, commandWithArgs, context, stream = false, sink }: RunHookOptions): Promise<void> {
|
|
30
|
-
try {
|
|
31
|
-
const proc = x(command, [...(args ?? [])], {
|
|
32
|
-
nodeOptions: { detached: process.platform !== 'win32' },
|
|
33
|
-
throwOnError: true,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
if (stream && sink?.onLine) {
|
|
37
|
-
for await (const line of proc) {
|
|
38
|
-
sink.onLine(line)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const result = await proc
|
|
43
|
-
|
|
44
|
-
await context.emit('kubb:debug', {
|
|
45
|
-
date: new Date(),
|
|
46
|
-
logs: [result.stdout.trimEnd()],
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
await context.emit('kubb:hook:end', {
|
|
50
|
-
command,
|
|
51
|
-
args,
|
|
52
|
-
id,
|
|
53
|
-
success: true,
|
|
54
|
-
error: null,
|
|
55
|
-
})
|
|
56
|
-
} catch (err) {
|
|
57
|
-
if (!(err instanceof NonZeroExitError)) {
|
|
58
|
-
await context.emit('kubb:hook:end', {
|
|
59
|
-
command,
|
|
60
|
-
args,
|
|
61
|
-
id,
|
|
62
|
-
success: false,
|
|
63
|
-
error: toError(err),
|
|
64
|
-
})
|
|
65
|
-
await context.emit('kubb:error', { error: toError(err) })
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const stderr = err.output?.stderr ?? ''
|
|
70
|
-
const stdout = err.output?.stdout ?? ''
|
|
71
|
-
|
|
72
|
-
await context.emit('kubb:debug', {
|
|
73
|
-
date: new Date(),
|
|
74
|
-
logs: [stdout, stderr].filter(Boolean),
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
if (stderr) sink?.onStderr?.(stderr)
|
|
78
|
-
if (stdout) sink?.onStdout?.(stdout)
|
|
79
|
-
|
|
80
|
-
const errorMessage = new Error(`Hook execute failed: ${commandWithArgs}`)
|
|
81
|
-
|
|
82
|
-
await context.emit('kubb:hook:end', {
|
|
83
|
-
command,
|
|
84
|
-
args,
|
|
85
|
-
id,
|
|
86
|
-
success: false,
|
|
87
|
-
error: errorMessage,
|
|
88
|
-
})
|
|
89
|
-
await context.emit('kubb:error', { error: errorMessage })
|
|
90
|
-
}
|
|
91
|
-
}
|
package/src/utils/watcher.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { styleText } from 'node:util'
|
|
2
|
-
import { WATCHER_IGNORED_PATHS } from '../constants.ts'
|
|
3
|
-
|
|
4
|
-
export async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {
|
|
5
|
-
const { watch } = await import('chokidar')
|
|
6
|
-
const watcher = watch(path, {
|
|
7
|
-
ignorePermissionErrors: true,
|
|
8
|
-
ignored: WATCHER_IGNORED_PATHS,
|
|
9
|
-
})
|
|
10
|
-
watcher.on('all', async (type, file) => {
|
|
11
|
-
console.log(styleText('yellow', styleText('bold', `Change detected: ${type} ${file}`)))
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
await cb(path)
|
|
15
|
-
} catch (_e) {
|
|
16
|
-
console.log(styleText('red', 'Watcher failed'))
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
}
|