@kubb/cli 3.0.0-alpha.4 → 3.0.0-alpha.6
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-Y35VLSP2.js → chunk-7EOWZACL.js} +62 -43
- package/dist/chunk-7EOWZACL.js.map +1 -0
- package/dist/{chunk-7CMTKETP.cjs → chunk-MXBF3FNZ.cjs} +775 -125
- package/dist/chunk-MXBF3FNZ.cjs.map +1 -0
- package/dist/{generate-FHYQHKKR.js → generate-B6YVAUQK.js} +4 -4
- package/dist/generate-B6YVAUQK.js.map +1 -0
- package/dist/{generate-ZGEX2WSJ.cjs → generate-D5R4IXLS.cjs} +16 -16
- package/dist/{generate-ZGEX2WSJ.cjs.map → generate-D5R4IXLS.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 +42 -34
- package/src/utils/Writables.ts +2 -22
- package/src/utils/executeHooks.ts +14 -20
- package/src/utils/getSummary.ts +5 -12
- package/src/utils/writeLog.ts +13 -3
- package/dist/chunk-7CMTKETP.cjs.map +0 -1
- package/dist/chunk-Y35VLSP2.js.map +0 -1
- package/dist/generate-FHYQHKKR.js.map +0 -1
|
@@ -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,30 @@ 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
|
-
logger.emit('success', `
|
|
38
|
-
|
|
39
|
-
if (subProcess) {
|
|
40
|
-
logger.emit('info', `Executing hooks\n ${subProcess.stdout}`)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
consolaWritable.destroy()
|
|
44
|
-
return { subProcess, abort: abortController.abort.bind(abortController) }
|
|
38
|
+
logger.emit('success', `Executed hook ${logger.logLevel !== LogMapper.silent ? c.dim(command) : ''}`)
|
|
45
39
|
})
|
|
46
|
-
|
|
40
|
+
})
|
|
47
41
|
|
|
48
|
-
await Promise.all(
|
|
42
|
+
await Promise.all(promises)
|
|
49
43
|
|
|
50
|
-
logger.emit('success', '
|
|
44
|
+
logger.emit('success', 'Executed hooks')
|
|
51
45
|
}
|
package/src/utils/getSummary.ts
CHANGED
|
@@ -6,7 +6,7 @@ import c from 'tinyrainbow'
|
|
|
6
6
|
|
|
7
7
|
import { parseHrtimeToSeconds } from './parseHrtimeToSeconds.ts'
|
|
8
8
|
|
|
9
|
-
import type { Config, PluginManager } from '@kubb/core'
|
|
9
|
+
import type { Config, FileMetaBase, PluginManager } from '@kubb/core'
|
|
10
10
|
import type { Logger } from '@kubb/core/logger'
|
|
11
11
|
|
|
12
12
|
type SummaryProps = {
|
|
@@ -17,7 +17,7 @@ type SummaryProps = {
|
|
|
17
17
|
logger: Logger
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export function getSummary({ pluginManager, status, hrStart, config
|
|
20
|
+
export function getSummary({ pluginManager, status, hrStart, config }: SummaryProps): string[] {
|
|
21
21
|
const logs: string[] = []
|
|
22
22
|
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrStart))
|
|
23
23
|
|
|
@@ -29,7 +29,7 @@ export function getSummary({ pluginManager, status, hrStart, config, logger }: S
|
|
|
29
29
|
|
|
30
30
|
const failedPlugins = config.plugins?.filter((plugin) => !buildEndPlugins.includes(plugin.name))?.map((plugin) => plugin.name)
|
|
31
31
|
const pluginsCount = config.plugins?.length || 0
|
|
32
|
-
const files = pluginManager.fileManager.files.sort((a, b) => {
|
|
32
|
+
const files = pluginManager.fileManager.files.sort((a: { meta?: FileMetaBase }, b: { meta?: FileMetaBase }) => {
|
|
33
33
|
if (!a.meta?.pluginKey?.[0] || !b.meta?.pluginKey?.[0]) {
|
|
34
34
|
return 0
|
|
35
35
|
}
|
|
@@ -49,22 +49,15 @@ export function getSummary({ pluginManager, status, hrStart, config, logger }: S
|
|
|
49
49
|
: `${c.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,
|
|
50
50
|
pluginsFailed: status === 'failed' ? failedPlugins?.map((name) => randomCliColour(name))?.join(', ') : undefined,
|
|
51
51
|
filesCreated: files.length,
|
|
52
|
-
time: `${c.yellow(`${elapsedSeconds}s`)}
|
|
52
|
+
time: `${c.yellow(`${elapsedSeconds}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],
|
|
65
59
|
[`${c.dim('Failed:')} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],
|
|
66
|
-
[`${c.bold('Generated:')} ${meta.filesCreated} files`, true],
|
|
67
|
-
[`${c.bold('Time:')} ${meta.time}`, true],
|
|
60
|
+
[`${c.bold('Generated:')} ${meta.filesCreated} files in ${meta.time}`, true],
|
|
68
61
|
[`${c.bold('Output:')} ${meta.output}`, true],
|
|
69
62
|
]
|
|
70
63
|
.map((item) => {
|
package/src/utils/writeLog.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { resolve } from 'node:path'
|
|
2
2
|
import { read, write } from '@kubb/fs'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type Props = {
|
|
5
|
+
data: string
|
|
6
|
+
fileName?: string
|
|
7
|
+
override?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function writeLog({ data, override, fileName = 'kubb.log' }: Props): Promise<string | undefined> {
|
|
5
11
|
if (data.trim() === '') {
|
|
6
12
|
return undefined
|
|
7
13
|
}
|
|
8
|
-
const path = resolve(process.cwd(),
|
|
14
|
+
const path = resolve(process.cwd(), fileName)
|
|
9
15
|
let previousLogs = ''
|
|
10
16
|
|
|
11
17
|
try {
|
|
@@ -14,5 +20,9 @@ export async function writeLog(data: string): Promise<string | undefined> {
|
|
|
14
20
|
/* empty */
|
|
15
21
|
}
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
if (override) {
|
|
24
|
+
return write(path, data.trim(), { sanity: false })
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return write(path, [previousLogs, data.trim()].filter(Boolean).join('\n'), { sanity: false })
|
|
18
28
|
}
|