@kubb/cli 4.11.1 → 4.11.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/{generate-mP1U-zi4.js → generate-CYBFB3tU.js} +11 -4
- package/dist/generate-CYBFB3tU.js.map +1 -0
- package/dist/{generate-BGADYMY6.js → generate-CpBJ2Y-n.js} +109 -57
- package/dist/generate-CpBJ2Y-n.js.map +1 -0
- package/dist/{generate-LbioowO-.cjs → generate-DpHvARzf.cjs} +109 -57
- package/dist/generate-DpHvARzf.cjs.map +1 -0
- package/dist/{generate-CVRHD5GD.cjs → generate-KUqCSnZp.cjs} +11 -4
- package/dist/generate-KUqCSnZp.cjs.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/commands/generate.ts +12 -2
- package/src/runners/generate.ts +88 -49
- package/src/utils/getSummary.ts +52 -8
- package/dist/generate-BGADYMY6.js.map +0 -1
- package/dist/generate-CVRHD5GD.cjs.map +0 -1
- package/dist/generate-LbioowO-.cjs.map +0 -1
- package/dist/generate-mP1U-zi4.js.map +0 -1
- package/src/utils/getErrorCauses.ts +0 -14
package/src/runners/generate.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { execa } from 'execa'
|
|
|
7
7
|
import pc from 'picocolors'
|
|
8
8
|
import type { Args } from '../commands/generate.ts'
|
|
9
9
|
import { executeHooks } from '../utils/executeHooks.ts'
|
|
10
|
-
import { getErrorCauses } from '../utils/getErrorCauses.ts'
|
|
11
10
|
import { getSummary } from '../utils/getSummary.ts'
|
|
12
11
|
|
|
13
12
|
type GenerateProps = {
|
|
@@ -88,20 +87,20 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
88
87
|
|
|
89
88
|
logger.emit('start', `Building ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)
|
|
90
89
|
|
|
91
|
-
const { files, failedPlugins, error } = await safeBuild(
|
|
90
|
+
const { files, failedPlugins, pluginTimings, error } = await safeBuild(
|
|
92
91
|
{
|
|
93
92
|
config: definedConfig,
|
|
94
93
|
logger,
|
|
95
94
|
},
|
|
96
|
-
{ pluginManager, fabric },
|
|
95
|
+
{ pluginManager, fabric, logger },
|
|
97
96
|
)
|
|
98
97
|
|
|
99
|
-
if (logger.logLevel
|
|
98
|
+
if (logger.logLevel >= LogMapper.debug) {
|
|
100
99
|
logger.consola?.start('Writing logs')
|
|
101
100
|
|
|
102
|
-
|
|
101
|
+
await logger.writeLogs()
|
|
103
102
|
|
|
104
|
-
logger.consola?.success(
|
|
103
|
+
logger.consola?.success('Written logs')
|
|
105
104
|
}
|
|
106
105
|
|
|
107
106
|
const summary = getSummary({
|
|
@@ -110,44 +109,34 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
110
109
|
config: definedConfig,
|
|
111
110
|
status: failedPlugins.size > 0 || error ? 'failed' : 'success',
|
|
112
111
|
hrStart,
|
|
112
|
+
pluginTimings: logger.logLevel >= LogMapper.verbose ? pluginTimings : undefined,
|
|
113
113
|
})
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
// Handle build failures (either from failed plugins or general errors)
|
|
116
|
+
const hasFailures = failedPlugins.size > 0 || error
|
|
117
|
+
|
|
118
|
+
if (hasFailures && logger.consola) {
|
|
116
119
|
logger.consola?.resumeLogs()
|
|
117
|
-
logger.consola
|
|
120
|
+
logger.consola?.log(`✗ Build failed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)
|
|
121
|
+
|
|
122
|
+
// Collect all errors from failed plugins and general error
|
|
123
|
+
const allErrors: Error[] = [
|
|
124
|
+
error,
|
|
125
|
+
...Array.from(failedPlugins)
|
|
126
|
+
.filter((it) => it.error)
|
|
127
|
+
.map((it) => it.error),
|
|
128
|
+
].filter(Boolean)
|
|
129
|
+
|
|
130
|
+
allErrors.forEach((err) => {
|
|
131
|
+
// Display error causes in debug mode
|
|
132
|
+
if (logger.logLevel >= LogMapper.debug && err.cause) {
|
|
133
|
+
logger.consola?.error(err.cause)
|
|
134
|
+
}
|
|
118
135
|
|
|
119
|
-
|
|
120
|
-
title: `${config.name || ''}`,
|
|
121
|
-
message: summary.join(''),
|
|
122
|
-
style: {
|
|
123
|
-
padding: 2,
|
|
124
|
-
borderColor: 'red',
|
|
125
|
-
borderStyle: 'rounded',
|
|
126
|
-
},
|
|
136
|
+
logger.consola?.error(err)
|
|
127
137
|
})
|
|
128
138
|
|
|
129
|
-
|
|
130
|
-
if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) {
|
|
131
|
-
errors.forEach((err) => {
|
|
132
|
-
logger.consola?.error(err)
|
|
133
|
-
})
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
;[...failedPlugins]
|
|
137
|
-
.filter((it) => it.error)
|
|
138
|
-
.forEach((it) => {
|
|
139
|
-
logger.consola?.error(it.error)
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
process.exit(1)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// TODO check if we can remove error
|
|
146
|
-
if (error && logger.consola) {
|
|
147
|
-
logger.consola?.resumeLogs()
|
|
148
|
-
logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)
|
|
149
|
-
|
|
150
|
-
logger.consola.box({
|
|
139
|
+
logger.consola?.box({
|
|
151
140
|
title: `${config.name || ''}`,
|
|
152
141
|
message: summary.join(''),
|
|
153
142
|
style: {
|
|
@@ -157,27 +146,30 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
157
146
|
},
|
|
158
147
|
})
|
|
159
148
|
|
|
160
|
-
const errors = getErrorCauses([error])
|
|
161
|
-
if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) {
|
|
162
|
-
errors.forEach((err) => {
|
|
163
|
-
logger.consola?.error(err)
|
|
164
|
-
})
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
logger.consola?.error(error)
|
|
168
|
-
|
|
169
149
|
process.exit(1)
|
|
170
150
|
}
|
|
171
151
|
|
|
172
152
|
// formatting
|
|
173
153
|
if (config.output.format === 'prettier') {
|
|
174
154
|
logger?.emit('start', `Formatting with ${config.output.format}`)
|
|
155
|
+
logger?.emit('debug', {
|
|
156
|
+
date: new Date(),
|
|
157
|
+
logs: [`Running prettier on ${path.resolve(definedConfig.root, definedConfig.output.path)}`],
|
|
158
|
+
})
|
|
175
159
|
|
|
176
160
|
try {
|
|
177
161
|
await execa('prettier', ['--ignore-unknown', '--write', path.resolve(definedConfig.root, definedConfig.output.path)])
|
|
162
|
+
logger?.emit('debug', {
|
|
163
|
+
date: new Date(),
|
|
164
|
+
logs: ['Prettier formatting completed successfully'],
|
|
165
|
+
})
|
|
178
166
|
} catch (e) {
|
|
179
167
|
logger.consola?.warn('Prettier not found')
|
|
180
168
|
logger.consola?.error(e)
|
|
169
|
+
logger?.emit('debug', {
|
|
170
|
+
date: new Date(),
|
|
171
|
+
logs: [`Prettier formatting failed: ${(e as Error).message}`],
|
|
172
|
+
})
|
|
181
173
|
}
|
|
182
174
|
|
|
183
175
|
logger?.emit('success', `Formatted with ${config.output.format}`)
|
|
@@ -185,12 +177,24 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
185
177
|
|
|
186
178
|
if (config.output.format === 'biome') {
|
|
187
179
|
logger?.emit('start', `Formatting with ${config.output.format}`)
|
|
180
|
+
logger?.emit('debug', {
|
|
181
|
+
date: new Date(),
|
|
182
|
+
logs: [`Running biome format on ${path.resolve(definedConfig.root, definedConfig.output.path)}`],
|
|
183
|
+
})
|
|
188
184
|
|
|
189
185
|
try {
|
|
190
186
|
await execa('biome', ['format', '--write', path.resolve(definedConfig.root, definedConfig.output.path)])
|
|
187
|
+
logger?.emit('debug', {
|
|
188
|
+
date: new Date(),
|
|
189
|
+
logs: ['Biome formatting completed successfully'],
|
|
190
|
+
})
|
|
191
191
|
} catch (e) {
|
|
192
192
|
logger.consola?.warn('Biome not found')
|
|
193
193
|
logger.consola?.error(e)
|
|
194
|
+
logger?.emit('debug', {
|
|
195
|
+
date: new Date(),
|
|
196
|
+
logs: [`Biome formatting failed: ${(e as Error).message}`],
|
|
197
|
+
})
|
|
194
198
|
}
|
|
195
199
|
|
|
196
200
|
logger?.emit('success', `Formatted with ${config.output.format}`)
|
|
@@ -199,12 +203,24 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
199
203
|
// linting
|
|
200
204
|
if (config.output.lint === 'eslint') {
|
|
201
205
|
logger?.emit('start', `Linting with ${config.output.lint}`)
|
|
206
|
+
logger?.emit('debug', {
|
|
207
|
+
date: new Date(),
|
|
208
|
+
logs: [`Running eslint on ${path.resolve(definedConfig.root, definedConfig.output.path)}`],
|
|
209
|
+
})
|
|
202
210
|
|
|
203
211
|
try {
|
|
204
212
|
await execa('eslint', [path.resolve(definedConfig.root, definedConfig.output.path), '--fix'])
|
|
213
|
+
logger?.emit('debug', {
|
|
214
|
+
date: new Date(),
|
|
215
|
+
logs: ['ESLint linting completed successfully'],
|
|
216
|
+
})
|
|
205
217
|
} catch (e) {
|
|
206
218
|
logger.consola?.warn('Eslint not found')
|
|
207
219
|
logger.consola?.error(e)
|
|
220
|
+
logger?.emit('debug', {
|
|
221
|
+
date: new Date(),
|
|
222
|
+
logs: [`ESLint linting failed: ${(e as Error).message}`],
|
|
223
|
+
})
|
|
208
224
|
}
|
|
209
225
|
|
|
210
226
|
logger?.emit('success', `Linted with ${config.output.lint}`)
|
|
@@ -212,12 +228,24 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
212
228
|
|
|
213
229
|
if (config.output.lint === 'biome') {
|
|
214
230
|
logger?.emit('start', `Linting with ${config.output.lint}`)
|
|
231
|
+
logger?.emit('debug', {
|
|
232
|
+
date: new Date(),
|
|
233
|
+
logs: [`Running biome lint on ${path.resolve(definedConfig.root, definedConfig.output.path)}`],
|
|
234
|
+
})
|
|
215
235
|
|
|
216
236
|
try {
|
|
217
237
|
await execa('biome', ['lint', '--fix', path.resolve(definedConfig.root, definedConfig.output.path)])
|
|
238
|
+
logger?.emit('debug', {
|
|
239
|
+
date: new Date(),
|
|
240
|
+
logs: ['Biome linting completed successfully'],
|
|
241
|
+
})
|
|
218
242
|
} catch (e) {
|
|
219
243
|
logger.consola?.warn('Biome not found')
|
|
220
244
|
logger.consola?.error(e)
|
|
245
|
+
logger?.emit('debug', {
|
|
246
|
+
date: new Date(),
|
|
247
|
+
logs: [`✗ Biome linting failed: ${(e as Error).message}`],
|
|
248
|
+
})
|
|
221
249
|
}
|
|
222
250
|
|
|
223
251
|
logger?.emit('success', `Linted with ${config.output.lint}`)
|
|
@@ -225,12 +253,24 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
225
253
|
|
|
226
254
|
if (config.output.lint === 'oxlint') {
|
|
227
255
|
logger?.emit('start', `Linting with ${config.output.lint}`)
|
|
256
|
+
logger?.emit('debug', {
|
|
257
|
+
date: new Date(),
|
|
258
|
+
logs: [`Running oxlint on ${path.resolve(definedConfig.root, definedConfig.output.path)}`],
|
|
259
|
+
})
|
|
228
260
|
|
|
229
261
|
try {
|
|
230
262
|
await execa('oxlint', ['--fix', path.resolve(definedConfig.root, definedConfig.output.path)])
|
|
263
|
+
logger?.emit('debug', {
|
|
264
|
+
date: new Date(),
|
|
265
|
+
logs: ['Oxlint linting completed successfully'],
|
|
266
|
+
})
|
|
231
267
|
} catch (e) {
|
|
232
268
|
logger.consola?.warn('Oxlint not found')
|
|
233
269
|
logger.consola?.error(e)
|
|
270
|
+
logger?.emit('debug', {
|
|
271
|
+
date: new Date(),
|
|
272
|
+
logs: [`✗ Oxlint linting failed: ${(e as Error).message}`],
|
|
273
|
+
})
|
|
234
274
|
}
|
|
235
275
|
|
|
236
276
|
logger?.emit('success', `Linted with ${config.output.lint}`)
|
|
@@ -240,8 +280,7 @@ export async function generate({ input, config, progressCache, args }: GenerateP
|
|
|
240
280
|
await executeHooks({ hooks: config.hooks, logger })
|
|
241
281
|
}
|
|
242
282
|
|
|
243
|
-
logger.consola?.log(`⚡Build completed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)
|
|
244
|
-
|
|
283
|
+
logger.consola?.log(`⚡ Build completed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)
|
|
245
284
|
logger.consola?.box({
|
|
246
285
|
title: `${config.name || ''}`,
|
|
247
286
|
message: summary.join(''),
|
package/src/utils/getSummary.ts
CHANGED
|
@@ -10,9 +10,10 @@ type SummaryProps = {
|
|
|
10
10
|
hrStart: [number, number]
|
|
11
11
|
filesCreated: number
|
|
12
12
|
config: Config
|
|
13
|
+
pluginTimings?: Map<string, number>
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export function getSummary({ failedPlugins, filesCreated, status, hrStart, config }: SummaryProps): string[] {
|
|
16
|
+
export function getSummary({ failedPlugins, filesCreated, status, hrStart, config, pluginTimings }: SummaryProps): string[] {
|
|
16
17
|
const logs = new Set<string>()
|
|
17
18
|
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrStart))
|
|
18
19
|
|
|
@@ -23,20 +24,63 @@ export function getSummary({ failedPlugins, filesCreated, status, hrStart, confi
|
|
|
23
24
|
plugins:
|
|
24
25
|
status === 'success'
|
|
25
26
|
? `${pc.green(`${successCount} successful`)}, ${pluginsCount} total`
|
|
26
|
-
: `${pc.red(`${failedPlugins.size
|
|
27
|
+
: `${pc.green(`${successCount} successful`)}, ${pc.red(`${failedPlugins.size} failed`)}, ${pluginsCount} total`,
|
|
27
28
|
pluginsFailed: status === 'failed' ? [...failedPlugins]?.map(({ plugin }) => randomCliColour(plugin.name))?.join(', ') : undefined,
|
|
28
29
|
filesCreated: filesCreated,
|
|
29
30
|
time: `${pc.yellow(`${elapsedSeconds}s`)}`,
|
|
30
31
|
output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root,
|
|
31
32
|
} as const
|
|
32
33
|
|
|
34
|
+
// Calculate label padding for perfect alignment
|
|
35
|
+
const labels = {
|
|
36
|
+
plugins: 'Plugins:',
|
|
37
|
+
failed: 'Failed:',
|
|
38
|
+
generated: 'Generated:',
|
|
39
|
+
output: 'Output:',
|
|
40
|
+
}
|
|
41
|
+
const maxLabelLength = Math.max(...Object.values(labels).map((l) => l.length))
|
|
42
|
+
|
|
43
|
+
const summaryLines: Array<[string, boolean]> = [
|
|
44
|
+
[`${pc.bold(labels.plugins.padEnd(maxLabelLength))} ${meta.plugins}`, true],
|
|
45
|
+
[`${pc.dim(labels.failed.padEnd(maxLabelLength))} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],
|
|
46
|
+
[`${pc.bold(labels.generated.padEnd(maxLabelLength))} ${meta.filesCreated} files in ${meta.time}`, true],
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
// Add plugin timing breakdown if available
|
|
50
|
+
if (pluginTimings && pluginTimings.size > 0) {
|
|
51
|
+
const MAX_TOP_PLUGINS = 5
|
|
52
|
+
const TIME_SCALE_DIVISOR = 100 // Each 100ms = 1 bar character
|
|
53
|
+
const MAX_BAR_LENGTH = 20
|
|
54
|
+
|
|
55
|
+
const sortedTimings = Array.from(pluginTimings.entries())
|
|
56
|
+
.sort((a, b) => b[1] - a[1])
|
|
57
|
+
.slice(0, MAX_TOP_PLUGINS)
|
|
58
|
+
|
|
59
|
+
if (sortedTimings.length > 0) {
|
|
60
|
+
summaryLines.push(['Plugin Timings:', true])
|
|
61
|
+
|
|
62
|
+
// Find the longest plugin name for alignment
|
|
63
|
+
const maxNameLength = Math.max(...sortedTimings.map(([name]) => name.length))
|
|
64
|
+
|
|
65
|
+
// Indent plugin timing bars to align with summary values (e.g., "7 successful", "60 files")
|
|
66
|
+
const indent = ' '.repeat(maxLabelLength + 1)
|
|
67
|
+
|
|
68
|
+
sortedTimings.forEach(([name, time]) => {
|
|
69
|
+
const timeStr = time >= 1000 ? `${(time / 1000).toFixed(2)}s` : `${Math.round(time)}ms`
|
|
70
|
+
const barLength = Math.min(Math.ceil(time / TIME_SCALE_DIVISOR), MAX_BAR_LENGTH)
|
|
71
|
+
const bar = '█'.repeat(barLength)
|
|
72
|
+
|
|
73
|
+
// Right-align plugin names, left-align bars, with consistent spacing
|
|
74
|
+
const paddedName = name.padStart(maxNameLength, ' ')
|
|
75
|
+
summaryLines.push([`${indent}${randomCliColour(paddedName)} ${pc.dim(bar)} ${pc.yellow(timeStr)}`, true])
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
summaryLines.push([`${pc.bold(labels.output.padEnd(maxLabelLength))} ${meta.output}`, true])
|
|
81
|
+
|
|
33
82
|
logs.add(
|
|
34
|
-
|
|
35
|
-
[`${pc.bold('Plugins:')} ${meta.plugins}`, true],
|
|
36
|
-
[`${pc.dim('Failed:')} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],
|
|
37
|
-
[`${pc.bold('Generated:')} ${meta.filesCreated} files in ${meta.time}`, true],
|
|
38
|
-
[`${pc.bold('Output:')} ${meta.output}`, true],
|
|
39
|
-
]
|
|
83
|
+
summaryLines
|
|
40
84
|
.map((item) => {
|
|
41
85
|
if (item.at(1)) {
|
|
42
86
|
return item.at(0)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-BGADYMY6.js","names":["process","definedConfig: Config"],"sources":["../src/utils/Writables.ts","../src/utils/executeHooks.ts","../src/utils/getErrorCauses.ts","../src/utils/parseHrtimeToSeconds.ts","../src/utils/getSummary.ts","../src/runners/generate.ts"],"sourcesContent":["import * as process from 'node:process'\nimport type { WritableOptions } from 'node:stream'\nimport { Writable } from 'node:stream'\nimport type { ConsolaInstance } from 'consola'\nimport pc from 'picocolors'\n\nexport class ConsolaWritable extends Writable {\n consola: ConsolaInstance | undefined\n command: string\n constructor(consola: ConsolaInstance | undefined, command: string, opts?: WritableOptions) {\n super(opts)\n\n this.command = command\n this.consola = consola\n }\n _write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n process.stdout.write(`${pc.dim(chunk?.toString())}`)\n\n callback()\n }\n}\n","import type { Config } from '@kubb/core'\nimport type { Logger } from '@kubb/core/logger'\nimport { LogMapper } from '@kubb/core/logger'\nimport { execa } from 'execa'\nimport pc from 'picocolors'\nimport { parseArgsStringToArgv } from 'string-argv'\nimport { ConsolaWritable } from './Writables.ts'\n\ntype ExecutingHooksProps = {\n hooks: NonNullable<Config['hooks']>\n logger: Logger\n}\n\nexport async function executeHooks({ hooks, logger }: ExecutingHooksProps): Promise<void> {\n const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean)\n\n for (const command of commands) {\n const consolaWritable = new ConsolaWritable(logger.consola!, command)\n const [cmd, ..._args] = [...parseArgsStringToArgv(command)]\n\n if (!cmd) {\n continue\n }\n\n logger?.emit('start', `Executing hook ${logger.logLevel !== LogMapper.silent ? pc.dim(command) : ''}`)\n\n await execa(cmd, _args, {\n detached: true,\n stdout: logger?.logLevel === LogMapper.silent ? undefined : ['pipe', consolaWritable],\n stripFinalNewline: true,\n })\n\n logger?.emit('success', `Executed hook ${logger.logLevel !== LogMapper.silent ? pc.dim(command) : ''}`)\n }\n\n logger?.emit('success', 'Executed hooks')\n}\n","export function getErrorCauses(errors: Error[]): Error[] {\n return errors\n .reduce((prev, error) => {\n const causedError = error?.cause as Error\n if (causedError) {\n prev = [...prev, ...getErrorCauses([causedError])]\n return prev\n }\n prev = [...prev, error]\n\n return prev\n }, [] as Error[])\n .filter(Boolean)\n}\n","export function parseHrtimeToSeconds(hrtime: [number, number]): string {\n const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3)\n return seconds\n}\n","import path from 'node:path'\nimport type { Config, Plugin } from '@kubb/core'\nimport { randomCliColour } from '@kubb/core/logger'\nimport pc from 'picocolors'\nimport { parseHrtimeToSeconds } from './parseHrtimeToSeconds.ts'\n\ntype SummaryProps = {\n failedPlugins: Set<{ plugin: Plugin; error: Error }>\n status: 'success' | 'failed'\n hrStart: [number, number]\n filesCreated: number\n config: Config\n}\n\nexport function getSummary({ failedPlugins, filesCreated, status, hrStart, config }: SummaryProps): string[] {\n const logs = new Set<string>()\n const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrStart))\n\n const pluginsCount = config.plugins?.length || 0\n const successCount = pluginsCount - failedPlugins.size\n\n const meta = {\n plugins:\n status === 'success'\n ? `${pc.green(`${successCount} successful`)}, ${pluginsCount} total`\n : `${pc.red(`${failedPlugins.size ?? 1} failed`)}, ${pluginsCount} total`,\n pluginsFailed: status === 'failed' ? [...failedPlugins]?.map(({ plugin }) => randomCliColour(plugin.name))?.join(', ') : undefined,\n filesCreated: filesCreated,\n time: `${pc.yellow(`${elapsedSeconds}s`)}`,\n output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root,\n } as const\n\n logs.add(\n [\n [`${pc.bold('Plugins:')} ${meta.plugins}`, true],\n [`${pc.dim('Failed:')} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],\n [`${pc.bold('Generated:')} ${meta.filesCreated} files in ${meta.time}`, true],\n [`${pc.bold('Output:')} ${meta.output}`, true],\n ]\n .map((item) => {\n if (item.at(1)) {\n return item.at(0)\n }\n return undefined\n })\n .filter(Boolean)\n .join('\\n'),\n )\n\n return [...logs]\n}\n","import path from 'node:path'\nimport process from 'node:process'\nimport { type Config, safeBuild, setup } from '@kubb/core'\nimport { createLogger, LogMapper } from '@kubb/core/logger'\nimport { Presets, SingleBar } from 'cli-progress'\nimport { execa } from 'execa'\nimport pc from 'picocolors'\nimport type { Args } from '../commands/generate.ts'\nimport { executeHooks } from '../utils/executeHooks.ts'\nimport { getErrorCauses } from '../utils/getErrorCauses.ts'\nimport { getSummary } from '../utils/getSummary.ts'\n\ntype GenerateProps = {\n input?: string\n config: Config\n args: Args\n progressCache: Map<string, SingleBar>\n}\n\nexport async function generate({ input, config, progressCache, args }: GenerateProps): Promise<void> {\n const hrStart = process.hrtime()\n const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3\n\n const logger = createLogger({\n logLevel,\n name: config.name,\n })\n\n const { root = process.cwd(), ...userConfig } = config\n const inputPath = input ?? ('path' in userConfig.input ? userConfig.input.path : undefined)\n\n if (logger.logLevel !== LogMapper.debug) {\n logger.on('progress_start', ({ id, size, message = '' }) => {\n logger.consola?.pauseLogs()\n const payload = { id, message }\n const progressBar = new SingleBar(\n {\n format: '{percentage}% {bar} {value}/{total} | {message}',\n barsize: 30,\n clearOnComplete: true,\n emptyOnZero: true,\n },\n Presets.shades_grey,\n )\n\n if (!progressCache.has(id)) {\n progressCache.set(id, progressBar)\n progressBar.start(size, 1, payload)\n }\n })\n\n logger.on('progress_stop', ({ id }) => {\n progressCache.get(id)?.stop()\n logger.consola?.resumeLogs()\n })\n\n logger.on('progressed', ({ id, message = '' }) => {\n const payload = { id, message }\n\n progressCache.get(id)?.increment(1, payload)\n })\n }\n\n const definedConfig: Config = {\n root,\n ...userConfig,\n input: inputPath\n ? {\n ...userConfig.input,\n path: inputPath,\n }\n : userConfig.input,\n output: {\n write: true,\n barrelType: 'named',\n extension: {\n '.ts': '.ts',\n },\n format: 'prettier',\n ...userConfig.output,\n },\n }\n\n const { fabric, pluginManager } = await setup({\n config: definedConfig,\n logger,\n })\n\n logger.emit('start', `Building ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n const { files, failedPlugins, error } = await safeBuild(\n {\n config: definedConfig,\n logger,\n },\n { pluginManager, fabric },\n )\n\n if (logger.logLevel === LogMapper.debug) {\n logger.consola?.start('Writing logs')\n\n const logFiles = await logger.writeLogs()\n\n logger.consola?.success(`Written logs: \\n${logFiles.join('\\n')}`)\n }\n\n const summary = getSummary({\n failedPlugins,\n filesCreated: files.length,\n config: definedConfig,\n status: failedPlugins.size > 0 || error ? 'failed' : 'success',\n hrStart,\n })\n\n if (failedPlugins.size && logger.consola) {\n logger.consola?.resumeLogs()\n logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n logger.consola.box({\n title: `${config.name || ''}`,\n message: summary.join(''),\n style: {\n padding: 2,\n borderColor: 'red',\n borderStyle: 'rounded',\n },\n })\n\n const errors = getErrorCauses([...failedPlugins].filter((it) => it.error).map((it) => it.error))\n if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) {\n errors.forEach((err) => {\n logger.consola?.error(err)\n })\n }\n\n ;[...failedPlugins]\n .filter((it) => it.error)\n .forEach((it) => {\n logger.consola?.error(it.error)\n })\n\n process.exit(1)\n }\n\n // TODO check if we can remove error\n if (error && logger.consola) {\n logger.consola?.resumeLogs()\n logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n logger.consola.box({\n title: `${config.name || ''}`,\n message: summary.join(''),\n style: {\n padding: 2,\n borderColor: 'red',\n borderStyle: 'rounded',\n },\n })\n\n const errors = getErrorCauses([error])\n if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) {\n errors.forEach((err) => {\n logger.consola?.error(err)\n })\n }\n\n logger.consola?.error(error)\n\n process.exit(1)\n }\n\n // formatting\n if (config.output.format === 'prettier') {\n logger?.emit('start', `Formatting with ${config.output.format}`)\n\n try {\n await execa('prettier', ['--ignore-unknown', '--write', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Prettier not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Formatted with ${config.output.format}`)\n }\n\n if (config.output.format === 'biome') {\n logger?.emit('start', `Formatting with ${config.output.format}`)\n\n try {\n await execa('biome', ['format', '--write', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Biome not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Formatted with ${config.output.format}`)\n }\n\n // linting\n if (config.output.lint === 'eslint') {\n logger?.emit('start', `Linting with ${config.output.lint}`)\n\n try {\n await execa('eslint', [path.resolve(definedConfig.root, definedConfig.output.path), '--fix'])\n } catch (e) {\n logger.consola?.warn('Eslint not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Linted with ${config.output.lint}`)\n }\n\n if (config.output.lint === 'biome') {\n logger?.emit('start', `Linting with ${config.output.lint}`)\n\n try {\n await execa('biome', ['lint', '--fix', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Biome not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Linted with ${config.output.lint}`)\n }\n\n if (config.output.lint === 'oxlint') {\n logger?.emit('start', `Linting with ${config.output.lint}`)\n\n try {\n await execa('oxlint', ['--fix', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Oxlint not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Linted with ${config.output.lint}`)\n }\n\n if (config.hooks) {\n await executeHooks({ hooks: config.hooks, logger })\n }\n\n logger.consola?.log(`⚡Build completed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n logger.consola?.box({\n title: `${config.name || ''}`,\n message: summary.join(''),\n style: {\n padding: 2,\n borderColor: 'green',\n borderStyle: 'rounded',\n },\n })\n}\n"],"mappings":";;;;;;;;;;;;AAMA,IAAa,kBAAb,cAAqC,SAAS;CAC5C;CACA;CACA,YAAY,SAAsC,SAAiB,MAAwB;AACzF,QAAM,KAAK;AAEX,OAAK,UAAU;AACf,OAAK,UAAU;;CAEjB,OAAO,OAAY,WAA2B,UAAgD;AAC5F,YAAQ,OAAO,MAAM,GAAG,GAAG,IAAI,OAAO,UAAU,CAAC,GAAG;AAEpD,YAAU;;;;;;ACLd,eAAsB,aAAa,EAAE,OAAO,UAA8C;CACxF,MAAM,WAAW,MAAM,QAAQ,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,KAAK,CAAC,OAAO,QAAQ;AAEtF,MAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,kBAAkB,IAAI,gBAA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AO,SAAS,UAAU;AACnC,UAAQ,KAAK,SAAS,gBAAgB,OAAO,OAAO,OAAO;AAE3D,MAAI;AACF,SAAM,MAAM,UAAU,CAAC,SAAS,KAAK,QAAQ,cAAc,MAAM,cAAc,OAAO,KAAK,CAAC,CAAC;WACtF,GAAG;AACV,UAAO,SAAS,KAAK,mBAAmB;AACxC,UAAO,SAAS,MAAM,EAAE;;AAG1B,UAAQ,KAAK,WAAW,eAAe,OAAO,OAAO,OAAO;;AAG9D,KAAI,OAAO,MACT,OAAM,aAAa;EAAE,OAAO,OAAO;EAAO;EAAQ,CAAC;AAGrD,QAAO,SAAS,IAAI,oBAAoB,OAAO,aAAa,UAAU,SAAS,GAAG,IAAI,UAAW,GAAG,KAAK;AAEzG,QAAO,SAAS,IAAI;EAClB,OAAO,GAAG,OAAO,QAAQ;EACzB,SAAS,QAAQ,KAAK,GAAG;EACzB,OAAO;GACL,SAAS;GACT,aAAa;GACb,aAAa;GACd;EACF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-CVRHD5GD.cjs","names":["results: Array<Config>","path","pc","LogMapper","pc","path","process","PromiseManager"],"sources":["../src/utils/getPlugins.ts","../src/utils/getConfig.ts","../src/utils/getCosmiConfig.ts","../src/utils/watcher.ts","../src/commands/generate.ts"],"sourcesContent":["import type { UserConfig } from '@kubb/core'\n\nfunction isJSONPlugins(plugins: UserConfig['plugins']) {\n return !!(plugins as any)?.some((plugin: any) => {\n return Array.isArray(plugin) && typeof plugin?.at(0) === 'string'\n })\n}\n\nfunction isObjectPlugins(plugins: UserConfig['plugins']): plugins is any {\n return plugins instanceof Object && !Array.isArray(plugins)\n}\n\nexport function getPlugins(plugins: UserConfig['plugins']): Promise<UserConfig['plugins']> {\n if (isObjectPlugins(plugins)) {\n throw new Error('Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')\n }\n\n if (isJSONPlugins(plugins)) {\n throw new Error('JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')\n }\n\n return Promise.resolve(plugins)\n}\n","import type { CLIOptions, Config, UserConfig } from '@kubb/core'\nimport { isPromise } from '@kubb/core/utils'\nimport type { Args } from '../commands/generate.ts'\nimport type { CosmiconfigResult } from './getCosmiConfig.ts'\nimport { getPlugins } from './getPlugins.ts'\n\n/**\n * Converting UserConfig to Config without a change in the object beside the JSON convert.\n */\nexport async function getConfig(result: CosmiconfigResult, args: Args): Promise<Array<Config> | Config> {\n const config = result?.config\n let kubbUserConfig = Promise.resolve(config) as Promise<UserConfig | Array<UserConfig>>\n\n // for ts or js files\n if (typeof config === 'function') {\n const possiblePromise = config(args as CLIOptions)\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise\n }\n kubbUserConfig = Promise.resolve(possiblePromise)\n }\n\n let JSONConfig = await kubbUserConfig\n\n if (Array.isArray(JSONConfig)) {\n const results: Array<Config> = []\n\n for (const item of JSONConfig) {\n const plugins = item.plugins ? await getPlugins(item.plugins) : undefined\n\n results.push({\n ...item,\n plugins,\n } as Config)\n }\n\n return results\n }\n\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,\n }\n\n return JSONConfig as Config\n}\n","import type { defineConfig, UserConfig } from '@kubb/core'\nimport { cosmiconfig } from 'cosmiconfig'\nimport { createJiti } from 'jiti'\n\nexport type CosmiconfigResult = {\n filepath: string\n isEmpty?: boolean\n config: ReturnType<typeof defineConfig> | UserConfig\n}\n\nconst tsLoader = async (configFile: string) => {\n const jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: 'automatic',\n importSource: '@kubb/react-fabric',\n },\n sourceMaps: true,\n })\n\n const mod = await jiti.import(configFile, { default: true })\n\n return mod\n}\n\nexport async function getCosmiConfig(moduleName: string, config?: string): Promise<CosmiconfigResult> {\n const searchPlaces = [\n 'package.json',\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n `.${moduleName}rc.yaml`,\n `.${moduleName}rc.yml`,\n\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.js`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n\n `${moduleName}.config.ts`,\n `${moduleName}.config.js`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ]\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n ...searchPlaces.map((searchPlace) => {\n return `.config/${searchPlace}`\n }),\n ...searchPlaces.map((searchPlace) => {\n return `configs/${searchPlace}`\n }),\n ...searchPlaces,\n ],\n loaders: {\n '.ts': tsLoader,\n },\n })\n\n const result = config ? await explorer.load(config) : await explorer.search()\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')\n }\n\n return result as CosmiconfigResult\n}\n","import { createLogger } from '@kubb/core/logger'\nimport pc from 'picocolors'\n\nexport async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {\n const { watch } = await import('chokidar')\n const logger = createLogger()\n\n const ignored = '**/{.git,node_modules}/**'\n\n const watcher = watch(path, {\n ignorePermissionErrors: true,\n ignored,\n })\n watcher.on('all', (type, file) => {\n logger?.emit('info', pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))\n\n try {\n cb(path)\n } catch (_e) {\n logger?.emit('warning', pc.red('Watcher failed'))\n }\n })\n}\n","import path from 'node:path'\nimport * as process from 'node:process'\nimport { isInputPath, PromiseManager } from '@kubb/core'\nimport { createLogger, LogMapper } from '@kubb/core/logger'\nimport type { ArgsDef, ParsedArgs } from 'citty'\nimport { defineCommand, showUsage } from 'citty'\nimport type { SingleBar } from 'cli-progress'\nimport pc from 'picocolors'\nimport { getConfig } from '../utils/getConfig.ts'\nimport { getCosmiConfig } from '../utils/getCosmiConfig.ts'\nimport { startWatcher } from '../utils/watcher.ts'\n\ndeclare global {\n var isDevtoolsEnabled: any\n}\n\nconst args = {\n config: {\n type: 'string',\n description: 'Path to the Kubb config',\n alias: 'c',\n },\n logLevel: {\n type: 'string',\n description: 'Info, silent or debug',\n alias: 'l',\n default: 'info',\n valueHint: 'silent|info|debug',\n },\n watch: {\n type: 'boolean',\n description: 'Watch mode based on the input file',\n alias: 'w',\n default: false,\n },\n debug: {\n type: 'boolean',\n description: 'Override logLevel to debug',\n alias: 'd',\n default: false,\n },\n help: {\n type: 'boolean',\n description: 'Show help',\n alias: 'h',\n default: false,\n },\n} as const satisfies ArgsDef\n\nexport type Args = ParsedArgs<typeof args>\n\nconst command = defineCommand({\n meta: {\n name: 'generate',\n description: \"[input] Generate files based on a 'kubb.config.ts' file\",\n },\n args,\n async run(commandContext) {\n const progressCache = new Map<string, SingleBar>()\n\n const { args } = commandContext\n\n const input = args._[0]\n\n if (args.help) {\n return showUsage(command)\n }\n\n if (args.debug) {\n args.logLevel = 'debug'\n }\n\n const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3\n const logger = createLogger({\n logLevel,\n })\n const { generate } = await import('../runners/generate.ts')\n\n logger.emit('start', 'Loading config')\n\n const result = await getCosmiConfig('kubb', args.config)\n logger.emit('success', `Config loaded(${pc.dim(path.relative(process.cwd(), result.filepath))})`)\n\n const config = await getConfig(result, args)\n\n const start = async () => {\n if (Array.isArray(config)) {\n const promiseManager = new PromiseManager()\n const promises = config.map((c) => () => {\n progressCache.clear()\n\n return generate({\n input,\n config: c,\n args,\n progressCache,\n })\n })\n\n await promiseManager.run('seq', promises)\n return\n }\n\n progressCache.clear()\n\n await generate({\n input,\n config,\n progressCache,\n args,\n })\n\n return\n }\n\n if (args.watch) {\n if (Array.isArray(config)) {\n throw new Error('Cannot use watcher with multiple Configs(array)')\n }\n\n if (isInputPath(config)) {\n return startWatcher([input || config.input.path], async (paths) => {\n await start()\n logger.emit('start', pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))\n })\n }\n }\n\n await start()\n\n if (globalThis.isDevtoolsEnabled) {\n const canRestart = await logger.consola?.prompt('Restart(could be used to validate the profiler)?', {\n type: 'confirm',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,OAAO,MAAM,KAAK,EAAE,OAAO,UAAU;AACjE,UAAM,OAAO;AACb,WAAO,KAAK,SAASH,mBAAG,OAAOA,mBAAG,KAAK,2BAA2B,MAAM,KAAK,QAAQ,GAAG,CAAC,CAAC;KAC1F;;AAIN,QAAM,OAAO;AAEb,MAAI,WAAW,kBAMb,KALmB,MAAM,OAAO,SAAS,OAAO,oDAAoD;GAClG,MAAM;GACN,SAAS;GACV,CAAC,CAGA,OAAM,OAAO;MAEb,cAAQ,KAAK,EAAE;;CAItB,CAAC;AAEF,uBAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-LbioowO-.cjs","names":["Writable","pc","LogMapper","pc","pc","path","process","LogMapper","SingleBar","Presets","definedConfig: Config","pc","path"],"sources":["../src/utils/Writables.ts","../src/utils/executeHooks.ts","../src/utils/getErrorCauses.ts","../src/utils/parseHrtimeToSeconds.ts","../src/utils/getSummary.ts","../src/runners/generate.ts"],"sourcesContent":["import * as process from 'node:process'\nimport type { WritableOptions } from 'node:stream'\nimport { Writable } from 'node:stream'\nimport type { ConsolaInstance } from 'consola'\nimport pc from 'picocolors'\n\nexport class ConsolaWritable extends Writable {\n consola: ConsolaInstance | undefined\n command: string\n constructor(consola: ConsolaInstance | undefined, command: string, opts?: WritableOptions) {\n super(opts)\n\n this.command = command\n this.consola = consola\n }\n _write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {\n process.stdout.write(`${pc.dim(chunk?.toString())}`)\n\n callback()\n }\n}\n","import type { Config } from '@kubb/core'\nimport type { Logger } from '@kubb/core/logger'\nimport { LogMapper } from '@kubb/core/logger'\nimport { execa } from 'execa'\nimport pc from 'picocolors'\nimport { parseArgsStringToArgv } from 'string-argv'\nimport { ConsolaWritable } from './Writables.ts'\n\ntype ExecutingHooksProps = {\n hooks: NonNullable<Config['hooks']>\n logger: Logger\n}\n\nexport async function executeHooks({ hooks, logger }: ExecutingHooksProps): Promise<void> {\n const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean)\n\n for (const command of commands) {\n const consolaWritable = new ConsolaWritable(logger.consola!, command)\n const [cmd, ..._args] = [...parseArgsStringToArgv(command)]\n\n if (!cmd) {\n continue\n }\n\n logger?.emit('start', `Executing hook ${logger.logLevel !== LogMapper.silent ? pc.dim(command) : ''}`)\n\n await execa(cmd, _args, {\n detached: true,\n stdout: logger?.logLevel === LogMapper.silent ? undefined : ['pipe', consolaWritable],\n stripFinalNewline: true,\n })\n\n logger?.emit('success', `Executed hook ${logger.logLevel !== LogMapper.silent ? pc.dim(command) : ''}`)\n }\n\n logger?.emit('success', 'Executed hooks')\n}\n","export function getErrorCauses(errors: Error[]): Error[] {\n return errors\n .reduce((prev, error) => {\n const causedError = error?.cause as Error\n if (causedError) {\n prev = [...prev, ...getErrorCauses([causedError])]\n return prev\n }\n prev = [...prev, error]\n\n return prev\n }, [] as Error[])\n .filter(Boolean)\n}\n","export function parseHrtimeToSeconds(hrtime: [number, number]): string {\n const seconds = (hrtime[0] + hrtime[1] / 1e9).toFixed(3)\n return seconds\n}\n","import path from 'node:path'\nimport type { Config, Plugin } from '@kubb/core'\nimport { randomCliColour } from '@kubb/core/logger'\nimport pc from 'picocolors'\nimport { parseHrtimeToSeconds } from './parseHrtimeToSeconds.ts'\n\ntype SummaryProps = {\n failedPlugins: Set<{ plugin: Plugin; error: Error }>\n status: 'success' | 'failed'\n hrStart: [number, number]\n filesCreated: number\n config: Config\n}\n\nexport function getSummary({ failedPlugins, filesCreated, status, hrStart, config }: SummaryProps): string[] {\n const logs = new Set<string>()\n const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrStart))\n\n const pluginsCount = config.plugins?.length || 0\n const successCount = pluginsCount - failedPlugins.size\n\n const meta = {\n plugins:\n status === 'success'\n ? `${pc.green(`${successCount} successful`)}, ${pluginsCount} total`\n : `${pc.red(`${failedPlugins.size ?? 1} failed`)}, ${pluginsCount} total`,\n pluginsFailed: status === 'failed' ? [...failedPlugins]?.map(({ plugin }) => randomCliColour(plugin.name))?.join(', ') : undefined,\n filesCreated: filesCreated,\n time: `${pc.yellow(`${elapsedSeconds}s`)}`,\n output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root,\n } as const\n\n logs.add(\n [\n [`${pc.bold('Plugins:')} ${meta.plugins}`, true],\n [`${pc.dim('Failed:')} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],\n [`${pc.bold('Generated:')} ${meta.filesCreated} files in ${meta.time}`, true],\n [`${pc.bold('Output:')} ${meta.output}`, true],\n ]\n .map((item) => {\n if (item.at(1)) {\n return item.at(0)\n }\n return undefined\n })\n .filter(Boolean)\n .join('\\n'),\n )\n\n return [...logs]\n}\n","import path from 'node:path'\nimport process from 'node:process'\nimport { type Config, safeBuild, setup } from '@kubb/core'\nimport { createLogger, LogMapper } from '@kubb/core/logger'\nimport { Presets, SingleBar } from 'cli-progress'\nimport { execa } from 'execa'\nimport pc from 'picocolors'\nimport type { Args } from '../commands/generate.ts'\nimport { executeHooks } from '../utils/executeHooks.ts'\nimport { getErrorCauses } from '../utils/getErrorCauses.ts'\nimport { getSummary } from '../utils/getSummary.ts'\n\ntype GenerateProps = {\n input?: string\n config: Config\n args: Args\n progressCache: Map<string, SingleBar>\n}\n\nexport async function generate({ input, config, progressCache, args }: GenerateProps): Promise<void> {\n const hrStart = process.hrtime()\n const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3\n\n const logger = createLogger({\n logLevel,\n name: config.name,\n })\n\n const { root = process.cwd(), ...userConfig } = config\n const inputPath = input ?? ('path' in userConfig.input ? userConfig.input.path : undefined)\n\n if (logger.logLevel !== LogMapper.debug) {\n logger.on('progress_start', ({ id, size, message = '' }) => {\n logger.consola?.pauseLogs()\n const payload = { id, message }\n const progressBar = new SingleBar(\n {\n format: '{percentage}% {bar} {value}/{total} | {message}',\n barsize: 30,\n clearOnComplete: true,\n emptyOnZero: true,\n },\n Presets.shades_grey,\n )\n\n if (!progressCache.has(id)) {\n progressCache.set(id, progressBar)\n progressBar.start(size, 1, payload)\n }\n })\n\n logger.on('progress_stop', ({ id }) => {\n progressCache.get(id)?.stop()\n logger.consola?.resumeLogs()\n })\n\n logger.on('progressed', ({ id, message = '' }) => {\n const payload = { id, message }\n\n progressCache.get(id)?.increment(1, payload)\n })\n }\n\n const definedConfig: Config = {\n root,\n ...userConfig,\n input: inputPath\n ? {\n ...userConfig.input,\n path: inputPath,\n }\n : userConfig.input,\n output: {\n write: true,\n barrelType: 'named',\n extension: {\n '.ts': '.ts',\n },\n format: 'prettier',\n ...userConfig.output,\n },\n }\n\n const { fabric, pluginManager } = await setup({\n config: definedConfig,\n logger,\n })\n\n logger.emit('start', `Building ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n const { files, failedPlugins, error } = await safeBuild(\n {\n config: definedConfig,\n logger,\n },\n { pluginManager, fabric },\n )\n\n if (logger.logLevel === LogMapper.debug) {\n logger.consola?.start('Writing logs')\n\n const logFiles = await logger.writeLogs()\n\n logger.consola?.success(`Written logs: \\n${logFiles.join('\\n')}`)\n }\n\n const summary = getSummary({\n failedPlugins,\n filesCreated: files.length,\n config: definedConfig,\n status: failedPlugins.size > 0 || error ? 'failed' : 'success',\n hrStart,\n })\n\n if (failedPlugins.size && logger.consola) {\n logger.consola?.resumeLogs()\n logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n logger.consola.box({\n title: `${config.name || ''}`,\n message: summary.join(''),\n style: {\n padding: 2,\n borderColor: 'red',\n borderStyle: 'rounded',\n },\n })\n\n const errors = getErrorCauses([...failedPlugins].filter((it) => it.error).map((it) => it.error))\n if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) {\n errors.forEach((err) => {\n logger.consola?.error(err)\n })\n }\n\n ;[...failedPlugins]\n .filter((it) => it.error)\n .forEach((it) => {\n logger.consola?.error(it.error)\n })\n\n process.exit(1)\n }\n\n // TODO check if we can remove error\n if (error && logger.consola) {\n logger.consola?.resumeLogs()\n logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n logger.consola.box({\n title: `${config.name || ''}`,\n message: summary.join(''),\n style: {\n padding: 2,\n borderColor: 'red',\n borderStyle: 'rounded',\n },\n })\n\n const errors = getErrorCauses([error])\n if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) {\n errors.forEach((err) => {\n logger.consola?.error(err)\n })\n }\n\n logger.consola?.error(error)\n\n process.exit(1)\n }\n\n // formatting\n if (config.output.format === 'prettier') {\n logger?.emit('start', `Formatting with ${config.output.format}`)\n\n try {\n await execa('prettier', ['--ignore-unknown', '--write', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Prettier not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Formatted with ${config.output.format}`)\n }\n\n if (config.output.format === 'biome') {\n logger?.emit('start', `Formatting with ${config.output.format}`)\n\n try {\n await execa('biome', ['format', '--write', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Biome not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Formatted with ${config.output.format}`)\n }\n\n // linting\n if (config.output.lint === 'eslint') {\n logger?.emit('start', `Linting with ${config.output.lint}`)\n\n try {\n await execa('eslint', [path.resolve(definedConfig.root, definedConfig.output.path), '--fix'])\n } catch (e) {\n logger.consola?.warn('Eslint not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Linted with ${config.output.lint}`)\n }\n\n if (config.output.lint === 'biome') {\n logger?.emit('start', `Linting with ${config.output.lint}`)\n\n try {\n await execa('biome', ['lint', '--fix', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Biome not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Linted with ${config.output.lint}`)\n }\n\n if (config.output.lint === 'oxlint') {\n logger?.emit('start', `Linting with ${config.output.lint}`)\n\n try {\n await execa('oxlint', ['--fix', path.resolve(definedConfig.root, definedConfig.output.path)])\n } catch (e) {\n logger.consola?.warn('Oxlint not found')\n logger.consola?.error(e)\n }\n\n logger?.emit('success', `Linted with ${config.output.lint}`)\n }\n\n if (config.hooks) {\n await executeHooks({ hooks: config.hooks, logger })\n }\n\n logger.consola?.log(`⚡Build completed ${logger.logLevel !== LogMapper.silent ? pc.dim(inputPath!) : ''}`)\n\n logger.consola?.box({\n title: `${config.name || ''}`,\n message: summary.join(''),\n style: {\n padding: 2,\n borderColor: 'green',\n borderStyle: 'rounded',\n },\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;AAMA,IAAa,kBAAb,cAAqCA,qBAAS;CAC5C;CACA;CACA,YAAY,SAAsC,SAAiB,MAAwB;AACzF,QAAM,KAAK;AAEX,OAAK,UAAU;AACf,OAAK,UAAU;;CAEjB,OAAO,OAAY,WAA2B,UAAgD;AAC5F,eAAQ,OAAO,MAAM,GAAGC,mBAAG,IAAI,OAAO,UAAU,CAAC,GAAG;AAEpD,YAAU;;;;;;ACLd,eAAsB,aAAa,EAAE,OAAO,UAA8C;CACxF,MAAM,WAAW,MAAM,QAAQ,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,MAAM,KAAK,CAAC,OAAO,QAAQ;AAEtF,MAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,kBAAkB,IAAI,gBAAgB,OAAO,SAAU,QAAQ;EACrE,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC,0CAAyB,QAAQ,CAAC;AAE3D,MAAI,CAAC,IACH;AAGF,UAAQ,KAAK,SAAS,kBAAkB,OAAO,aAAaC,6BAAU,SAASC,mBAAG,IAAI,QAAQ,GAAG,KAAK;AAEtG,yBAAY,KAAK,OAAO;GACtB,UAAU;GACV,QAAQ,QAAQ,aAAaD,6BAAU,SAAS,SAAY,CAAC,QAAQ,gBAAgB;GACrF,mBAAmB;GACpB,CAAC;AAEF,UAAQ,KAAK,WAAW,iBAAiB,O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EAAO;EAAQ,CAAC;AAGrD,QAAO,SAAS,IAAI,oBAAoB,OAAO,aAAaL,6BAAU,SAASI,mBAAG,IAAI,UAAW,GAAG,KAAK;AAEzG,QAAO,SAAS,IAAI;EAClB,OAAO,GAAG,OAAO,QAAQ;EACzB,SAAS,QAAQ,KAAK,GAAG;EACzB,OAAO;GACL,SAAS;GACT,aAAa;GACb,aAAa;GACd;EACF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-mP1U-zi4.js","names":["results: Array<Config>","path","process"],"sources":["../src/utils/getPlugins.ts","../src/utils/getConfig.ts","../src/utils/getCosmiConfig.ts","../src/utils/watcher.ts","../src/commands/generate.ts"],"sourcesContent":["import type { UserConfig } from '@kubb/core'\n\nfunction isJSONPlugins(plugins: UserConfig['plugins']) {\n return !!(plugins as any)?.some((plugin: any) => {\n return Array.isArray(plugin) && typeof plugin?.at(0) === 'string'\n })\n}\n\nfunction isObjectPlugins(plugins: UserConfig['plugins']): plugins is any {\n return plugins instanceof Object && !Array.isArray(plugins)\n}\n\nexport function getPlugins(plugins: UserConfig['plugins']): Promise<UserConfig['plugins']> {\n if (isObjectPlugins(plugins)) {\n throw new Error('Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')\n }\n\n if (isJSONPlugins(plugins)) {\n throw new Error('JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')\n }\n\n return Promise.resolve(plugins)\n}\n","import type { CLIOptions, Config, UserConfig } from '@kubb/core'\nimport { isPromise } from '@kubb/core/utils'\nimport type { Args } from '../commands/generate.ts'\nimport type { CosmiconfigResult } from './getCosmiConfig.ts'\nimport { getPlugins } from './getPlugins.ts'\n\n/**\n * Converting UserConfig to Config without a change in the object beside the JSON convert.\n */\nexport async function getConfig(result: CosmiconfigResult, args: Args): Promise<Array<Config> | Config> {\n const config = result?.config\n let kubbUserConfig = Promise.resolve(config) as Promise<UserConfig | Array<UserConfig>>\n\n // for ts or js files\n if (typeof config === 'function') {\n const possiblePromise = config(args as CLIOptions)\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise\n }\n kubbUserConfig = Promise.resolve(possiblePromise)\n }\n\n let JSONConfig = await kubbUserConfig\n\n if (Array.isArray(JSONConfig)) {\n const results: Array<Config> = []\n\n for (const item of JSONConfig) {\n const plugins = item.plugins ? await getPlugins(item.plugins) : undefined\n\n results.push({\n ...item,\n plugins,\n } as Config)\n }\n\n return results\n }\n\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,\n }\n\n return JSONConfig as Config\n}\n","import type { defineConfig, UserConfig } from '@kubb/core'\nimport { cosmiconfig } from 'cosmiconfig'\nimport { createJiti } from 'jiti'\n\nexport type CosmiconfigResult = {\n filepath: string\n isEmpty?: boolean\n config: ReturnType<typeof defineConfig> | UserConfig\n}\n\nconst tsLoader = async (configFile: string) => {\n const jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: 'automatic',\n importSource: '@kubb/react-fabric',\n },\n sourceMaps: true,\n })\n\n const mod = await jiti.import(configFile, { default: true })\n\n return mod\n}\n\nexport async function getCosmiConfig(moduleName: string, config?: string): Promise<CosmiconfigResult> {\n const searchPlaces = [\n 'package.json',\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n `.${moduleName}rc.yaml`,\n `.${moduleName}rc.yml`,\n\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.js`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n\n `${moduleName}.config.ts`,\n `${moduleName}.config.js`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ]\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n ...searchPlaces.map((searchPlace) => {\n return `.config/${searchPlace}`\n }),\n ...searchPlaces.map((searchPlace) => {\n return `configs/${searchPlace}`\n }),\n ...searchPlaces,\n ],\n loaders: {\n '.ts': tsLoader,\n },\n })\n\n const result = config ? await explorer.load(config) : await explorer.search()\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')\n }\n\n return result as CosmiconfigResult\n}\n","import { createLogger } from '@kubb/core/logger'\nimport pc from 'picocolors'\n\nexport async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {\n const { watch } = await import('chokidar')\n const logger = createLogger()\n\n const ignored = '**/{.git,node_modules}/**'\n\n const watcher = watch(path, {\n ignorePermissionErrors: true,\n ignored,\n })\n watcher.on('all', (type, file) => {\n logger?.emit('info', pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))\n\n try {\n cb(path)\n } catch (_e) {\n logger?.emit('warning', pc.red('Watcher failed'))\n }\n })\n}\n","import path from 'node:path'\nimport * as process from 'node:process'\nimport { isInputPath, PromiseManager } from '@kubb/core'\nimport { createLogger, LogMapper } from '@kubb/core/logger'\nimport type { ArgsDef, ParsedArgs } from 'citty'\nimport { defineCommand, showUsage } from 'citty'\nimport type { SingleBar } from 'cli-progress'\nimport pc from 'picocolors'\nimport { getConfig } from '../utils/getConfig.ts'\nimport { getCosmiConfig } from '../utils/getCosmiConfig.ts'\nimport { startWatcher } from '../utils/watcher.ts'\n\ndeclare global {\n var isDevtoolsEnabled: any\n}\n\nconst args = {\n config: {\n type: 'string',\n description: 'Path to the Kubb config',\n alias: 'c',\n },\n logLevel: {\n type: 'string',\n description: 'Info, silent or debug',\n alias: 'l',\n default: 'info',\n valueHint: 'silent|info|debug',\n },\n watch: {\n type: 'boolean',\n description: 'Watch mode based on the input file',\n alias: 'w',\n default: false,\n },\n debug: {\n type: 'boolean',\n description: 'Override logLevel to debug',\n alias: 'd',\n default: false,\n },\n help: {\n type: 'boolean',\n description: 'Show help',\n alias: 'h',\n default: false,\n },\n} as const satisfies ArgsDef\n\nexport type Args = ParsedArgs<typeof args>\n\nconst command = defineCommand({\n meta: {\n name: 'generate',\n description: \"[input] Generate files based on a 'kubb.config.ts' file\",\n },\n args,\n async run(commandContext) {\n const progressCache = new Map<string, SingleBar>()\n\n const { args } = commandContext\n\n const input = args._[0]\n\n if (args.help) {\n return showUsage(command)\n }\n\n if (args.debug) {\n args.logLevel = 'debug'\n }\n\n const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3\n const logger = createLogger({\n logLevel,\n })\n const { generate } = await import('../runners/generate.ts')\n\n logger.emit('start', 'Loading config')\n\n const result = await getCosmiConfig('kubb', args.config)\n logger.emit('success', `Config loaded(${pc.dim(path.relative(process.cwd(), result.filepath))})`)\n\n const config = await getConfig(result, args)\n\n const start = async () => {\n if (Array.isArray(config)) {\n const promiseManager = new PromiseManager()\n const promises = config.map((c) => () => {\n progressCache.clear()\n\n return generate({\n input,\n config: c,\n args,\n progressCache,\n })\n })\n\n await promiseManager.run('seq', promises)\n return\n }\n\n progressCache.clear()\n\n await generate({\n input,\n config,\n progressCache,\n args,\n })\n\n return\n }\n\n if (args.watch) {\n if (Array.isArray(config)) {\n throw new Error('Cannot use watcher with multiple Configs(array)')\n }\n\n if (isInputPath(config)) {\n return startWatcher([input || config.input.path], async (paths) => {\n await start()\n logger.emit('start', pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))\n })\n }\n }\n\n await start()\n\n if (globalThis.isDevtoolsEnabled) {\n const canRestart = await logger.consola?.prompt('Restart(could be used to validate the profiler)?', {\n type: 'confirm',\n initial: false,\n })\n\n if (canRestart) {\n await start()\n } else {\n process.exit(1)\n }\n }\n },\n})\n\nexport default command\n"],"mappings":";;;;;;;;;;;AAEA,SAAS,cAAc,SAAgC;AACrD,QAAO,CAAC,CAAE,SAAiB,MAAM,WAAgB;AAC/C,SAAO,MAAM,QAAQ,OAAO,IAAI,OAAO,QAAQ,GAAG,EAAE,KAAK;GACzD;;AAGJ,SAAS,gBAAgB,SAAgD;AACvE,QAAO,mBAAmB,UAAU,CAAC,MAAM,QAAQ,QAAQ;;AAG7D,SAAgB,WAAW,SAAgE;AACzF,KAAI,gBAAgB,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|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function getErrorCauses(errors: Error[]): Error[] {
|
|
2
|
-
return errors
|
|
3
|
-
.reduce((prev, error) => {
|
|
4
|
-
const causedError = error?.cause as Error
|
|
5
|
-
if (causedError) {
|
|
6
|
-
prev = [...prev, ...getErrorCauses([causedError])]
|
|
7
|
-
return prev
|
|
8
|
-
}
|
|
9
|
-
prev = [...prev, error]
|
|
10
|
-
|
|
11
|
-
return prev
|
|
12
|
-
}, [] as Error[])
|
|
13
|
-
.filter(Boolean)
|
|
14
|
-
}
|