@kubb/cli 3.0.0-alpha.4 → 3.0.0-alpha.5
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/{chunk-7CMTKETP.cjs → chunk-H3BA33NF.cjs} +757 -116
- package/dist/chunk-H3BA33NF.cjs.map +1 -0
- package/dist/{chunk-Y35VLSP2.js → chunk-WJ72QPXS.js} +44 -33
- package/dist/chunk-WJ72QPXS.js.map +1 -0
- package/dist/{generate-FHYQHKKR.js → generate-LZOUPH5K.js} +4 -4
- package/dist/generate-LZOUPH5K.js.map +1 -0
- package/dist/{generate-ZGEX2WSJ.cjs → generate-M3IAQ4OY.cjs} +16 -16
- package/dist/{generate-ZGEX2WSJ.cjs.map → generate-M3IAQ4OY.cjs.map} +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/src/commands/generate.ts +2 -2
- package/src/generate.ts +25 -29
- package/src/utils/Writables.ts +2 -22
- package/src/utils/executeHooks.ts +13 -15
- package/src/utils/getSummary.ts +0 -6
- package/dist/chunk-7CMTKETP.cjs.map +0 -1
- package/dist/chunk-Y35VLSP2.js.map +0 -1
- package/dist/generate-FHYQHKKR.js.map +0 -1
package/src/generate.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createLogger } from '@kubb/core/logger'
|
|
1
|
+
import { createLogger, LogMapper } from '@kubb/core/logger'
|
|
2
2
|
|
|
3
3
|
import c from 'tinyrainbow'
|
|
4
4
|
|
|
@@ -8,9 +8,11 @@ import { executeHooks } from './utils/executeHooks.ts'
|
|
|
8
8
|
import { getErrorCauses } from './utils/getErrorCauses.ts'
|
|
9
9
|
import { getSummary } from './utils/getSummary.ts'
|
|
10
10
|
import { writeLog } from './utils/writeLog.ts'
|
|
11
|
-
import
|
|
11
|
+
import type * as KubbFile from '@kubb/fs/types'
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { SingleBar, Presets } from 'cli-progress'
|
|
14
|
+
import { getRelativePath } from '@kubb/fs'
|
|
15
|
+
import { relative } from 'node:path'
|
|
14
16
|
|
|
15
17
|
type GenerateProps = {
|
|
16
18
|
input?: string
|
|
@@ -18,39 +20,33 @@ type GenerateProps = {
|
|
|
18
20
|
args: Args
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
export function
|
|
22
|
-
|
|
23
|
+
export async function generate({ input, config, args }: GenerateProps): Promise<void> {
|
|
24
|
+
const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3
|
|
25
|
+
const logger = createLogger({
|
|
26
|
+
logLevel,
|
|
27
|
+
name: config.name,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const progress = new SingleBar(
|
|
23
31
|
{
|
|
24
|
-
format: '
|
|
32
|
+
format: logLevel === LogMapper.info ? '{percentage}% {bar} {value}/{total} files | ETA: {eta}s | {filename}' : '{percentage}% {bar} ETA: {eta}s',
|
|
25
33
|
barsize: 40,
|
|
26
34
|
fps: 5,
|
|
27
|
-
stream: process.stderr,
|
|
28
35
|
clearOnComplete: true,
|
|
29
36
|
},
|
|
30
37
|
Presets.shades_grey,
|
|
31
38
|
)
|
|
32
|
-
}
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
logger.on('progress', ({ count, size, file }) => {
|
|
41
|
+
if (count === 0) {
|
|
42
|
+
progress.start(size, 0)
|
|
43
|
+
} else if (count === size) {
|
|
44
|
+
progress.stop()
|
|
45
|
+
} else {
|
|
46
|
+
progress.update(count, { filename: relative(config.root, file.path) || '' })
|
|
47
|
+
}
|
|
39
48
|
})
|
|
40
49
|
|
|
41
|
-
// const progress = createMultiProgressBar()
|
|
42
|
-
// let progressFiles: any
|
|
43
|
-
//
|
|
44
|
-
// logger.on('progress', (count, size) => {
|
|
45
|
-
// if (count === 0) {
|
|
46
|
-
// progressFiles = progress.create(size, 0)
|
|
47
|
-
// }
|
|
48
|
-
// progressFiles.update(count)
|
|
49
|
-
// if (count === size) {
|
|
50
|
-
// progressFiles.stop()
|
|
51
|
-
// }
|
|
52
|
-
// })
|
|
53
|
-
|
|
54
50
|
logger.on('debug', async (messages: string[]) => {
|
|
55
51
|
await writeLog(messages.join('\n'))
|
|
56
52
|
})
|
|
@@ -58,7 +54,7 @@ export async function generate({ input, config, args }: GenerateProps): Promise<
|
|
|
58
54
|
const { root = process.cwd(), ...userConfig } = config
|
|
59
55
|
const inputPath = input ?? ('path' in userConfig.input ? userConfig.input.path : undefined)
|
|
60
56
|
|
|
61
|
-
logger.emit('start',
|
|
57
|
+
logger.emit('start', `Building ${logLevel !== LogMapper.silent ? c.dim(inputPath) : ''}`)
|
|
62
58
|
|
|
63
59
|
const definedConfig: Config = {
|
|
64
60
|
root,
|
|
@@ -89,7 +85,7 @@ export async function generate({ input, config, args }: GenerateProps): Promise<
|
|
|
89
85
|
})
|
|
90
86
|
|
|
91
87
|
if (error && logger.consola) {
|
|
92
|
-
logger.consola.error(
|
|
88
|
+
logger.consola.error(`Build failed ${logLevel !== LogMapper.silent ? c.dim(inputPath) : ''}`)
|
|
93
89
|
|
|
94
90
|
logger.consola.box({
|
|
95
91
|
title: `${config.name || ''}`,
|
|
@@ -117,7 +113,7 @@ export async function generate({ input, config, args }: GenerateProps): Promise<
|
|
|
117
113
|
await executeHooks({ hooks: config.hooks, logger })
|
|
118
114
|
}
|
|
119
115
|
|
|
120
|
-
logger.consola?.
|
|
116
|
+
logger.consola?.log(`⚡️Build completed ${logLevel !== LogMapper.silent ? c.dim(inputPath) : ''}`)
|
|
121
117
|
|
|
122
118
|
logger.consola?.box({
|
|
123
119
|
title: `${config.name || ''}`,
|
package/src/utils/Writables.ts
CHANGED
|
@@ -4,23 +4,7 @@ import c from 'tinyrainbow'
|
|
|
4
4
|
|
|
5
5
|
import type { WritableOptions } from 'node:stream'
|
|
6
6
|
import type { ConsolaInstance } from 'consola'
|
|
7
|
-
|
|
8
|
-
export class BasicWritables extends Writable {
|
|
9
|
-
#frame = 'Loading ...'
|
|
10
|
-
set frame(frame: string) {
|
|
11
|
-
this.#frame = frame
|
|
12
|
-
}
|
|
13
|
-
get frame() {
|
|
14
|
-
return this.#frame
|
|
15
|
-
}
|
|
16
|
-
_write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
|
17
|
-
if (chunk?.toString() !== this.frame && chunk?.toString()) {
|
|
18
|
-
this.frame = chunk?.toString()
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
callback()
|
|
22
|
-
}
|
|
23
|
-
}
|
|
7
|
+
import * as process from 'node:process'
|
|
24
8
|
|
|
25
9
|
export class ConsolaWritable extends Writable {
|
|
26
10
|
consola: ConsolaInstance
|
|
@@ -32,11 +16,7 @@ export class ConsolaWritable extends Writable {
|
|
|
32
16
|
this.consola = consola
|
|
33
17
|
}
|
|
34
18
|
_write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
|
35
|
-
|
|
36
|
-
this.consola.log(`${c.bold(c.blue(this.command))}: ${chunk?.toString()}`)
|
|
37
|
-
} else {
|
|
38
|
-
this.consola.log(`${c.bold(c.blue(this.command))}: ${chunk?.toString()}`)
|
|
39
|
-
}
|
|
19
|
+
process.stdout.write(c.dim(chunk?.toString()))
|
|
40
20
|
|
|
41
21
|
callback()
|
|
42
22
|
}
|
|
@@ -7,6 +7,7 @@ import { ConsolaWritable } from './Writables.ts'
|
|
|
7
7
|
|
|
8
8
|
import type { Config } from '@kubb/core'
|
|
9
9
|
import { LogMapper } from '@kubb/core/logger'
|
|
10
|
+
import PQueue from 'p-queue'
|
|
10
11
|
|
|
11
12
|
type ExecutingHooksProps = {
|
|
12
13
|
hooks: NonNullable<Config['hooks']>
|
|
@@ -15,37 +16,34 @@ type ExecutingHooksProps = {
|
|
|
15
16
|
|
|
16
17
|
export async function executeHooks({ hooks, logger }: ExecutingHooksProps): Promise<void> {
|
|
17
18
|
const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean)
|
|
19
|
+
const queue = new PQueue({ concurrency: 1 })
|
|
18
20
|
|
|
19
|
-
const
|
|
20
|
-
.
|
|
21
|
-
|
|
22
|
-
const abortController = new AbortController()
|
|
23
|
-
const [cmd, ..._args] = [...parseArgsStringToArgv(command)]
|
|
21
|
+
const promises = commands.map(async (command) => {
|
|
22
|
+
const consolaWritable = new ConsolaWritable(logger.consola!, command)
|
|
23
|
+
const [cmd, ..._args] = [...parseArgsStringToArgv(command)]
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (!cmd) {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
+
await queue.add(async () => {
|
|
29
30
|
logger.emit('start', `Executing hook ${logger.logLevel !== LogMapper.silent ? c.dim(command) : ''}`)
|
|
30
31
|
|
|
31
32
|
const subProcess = await execa(cmd, _args, {
|
|
32
33
|
detached: true,
|
|
33
|
-
cancelSignal: abortController.signal,
|
|
34
34
|
stdout: logger.logLevel === LogMapper.silent ? undefined : ['pipe', consolaWritable],
|
|
35
|
+
stripFinalNewline: true,
|
|
35
36
|
})
|
|
36
37
|
|
|
37
38
|
logger.emit('success', `Executing hook ${logger.logLevel !== LogMapper.silent ? c.dim(command) : ''}`)
|
|
38
39
|
|
|
39
40
|
if (subProcess) {
|
|
40
|
-
logger.emit('
|
|
41
|
+
logger.emit('debug', [subProcess.stdout])
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
consolaWritable.destroy()
|
|
44
|
-
return { subProcess, abort: abortController.abort.bind(abortController) }
|
|
45
43
|
})
|
|
46
|
-
|
|
44
|
+
})
|
|
47
45
|
|
|
48
|
-
await Promise.all(
|
|
46
|
+
await Promise.all(promises)
|
|
49
47
|
|
|
50
48
|
logger.emit('success', 'Executing hooks')
|
|
51
49
|
}
|
package/src/utils/getSummary.ts
CHANGED
|
@@ -53,12 +53,6 @@ export function getSummary({ pluginManager, status, hrStart, config, logger }: S
|
|
|
53
53
|
output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root,
|
|
54
54
|
} as const
|
|
55
55
|
|
|
56
|
-
logger.emit('debug', ['\nGenerated files:\n'])
|
|
57
|
-
logger.emit(
|
|
58
|
-
'debug',
|
|
59
|
-
files.map((file) => `${randomCliColour(JSON.stringify(file.meta?.pluginKey))} ${file.path}`),
|
|
60
|
-
)
|
|
61
|
-
|
|
62
56
|
logs.push(
|
|
63
57
|
[
|
|
64
58
|
[`${c.bold('Plugins:')} ${meta.plugins}`, true],
|