@kubb/cli 4.33.0 → 4.33.2
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/dist/{agent-D0A3RQho.js → agent-BGWY8Iow.js} +5 -5
- package/dist/agent-BGWY8Iow.js.map +1 -0
- package/dist/{agent-CduUX7Ye.cjs → agent-Bd1QdPVV.cjs} +7 -7
- package/dist/agent-Bd1QdPVV.cjs.map +1 -0
- package/dist/{agent-DrnwQBZf.cjs → agent-CmQJU9h7.cjs} +7 -7
- package/dist/agent-CmQJU9h7.cjs.map +1 -0
- package/dist/{agent-CJ69TqoO.js → agent-u_Ehwz6r.js} +5 -5
- package/dist/agent-u_Ehwz6r.js.map +1 -0
- package/dist/{constants-CnPOlsJq.cjs → constants-BTUap0zs.cjs} +1 -19
- package/dist/{constants-CnPOlsJq.cjs.map → constants-BTUap0zs.cjs.map} +1 -1
- package/dist/{constants-CEKRremI.js → constants-CM3dJzjK.js} +2 -14
- package/dist/{constants-CEKRremI.js.map → constants-CM3dJzjK.js.map} +1 -1
- package/dist/{types-CLtz0jem.js → define--M_JMcDC.js} +6 -6
- package/dist/define--M_JMcDC.js.map +1 -0
- package/dist/{types-Ck2lzFON.cjs → define-D6Kfm7-Z.cjs} +6 -6
- package/dist/define-D6Kfm7-Z.cjs.map +1 -0
- package/dist/{errors-bSLTEh4e.js → errors-6mF_WKxg.js} +5 -5
- package/dist/errors-6mF_WKxg.js.map +1 -0
- package/dist/{errors-BUjJsNoe.cjs → errors-DBW0N9w4.cjs} +5 -5
- package/dist/errors-DBW0N9w4.cjs.map +1 -0
- package/dist/{generate-ByMgAV76.cjs → generate-6Cm1AK2n.cjs} +275 -153
- package/dist/generate-6Cm1AK2n.cjs.map +1 -0
- package/dist/{generate-HP5ySfjV.js → generate-DcNp9Owd.js} +271 -149
- package/dist/generate-DcNp9Owd.js.map +1 -0
- package/dist/{generate-CiUPO5ds.cjs → generate-DqmjK5Lc.cjs} +3 -3
- package/dist/generate-DqmjK5Lc.cjs.map +1 -0
- package/dist/{generate-DIIxtkWT.js → generate-rtsmgWhO.js} +3 -3
- package/dist/generate-rtsmgWhO.js.map +1 -0
- package/dist/index.cjs +13 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/{init-DLNrkDF4.js → init--9nMhvx6.js} +4 -4
- package/dist/init--9nMhvx6.js.map +1 -0
- package/dist/{init-Df_aXezV.cjs → init-BvjtU-sC.cjs} +5 -4
- package/dist/init-BvjtU-sC.cjs.map +1 -0
- package/dist/{init-DyKK2fTp.js → init-C-InrmSY.js} +42 -31
- package/dist/init-C-InrmSY.js.map +1 -0
- package/dist/{init-Cd1hCb7q.cjs → init-hmolV6B4.cjs} +47 -37
- package/dist/init-hmolV6B4.cjs.map +1 -0
- package/dist/{jiti-BdskUHhD.cjs → jiti-Cd3S0xwr.cjs} +1 -1
- package/dist/{jiti-BdskUHhD.cjs.map → jiti-Cd3S0xwr.cjs.map} +1 -1
- package/dist/{jiti-Cl7t20dO.js → jiti-e08mD2Ph.js} +1 -1
- package/dist/{jiti-Cl7t20dO.js.map → jiti-e08mD2Ph.js.map} +1 -1
- package/dist/{mcp-Clg-Qnkr.cjs → mcp-Bd-DXHWV.cjs} +5 -4
- package/dist/mcp-Bd-DXHWV.cjs.map +1 -0
- package/dist/{mcp-Bd9LITaI.js → mcp-CZzxfbHW.js} +4 -4
- package/dist/mcp-CZzxfbHW.js.map +1 -0
- package/dist/{mcp-B73FC8dF.cjs → mcp-ChHFPRzD.cjs} +4 -4
- package/dist/mcp-ChHFPRzD.cjs.map +1 -0
- package/dist/{mcp-Cf-1dsB-.js → mcp-D2SHEg_d.js} +4 -4
- package/dist/mcp-D2SHEg_d.js.map +1 -0
- package/dist/{package-aKgzEJtp.cjs → package-BXijqaX5.cjs} +2 -2
- package/dist/package-BXijqaX5.cjs.map +1 -0
- package/dist/package-DeOlqJ31.js +6 -0
- package/dist/package-DeOlqJ31.js.map +1 -0
- package/dist/shell-7HPrTCJ5.cjs +57 -0
- package/dist/shell-7HPrTCJ5.cjs.map +1 -0
- package/dist/shell-DqqWsHCD.js +46 -0
- package/dist/shell-DqqWsHCD.js.map +1 -0
- package/dist/{telemetry-T5IA2dWA.cjs → telemetry-Cn9X1I5B.cjs} +46 -9
- package/dist/telemetry-Cn9X1I5B.cjs.map +1 -0
- package/dist/{telemetry-C4gOKX2x.js → telemetry-DxiR7clS.js} +40 -9
- package/dist/telemetry-DxiR7clS.js.map +1 -0
- package/dist/{validate-Cr26q5xX.js → validate-BH2Ysgxr.js} +4 -4
- package/dist/validate-BH2Ysgxr.js.map +1 -0
- package/dist/{validate-DURmg-2Q.cjs → validate-BQvsoQz-.cjs} +5 -4
- package/dist/validate-BQvsoQz-.cjs.map +1 -0
- package/dist/{validate-Dqi9T_c4.cjs → validate-Bbrn3Q-A.cjs} +4 -4
- package/dist/validate-Bbrn3Q-A.cjs.map +1 -0
- package/dist/{validate-Chjg23AE.js → validate-l8vLmwKA.js} +4 -4
- package/dist/validate-l8vLmwKA.js.map +1 -0
- package/package.json +6 -5
- package/src/commands/agent/start.ts +1 -1
- package/src/commands/agent.ts +1 -1
- package/src/commands/generate.ts +1 -1
- package/src/commands/init.ts +1 -1
- package/src/commands/mcp.ts +1 -1
- package/src/commands/validate.ts +1 -1
- package/src/constants.ts +0 -1
- package/src/index.ts +1 -1
- package/src/loggers/clackLogger.ts +26 -28
- package/src/loggers/fileSystemLogger.ts +1 -2
- package/src/loggers/githubActionsLogger.ts +26 -28
- package/src/loggers/plainLogger.ts +25 -26
- package/src/loggers/utils.ts +4 -5
- package/src/runners/agent.ts +1 -1
- package/src/runners/generate.ts +20 -7
- package/src/runners/init.ts +2 -1
- package/src/runners/mcp.ts +1 -1
- package/src/runners/validate.ts +1 -1
- package/src/utils/executeHooks.ts +2 -2
- package/src/utils/getIntro.ts +1 -80
- package/src/utils/getSummary.ts +1 -2
- package/src/utils/packageManager.ts +2 -2
- package/src/utils/runHook.ts +2 -2
- package/src/utils/telemetry.ts +1 -2
- package/dist/agent-CJ69TqoO.js.map +0 -1
- package/dist/agent-CduUX7Ye.cjs.map +0 -1
- package/dist/agent-D0A3RQho.js.map +0 -1
- package/dist/agent-DrnwQBZf.cjs.map +0 -1
- package/dist/errors-BUjJsNoe.cjs.map +0 -1
- package/dist/errors-bSLTEh4e.js.map +0 -1
- package/dist/generate-ByMgAV76.cjs.map +0 -1
- package/dist/generate-CiUPO5ds.cjs.map +0 -1
- package/dist/generate-DIIxtkWT.js.map +0 -1
- package/dist/generate-HP5ySfjV.js.map +0 -1
- package/dist/init-Cd1hCb7q.cjs.map +0 -1
- package/dist/init-DLNrkDF4.js.map +0 -1
- package/dist/init-Df_aXezV.cjs.map +0 -1
- package/dist/init-DyKK2fTp.js.map +0 -1
- package/dist/mcp-B73FC8dF.cjs.map +0 -1
- package/dist/mcp-Bd9LITaI.js.map +0 -1
- package/dist/mcp-Cf-1dsB-.js.map +0 -1
- package/dist/mcp-Clg-Qnkr.cjs.map +0 -1
- package/dist/package-681jTtCk.js +0 -6
- package/dist/package-681jTtCk.js.map +0 -1
- package/dist/package-aKgzEJtp.cjs.map +0 -1
- package/dist/telemetry-C4gOKX2x.js.map +0 -1
- package/dist/telemetry-T5IA2dWA.cjs.map +0 -1
- package/dist/types-CLtz0jem.js.map +0 -1
- package/dist/types-Ck2lzFON.cjs.map +0 -1
- package/dist/validate-Chjg23AE.js.map +0 -1
- package/dist/validate-Cr26q5xX.js.map +0 -1
- package/dist/validate-DURmg-2Q.cjs.map +0 -1
- package/dist/validate-Dqi9T_c4.cjs.map +0 -1
- package/src/cli/adapters/nodeAdapter.ts +0 -159
- package/src/cli/help.ts +0 -36
- package/src/cli/index.ts +0 -16
- package/src/cli/parse.ts +0 -18
- package/src/cli/schema.ts +0 -38
- package/src/cli/types.ts +0 -95
- package/src/utils/envDetection.ts +0 -34
- package/src/utils/errors.ts +0 -23
- package/src/utils/formatMsWithColor.ts +0 -22
- package/src/utils/randomColor.ts +0 -14
- package/src/utils/spawnAsync.ts +0 -47
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { parseArgs, styleText } from 'node:util'
|
|
2
|
-
import { renderHelp } from '../help.ts'
|
|
3
|
-
import type { CommandDefinition, OptionType, ParsedArgs, RunOptions } from '../types.ts'
|
|
4
|
-
import { defineCLIAdapter } from '../types.ts'
|
|
5
|
-
|
|
6
|
-
type ParseOption = { type: OptionType; short?: string; default?: string | boolean }
|
|
7
|
-
type ParseOptions = Record<string, ParseOption>
|
|
8
|
-
|
|
9
|
-
function buildParseOptions(def: CommandDefinition): ParseOptions {
|
|
10
|
-
const result: ParseOptions = {
|
|
11
|
-
help: { type: 'boolean', short: 'h' },
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
for (const [name, opt] of Object.entries(def.options ?? {})) {
|
|
15
|
-
result[name] = {
|
|
16
|
-
type: opt.type,
|
|
17
|
-
...(opt.short ? { short: opt.short } : {}),
|
|
18
|
-
...(opt.default !== undefined ? { default: opt.default } : {}),
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return result
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function runCommand(def: CommandDefinition, argv: string[], parentName?: string): Promise<void> {
|
|
26
|
-
const parseOptions = buildParseOptions(def)
|
|
27
|
-
|
|
28
|
-
let parsed: ParsedArgs
|
|
29
|
-
try {
|
|
30
|
-
const result = parseArgs({
|
|
31
|
-
args: argv,
|
|
32
|
-
options: parseOptions,
|
|
33
|
-
allowPositionals: true,
|
|
34
|
-
strict: false,
|
|
35
|
-
})
|
|
36
|
-
parsed = { values: result.values as ParsedArgs['values'], positionals: result.positionals }
|
|
37
|
-
} catch {
|
|
38
|
-
renderHelp(def, parentName)
|
|
39
|
-
process.exit(1)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (parsed.values['help']) {
|
|
43
|
-
renderHelp(def, parentName)
|
|
44
|
-
process.exit(0)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Validate required options before running the command
|
|
48
|
-
for (const [name, opt] of Object.entries(def.options ?? {})) {
|
|
49
|
-
if (opt.required && parsed.values[name] === undefined) {
|
|
50
|
-
console.error(styleText('red', `Error: --${name} is required`))
|
|
51
|
-
renderHelp(def, parentName)
|
|
52
|
-
process.exit(1)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (!def.run) {
|
|
57
|
-
renderHelp(def, parentName)
|
|
58
|
-
process.exit(0)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
await def.run(parsed)
|
|
63
|
-
} catch (err) {
|
|
64
|
-
console.error(styleText('red', `Error: ${err instanceof Error ? err.message : String(err)}`))
|
|
65
|
-
renderHelp(def, parentName)
|
|
66
|
-
process.exit(1)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function printRootHelp(programName: string, version: string, defs: CommandDefinition[]): void {
|
|
71
|
-
console.log(`\n${styleText('bold', 'Usage:')} ${programName} <command> [options]\n`)
|
|
72
|
-
console.log(` Kubb generation — v${version}\n`)
|
|
73
|
-
console.log(styleText('bold', 'Commands:'))
|
|
74
|
-
for (const def of defs) {
|
|
75
|
-
console.log(` ${styleText('cyan', def.name.padEnd(16))}${def.description}`)
|
|
76
|
-
}
|
|
77
|
-
console.log()
|
|
78
|
-
console.log(styleText('bold', 'Options:'))
|
|
79
|
-
console.log(` ${styleText('cyan', '-v, --version'.padEnd(30))}Show version number`)
|
|
80
|
-
console.log(` ${styleText('cyan', '-h, --help'.padEnd(30))}Show help`)
|
|
81
|
-
console.log()
|
|
82
|
-
console.log(`Run ${styleText('cyan', `${programName} <command> --help`)} for command-specific help.\n`)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** CLI adapter using `node:util parseArgs`. No external dependencies. */
|
|
86
|
-
export const nodeAdapter = defineCLIAdapter({
|
|
87
|
-
renderHelp(def: CommandDefinition, parentName?: string): void {
|
|
88
|
-
renderHelp(def, parentName)
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
async run(defs: CommandDefinition[], argv: string[], opts: RunOptions): Promise<void> {
|
|
92
|
-
const { programName, defaultCommandName, version } = opts
|
|
93
|
-
|
|
94
|
-
const args = argv.length >= 2 && argv[0]?.includes('node') ? argv.slice(2) : argv
|
|
95
|
-
|
|
96
|
-
if (args[0] === '--version' || args[0] === '-v') {
|
|
97
|
-
console.log(version)
|
|
98
|
-
process.exit(0)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (args[0] === '--help' || args[0] === '-h') {
|
|
102
|
-
printRootHelp(programName, version, defs)
|
|
103
|
-
process.exit(0)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (args.length === 0) {
|
|
107
|
-
const defaultDef = defs.find((d) => d.name === defaultCommandName)
|
|
108
|
-
if (defaultDef?.run) {
|
|
109
|
-
await runCommand(defaultDef, [], programName)
|
|
110
|
-
} else {
|
|
111
|
-
printRootHelp(programName, version, defs)
|
|
112
|
-
}
|
|
113
|
-
return
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const [first, ...rest] = args
|
|
117
|
-
const isKnownSubcommand = defs.some((d) => d.name === first)
|
|
118
|
-
|
|
119
|
-
let def: CommandDefinition | undefined
|
|
120
|
-
let commandArgv: string[]
|
|
121
|
-
let parentName: string | undefined
|
|
122
|
-
|
|
123
|
-
if (isKnownSubcommand) {
|
|
124
|
-
def = defs.find((d) => d.name === first)
|
|
125
|
-
commandArgv = rest
|
|
126
|
-
parentName = programName
|
|
127
|
-
} else {
|
|
128
|
-
def = defs.find((d) => d.name === defaultCommandName)
|
|
129
|
-
commandArgv = args
|
|
130
|
-
parentName = programName
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (!def) {
|
|
134
|
-
console.error(`Unknown command: ${first}`)
|
|
135
|
-
printRootHelp(programName, version, defs)
|
|
136
|
-
process.exit(1)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (def.subCommands?.length) {
|
|
140
|
-
const [subName, ...subRest] = commandArgv
|
|
141
|
-
const subDef = def.subCommands.find((s) => s.name === subName)
|
|
142
|
-
|
|
143
|
-
if (subName === '--help' || subName === '-h') {
|
|
144
|
-
renderHelp(def, parentName)
|
|
145
|
-
process.exit(0)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (!subDef) {
|
|
149
|
-
renderHelp(def, parentName)
|
|
150
|
-
process.exit(subName ? 1 : 0)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
await runCommand(subDef, subRest, `${parentName} ${def.name}`)
|
|
154
|
-
return
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
await runCommand(def, commandArgv, parentName)
|
|
158
|
-
},
|
|
159
|
-
})
|
package/src/cli/help.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { styleText } from 'node:util'
|
|
2
|
-
import { getCommandSchema } from './schema.ts'
|
|
3
|
-
import type { CommandDefinition, OptionSchema } from './types.ts'
|
|
4
|
-
|
|
5
|
-
/** Prints formatted help output for a command using its `CommandDefinition`. */
|
|
6
|
-
export function renderHelp(def: CommandDefinition, parentName?: string): void {
|
|
7
|
-
const schema = getCommandSchema([def])[0]!
|
|
8
|
-
|
|
9
|
-
const programName = parentName ? `${parentName} ${schema.name}` : schema.name
|
|
10
|
-
|
|
11
|
-
const argsPart = schema.arguments?.length ? ` ${schema.arguments.join(' ')}` : ''
|
|
12
|
-
const subCmdPart = schema.subCommands.length ? ' <command>' : ''
|
|
13
|
-
console.log(`\n${styleText('bold', 'Usage:')} ${programName}${argsPart}${subCmdPart} [options]\n`)
|
|
14
|
-
|
|
15
|
-
if (schema.description) {
|
|
16
|
-
console.log(` ${schema.description}\n`)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (schema.subCommands.length) {
|
|
20
|
-
console.log(styleText('bold', 'Commands:'))
|
|
21
|
-
for (const sub of schema.subCommands) {
|
|
22
|
-
console.log(` ${styleText('cyan', sub.name.padEnd(16))}${sub.description}`)
|
|
23
|
-
}
|
|
24
|
-
console.log()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const options: OptionSchema[] = [...schema.options, { name: 'help', flags: '-h, --help', type: 'boolean' as const, description: 'Show help' }]
|
|
28
|
-
|
|
29
|
-
console.log(styleText('bold', 'Options:'))
|
|
30
|
-
for (const opt of options) {
|
|
31
|
-
const flags = styleText('cyan', opt.flags.padEnd(30))
|
|
32
|
-
const defaultPart = opt.default !== undefined ? styleText('dim', ` (default: ${opt.default})`) : ''
|
|
33
|
-
console.log(` ${flags}${opt.description}${defaultPart}`)
|
|
34
|
-
}
|
|
35
|
-
console.log()
|
|
36
|
-
}
|
package/src/cli/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { nodeAdapter } from './adapters/nodeAdapter.ts'
|
|
2
|
-
export { createCLI } from './parse.ts'
|
|
3
|
-
export { getCommandSchema } from './schema.ts'
|
|
4
|
-
export type {
|
|
5
|
-
BooleanOption,
|
|
6
|
-
CLIAdapter,
|
|
7
|
-
CommandDefinition,
|
|
8
|
-
CommandSchema,
|
|
9
|
-
OptionDefinition,
|
|
10
|
-
OptionSchema,
|
|
11
|
-
OptionType,
|
|
12
|
-
ParsedArgs,
|
|
13
|
-
RunOptions,
|
|
14
|
-
StringOption,
|
|
15
|
-
} from './types.ts'
|
|
16
|
-
export { defineCLIAdapter, defineCommand } from './types.ts'
|
package/src/cli/parse.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { nodeAdapter } from './adapters/nodeAdapter.ts'
|
|
2
|
-
import type { CLIAdapter, CommandDefinition, RunOptions } from './types.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Create a CLI runner bound to a specific adapter.
|
|
6
|
-
* Defaults to the built-in `nodeAdapter` (Node.js `node:util parseArgs`).
|
|
7
|
-
*/
|
|
8
|
-
export function createCLI(options?: { adapter?: CLIAdapter }): {
|
|
9
|
-
run(commands: CommandDefinition[], argv: string[], opts: RunOptions): Promise<void>
|
|
10
|
-
} {
|
|
11
|
-
const adapter = options?.adapter ?? nodeAdapter
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
run(commands, argv, opts) {
|
|
15
|
-
return adapter.run(commands, argv, opts)
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
}
|
package/src/cli/schema.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { CommandDefinition, CommandSchema, OptionDefinition, OptionSchema } from './types.ts'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Serializes `CommandDefinition[]` to a plain, JSON-serializable structure.
|
|
5
|
-
* Use to expose CLI capabilities to AI agents or MCP tools.
|
|
6
|
-
*/
|
|
7
|
-
export function getCommandSchema(defs: CommandDefinition[]): CommandSchema[] {
|
|
8
|
-
return defs.map(serializeCommand)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function serializeCommand(def: CommandDefinition): CommandSchema {
|
|
12
|
-
return {
|
|
13
|
-
name: def.name,
|
|
14
|
-
description: def.description,
|
|
15
|
-
arguments: def.arguments,
|
|
16
|
-
options: serializeOptions(def.options ?? {}),
|
|
17
|
-
subCommands: def.subCommands ? def.subCommands.map(serializeCommand) : [],
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function serializeOptions(options: Record<string, OptionDefinition>): OptionSchema[] {
|
|
22
|
-
return Object.entries(options).map(([name, opt]) => {
|
|
23
|
-
const shortPart = opt.short ? `-${opt.short}, ` : ''
|
|
24
|
-
const valuePart = opt.type === 'string' ? ` <${opt.hint ?? name}>` : ''
|
|
25
|
-
const flags = `${shortPart}--${name}${valuePart}`
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
name,
|
|
29
|
-
flags,
|
|
30
|
-
type: opt.type,
|
|
31
|
-
description: opt.description,
|
|
32
|
-
...(opt.default !== undefined ? { default: opt.default } : {}),
|
|
33
|
-
...(opt.hint ? { hint: opt.hint } : {}),
|
|
34
|
-
...(opt.enum ? { enum: opt.enum } : {}),
|
|
35
|
-
...(opt.required ? { required: opt.required } : {}),
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
}
|
package/src/cli/types.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
type BaseOption = {
|
|
2
|
-
/** Single-character short alias, e.g. `'c'` for `--config`. */
|
|
3
|
-
short?: string
|
|
4
|
-
description: string
|
|
5
|
-
hint?: string
|
|
6
|
-
required?: boolean
|
|
7
|
-
/** Allowed values for string options. Used in help output and AI/MCP tool schemas. */
|
|
8
|
-
enum?: string[]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type StringOption = BaseOption & { type: 'string'; default?: string }
|
|
12
|
-
export type BooleanOption = BaseOption & { type: 'boolean'; default?: boolean }
|
|
13
|
-
export type OptionDefinition = StringOption | BooleanOption
|
|
14
|
-
export type OptionType = OptionDefinition['type']
|
|
15
|
-
|
|
16
|
-
type OptionTypeMap = { string: string; boolean: boolean }
|
|
17
|
-
|
|
18
|
-
type IsRequired<O extends OptionDefinition> = O['default'] extends string | boolean ? true : O['required'] extends true ? true : false
|
|
19
|
-
|
|
20
|
-
/** Infers typed values from an options record. Options with a `default` or `required: true` are always defined. */
|
|
21
|
-
type InferValues<O extends Record<string, OptionDefinition>> = {
|
|
22
|
-
[K in keyof O as IsRequired<O[K]> extends true ? K : never]: OptionTypeMap[O[K]['type']]
|
|
23
|
-
} & {
|
|
24
|
-
[K in keyof O as IsRequired<O[K]> extends true ? never : K]?: OptionTypeMap[O[K]['type']]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type ParsedArgs = {
|
|
28
|
-
values: Record<string, string | boolean | undefined>
|
|
29
|
-
positionals: string[]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type CommandDefinition = {
|
|
33
|
-
name: string
|
|
34
|
-
description: string
|
|
35
|
-
/** Positional argument labels shown in usage line, e.g. `['[input]']`. */
|
|
36
|
-
arguments?: string[]
|
|
37
|
-
options?: Record<string, OptionDefinition>
|
|
38
|
-
subCommands?: CommandDefinition[]
|
|
39
|
-
run?: (args: ParsedArgs) => Promise<void>
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Returns a `CommandDefinition` with typed `values` in `run()`.
|
|
44
|
-
* The callback receives `values` typed from the declared options — no casts needed.
|
|
45
|
-
*/
|
|
46
|
-
export function defineCommand<O extends Record<string, OptionDefinition>>(def: {
|
|
47
|
-
name: string
|
|
48
|
-
description: string
|
|
49
|
-
arguments?: string[]
|
|
50
|
-
options?: O
|
|
51
|
-
subCommands?: CommandDefinition[]
|
|
52
|
-
run?: (args: { values: InferValues<O>; positionals: string[] }) => Promise<void>
|
|
53
|
-
}): CommandDefinition {
|
|
54
|
-
const { run, ...rest } = def
|
|
55
|
-
if (!run) return rest
|
|
56
|
-
return {
|
|
57
|
-
...rest,
|
|
58
|
-
run: (args) => run({ values: args.values as InferValues<O>, positionals: args.positionals }),
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type RunOptions = {
|
|
63
|
-
programName: string
|
|
64
|
-
defaultCommandName: string
|
|
65
|
-
version: string
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export type CLIAdapter = {
|
|
69
|
-
run(commands: CommandDefinition[], argv: string[], opts: RunOptions): Promise<void>
|
|
70
|
-
renderHelp(def: CommandDefinition, parentName?: string): void
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Returns a `CLIAdapter` with type inference. Pass a different adapter to `createCLI` to swap the CLI engine. */
|
|
74
|
-
export function defineCLIAdapter(adapter: CLIAdapter): CLIAdapter {
|
|
75
|
-
return adapter
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export type OptionSchema = {
|
|
79
|
-
name: string
|
|
80
|
-
flags: string
|
|
81
|
-
type: OptionType
|
|
82
|
-
description: string
|
|
83
|
-
default?: string | boolean
|
|
84
|
-
hint?: string
|
|
85
|
-
required?: boolean
|
|
86
|
-
enum?: string[]
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export type CommandSchema = {
|
|
90
|
-
name: string
|
|
91
|
-
description: string
|
|
92
|
-
arguments?: string[]
|
|
93
|
-
options: OptionSchema[]
|
|
94
|
-
subCommands: CommandSchema[]
|
|
95
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if running in GitHub Actions environment
|
|
3
|
-
*/
|
|
4
|
-
export function isGitHubActions(): boolean {
|
|
5
|
-
return !!process.env.GITHUB_ACTIONS
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Check if running in any CI environment.
|
|
10
|
-
* Covers all major CI systems via their well-known environment variables.
|
|
11
|
-
*/
|
|
12
|
-
export function isCIEnvironment(): boolean {
|
|
13
|
-
return !!(
|
|
14
|
-
(
|
|
15
|
-
process.env.CI || // Generic (GitHub Actions, GitLab CI, CircleCI, Travis CI, etc.)
|
|
16
|
-
process.env.GITHUB_ACTIONS || // GitHub Actions
|
|
17
|
-
process.env.GITLAB_CI || // GitLab CI
|
|
18
|
-
process.env.BITBUCKET_BUILD_NUMBER || // Bitbucket Pipelines
|
|
19
|
-
process.env.JENKINS_URL || // Jenkins
|
|
20
|
-
process.env.CIRCLECI || // CircleCI
|
|
21
|
-
process.env.TRAVIS || // Travis CI
|
|
22
|
-
process.env.TEAMCITY_VERSION || // TeamCity
|
|
23
|
-
process.env.BUILDKITE || // Buildkite
|
|
24
|
-
process.env.TF_BUILD
|
|
25
|
-
) // Azure Pipelines
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Check if TTY is available for interactive output
|
|
31
|
-
*/
|
|
32
|
-
export function canUseTTY(): boolean {
|
|
33
|
-
return !!process.stdout.isTTY && !isCIEnvironment()
|
|
34
|
-
}
|
package/src/utils/errors.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coerce an unknown thrown value to an `Error` instance.
|
|
3
|
-
* When the value is already an `Error` it is returned as-is;
|
|
4
|
-
* otherwise a new `Error` is created whose message is `String(value)`.
|
|
5
|
-
*/
|
|
6
|
-
export function toError(value: unknown): Error {
|
|
7
|
-
return value instanceof Error ? value : new Error(String(value))
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Safely extract a human-readable message from any thrown value.
|
|
12
|
-
*/
|
|
13
|
-
export function getErrorMessage(value: unknown): string {
|
|
14
|
-
return value instanceof Error ? value.message : String(value)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Extract the `.cause` property of an `Error` as an `Error | undefined`.
|
|
19
|
-
* Returns `undefined` when the cause is absent or is not an `Error`.
|
|
20
|
-
*/
|
|
21
|
-
export function toCause(error: Error): Error | undefined {
|
|
22
|
-
return error.cause instanceof Error ? error.cause : undefined
|
|
23
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { styleText } from 'node:util'
|
|
2
|
-
import { formatMs } from '@kubb/core/utils'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Formats milliseconds with color based on duration thresholds:
|
|
6
|
-
* - Green: <= 500ms
|
|
7
|
-
* - Yellow: > 500ms and <= 1000ms
|
|
8
|
-
* - Red: > 1000ms
|
|
9
|
-
*/
|
|
10
|
-
export function formatMsWithColor(ms: number): string {
|
|
11
|
-
const formatted = formatMs(ms)
|
|
12
|
-
|
|
13
|
-
if (ms <= 500) {
|
|
14
|
-
return styleText('green', formatted)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
if (ms <= 1000) {
|
|
18
|
-
return styleText('yellow', formatted)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return styleText('red', formatted)
|
|
22
|
-
}
|
package/src/utils/randomColor.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto'
|
|
2
|
-
import { styleText } from 'node:util'
|
|
3
|
-
import { randomColors } from '../constants.ts'
|
|
4
|
-
|
|
5
|
-
export function randomCliColor(text?: string): string {
|
|
6
|
-
if (!text) {
|
|
7
|
-
return ''
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const index = createHash('sha256').update(text).digest().readUInt32BE(0) % randomColors.length
|
|
11
|
-
const color = randomColors[index] ?? 'white'
|
|
12
|
-
|
|
13
|
-
return styleText(color, text)
|
|
14
|
-
}
|
package/src/utils/spawnAsync.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process'
|
|
2
|
-
|
|
3
|
-
type SpawnOptions = {
|
|
4
|
-
cwd?: string
|
|
5
|
-
env?: NodeJS.ProcessEnv
|
|
6
|
-
/**
|
|
7
|
-
* When `true`, spawns a detached background process and resolves immediately.
|
|
8
|
-
* The child is unref'd so the parent process can exit independently.
|
|
9
|
-
* Defaults to `false` (foreground — inherits stdio and waits for exit).
|
|
10
|
-
*/
|
|
11
|
-
detached?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Spawns `cmd args` and returns a promise.
|
|
16
|
-
* - Foreground (default): inherits stdio and resolves when the process exits successfully.
|
|
17
|
-
* - Detached: spawns in its own process group, un-refs the child, and resolves immediately.
|
|
18
|
-
*/
|
|
19
|
-
export function spawnAsync(cmd: string, args: string[], options: SpawnOptions = {}): Promise<void> {
|
|
20
|
-
const { cwd = process.cwd(), env, detached = false } = options
|
|
21
|
-
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
const child = spawn(cmd, args, {
|
|
24
|
-
stdio: detached ? 'ignore' : 'inherit',
|
|
25
|
-
cwd,
|
|
26
|
-
env,
|
|
27
|
-
detached,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
if (detached) {
|
|
31
|
-
child.unref()
|
|
32
|
-
resolve()
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
child.on('close', (code, signal) => {
|
|
37
|
-
if (code === 0) {
|
|
38
|
-
resolve()
|
|
39
|
-
} else if (signal !== null) {
|
|
40
|
-
reject(new Error(`"${cmd} ${args.join(' ')}" was terminated by signal ${signal}`))
|
|
41
|
-
} else {
|
|
42
|
-
reject(new Error(`"${cmd} ${args.join(' ')}" exited with code ${code}`))
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
child.on('error', reject)
|
|
46
|
-
})
|
|
47
|
-
}
|