@kubb/cli 3.0.0-alpha.1 → 3.0.0-alpha.11
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-EKC3Q472.js +204 -0
- package/dist/chunk-EKC3Q472.js.map +1 -0
- package/dist/{chunk-NKSXZ2SM.cjs → chunk-IO6NJ3A2.cjs} +1156 -3685
- package/dist/chunk-IO6NJ3A2.cjs.map +1 -0
- package/dist/{generate-IC27XOTA.js → generate-USO6RHZL.js} +29 -43
- package/dist/generate-USO6RHZL.js.map +1 -0
- package/dist/{generate-SW6IGE4J.cjs → generate-XNK7VVP4.cjs} +49 -51
- package/dist/generate-XNK7VVP4.cjs.map +1 -0
- package/dist/index.cjs +26 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -18
- package/dist/index.js.map +1 -1
- package/package.json +15 -13
- package/src/commands/generate.ts +15 -13
- package/src/generate.ts +79 -57
- package/src/index.ts +1 -1
- package/src/utils/Writables.ts +23 -0
- package/src/utils/executeHooks.ts +24 -44
- package/src/utils/getPlugins.ts +0 -10
- package/src/utils/getSummary.ts +10 -36
- package/src/utils/watcher.ts +4 -6
- package/dist/chunk-NKSXZ2SM.cjs.map +0 -1
- package/dist/chunk-VGYRBGKV.js +0 -252
- package/dist/chunk-VGYRBGKV.js.map +0 -1
- package/dist/generate-IC27XOTA.js.map +0 -1
- package/dist/generate-SW6IGE4J.cjs.map +0 -1
- package/src/utils/OraWritable.ts +0 -22
- package/src/utils/spinner.ts +0 -5
- package/src/utils/writeLog.ts +0 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/cli",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.11",
|
|
4
4
|
"description": "Generator cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -18,9 +18,6 @@
|
|
|
18
18
|
"author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"type": "module",
|
|
21
|
-
"main": "dist/index.cjs",
|
|
22
|
-
"module": "dist/index.js",
|
|
23
|
-
"types": "./dist/index.d.ts",
|
|
24
21
|
"exports": {
|
|
25
22
|
".": {
|
|
26
23
|
"import": "./dist/index.js",
|
|
@@ -28,9 +25,12 @@
|
|
|
28
25
|
"default": "./dist/index.cjs"
|
|
29
26
|
}
|
|
30
27
|
},
|
|
28
|
+
"main": "dist/index.cjs",
|
|
29
|
+
"module": "dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
31
|
"bin": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"bkubb": "bin/bkubb.cjs",
|
|
33
|
+
"kubb": "bin/kubb.cjs"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"src",
|
|
@@ -43,28 +43,30 @@
|
|
|
43
43
|
"bundle-require": "^5.0.0",
|
|
44
44
|
"chokidar": "^3.6.0",
|
|
45
45
|
"citty": "^0.1.6",
|
|
46
|
+
"cli-progress": "^3.12.0",
|
|
46
47
|
"consola": "^3.2.3",
|
|
47
48
|
"cosmiconfig": "^9.0.0",
|
|
48
49
|
"esbuild": "^0.23.1",
|
|
49
50
|
"execa": "^9.3.1",
|
|
50
51
|
"js-runtime": "^0.0.8",
|
|
51
52
|
"latest-version": "^9.0.0",
|
|
52
|
-
"
|
|
53
|
+
"p-queue": "^8.0.1",
|
|
53
54
|
"semver": "^7.6.3",
|
|
54
55
|
"string-argv": "^0.3.2",
|
|
55
56
|
"tinyrainbow": "^1.2.0",
|
|
56
|
-
"@kubb/core": "3.0.0-alpha.
|
|
57
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
57
|
+
"@kubb/core": "3.0.0-alpha.11",
|
|
58
|
+
"@kubb/fs": "3.0.0-alpha.11"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@types/
|
|
61
|
+
"@types/cli-progress": "^3.11.6",
|
|
62
|
+
"@types/node": "^20.16.2",
|
|
61
63
|
"@types/semver": "^7.5.8",
|
|
62
64
|
"source-map-support": "^0.5.21",
|
|
63
65
|
"tsup": "^8.2.4",
|
|
64
66
|
"typescript": "^5.5.4",
|
|
65
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
66
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
67
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
67
|
+
"@kubb/config-ts": "3.0.0-alpha.11",
|
|
68
|
+
"@kubb/config-tsup": "3.0.0-alpha.11",
|
|
69
|
+
"@kubb/plugin-oas": "3.0.0-alpha.11"
|
|
68
70
|
},
|
|
69
71
|
"engines": {
|
|
70
72
|
"node": ">=20"
|
package/src/commands/generate.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { LogLevel } from '@kubb/core/logger'
|
|
2
1
|
import { defineCommand, showUsage } from 'citty'
|
|
3
2
|
import type { ArgsDef, ParsedArgs } from 'citty'
|
|
4
3
|
import { execa } from 'execa'
|
|
5
4
|
import c from 'tinyrainbow'
|
|
6
5
|
|
|
7
|
-
import path from 'node:path'
|
|
8
6
|
import { getConfig } from '../utils/getConfig.ts'
|
|
9
7
|
import { getCosmiConfig } from '../utils/getCosmiConfig.ts'
|
|
10
|
-
import { spinner } from '../utils/spinner.ts'
|
|
11
8
|
import { startWatcher } from '../utils/watcher.ts'
|
|
12
9
|
|
|
10
|
+
import path from 'node:path'
|
|
13
11
|
import { PromiseManager, isInputPath } from '@kubb/core'
|
|
12
|
+
import { LogMapper, createLogger } from '@kubb/core/logger'
|
|
14
13
|
import { generate } from '../generate.ts'
|
|
15
14
|
|
|
16
15
|
const args = {
|
|
@@ -23,8 +22,8 @@ const args = {
|
|
|
23
22
|
type: 'string',
|
|
24
23
|
description: 'Info, silent or debug',
|
|
25
24
|
alias: 'l',
|
|
26
|
-
default:
|
|
27
|
-
valueHint:
|
|
25
|
+
default: 'info',
|
|
26
|
+
valueHint: 'silent|info|debug',
|
|
28
27
|
},
|
|
29
28
|
watch: {
|
|
30
29
|
type: 'boolean',
|
|
@@ -60,9 +59,6 @@ const command = defineCommand({
|
|
|
60
59
|
description: "[input] Generate files based on a 'kubb.config.ts' file",
|
|
61
60
|
},
|
|
62
61
|
args,
|
|
63
|
-
setup() {
|
|
64
|
-
spinner.start('🔍 Loading config')
|
|
65
|
-
},
|
|
66
62
|
async run({ args }) {
|
|
67
63
|
const input = args._[0]
|
|
68
64
|
|
|
@@ -72,7 +68,7 @@ const command = defineCommand({
|
|
|
72
68
|
}
|
|
73
69
|
|
|
74
70
|
if (args.debug) {
|
|
75
|
-
args.logLevel =
|
|
71
|
+
args.logLevel = 'debug'
|
|
76
72
|
}
|
|
77
73
|
|
|
78
74
|
if (args.bun) {
|
|
@@ -82,8 +78,15 @@ const command = defineCommand({
|
|
|
82
78
|
return
|
|
83
79
|
}
|
|
84
80
|
|
|
81
|
+
const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3
|
|
82
|
+
const logger = createLogger({
|
|
83
|
+
logLevel,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
logger.emit('start', 'Loading config')
|
|
87
|
+
|
|
85
88
|
const result = await getCosmiConfig('kubb', args.config)
|
|
86
|
-
|
|
89
|
+
logger.emit('success', `Config loaded(${c.dim(path.relative(process.cwd(), result.filepath))})`)
|
|
87
90
|
|
|
88
91
|
const config = await getConfig(result, args)
|
|
89
92
|
|
|
@@ -94,9 +97,8 @@ const command = defineCommand({
|
|
|
94
97
|
|
|
95
98
|
if (isInputPath(config)) {
|
|
96
99
|
return startWatcher([input || config.input.path], async (paths) => {
|
|
97
|
-
await generate({ config, args })
|
|
98
|
-
|
|
99
|
-
spinner.start(c.yellow(c.bold(`Watching for changes in ${paths.join(' and ')}`)))
|
|
100
|
+
await generate({ config, args, input })
|
|
101
|
+
logger.emit('start', c.yellow(c.bold(`Watching for changes in ${paths.join(' and ')}`)))
|
|
100
102
|
})
|
|
101
103
|
}
|
|
102
104
|
}
|
package/src/generate.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogMapper } from '@kubb/core/logger'
|
|
2
2
|
|
|
3
3
|
import c from 'tinyrainbow'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { type Config, Warning, safeBuild } from '@kubb/core'
|
|
8
|
-
import { createConsola } from 'consola'
|
|
9
|
-
import type { Args } from './commands/generate.ts'
|
|
5
|
+
import { type Config, safeBuild } from '@kubb/core'
|
|
10
6
|
import { executeHooks } from './utils/executeHooks.ts'
|
|
11
7
|
import { getErrorCauses } from './utils/getErrorCauses.ts'
|
|
12
8
|
import { getSummary } from './utils/getSummary.ts'
|
|
13
|
-
|
|
9
|
+
|
|
10
|
+
import { Presets, SingleBar } from 'cli-progress'
|
|
11
|
+
import type { Args } from './commands/generate.ts'
|
|
12
|
+
import { createLogger } from '@kubb/core/logger'
|
|
14
13
|
|
|
15
14
|
type GenerateProps = {
|
|
16
15
|
input?: string
|
|
@@ -19,48 +18,49 @@ type GenerateProps = {
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
export async function generate({ input, config, args }: GenerateProps): Promise<void> {
|
|
22
|
-
const logLevel =
|
|
21
|
+
const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3
|
|
23
22
|
const logger = createLogger({
|
|
24
23
|
logLevel,
|
|
25
24
|
name: config.name,
|
|
26
|
-
spinner,
|
|
27
|
-
consola: createConsola({
|
|
28
|
-
level: LogMapper[logLevel] || 3,
|
|
29
|
-
}),
|
|
30
25
|
})
|
|
26
|
+
const { root = process.cwd(), ...userConfig } = config
|
|
27
|
+
const inputPath = input ?? ('path' in userConfig.input ? userConfig.input.path : undefined)
|
|
31
28
|
|
|
32
|
-
logger.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
29
|
+
if (logger.logLevel !== LogMapper.debug) {
|
|
30
|
+
const progressCache = new Map<string, SingleBar>()
|
|
31
|
+
|
|
32
|
+
logger.on('progress_start', ({ id, size, message = '' }) => {
|
|
33
|
+
logger.consola?.pauseLogs()
|
|
34
|
+
const payload = { id, message }
|
|
35
|
+
const progressBar = new SingleBar(
|
|
36
|
+
{
|
|
37
|
+
format: '{percentage}% {bar} {value}/{total} | {message}',
|
|
38
|
+
barsize: 30,
|
|
39
|
+
clearOnComplete: true,
|
|
40
|
+
emptyOnZero: true,
|
|
41
|
+
},
|
|
42
|
+
Presets.shades_grey,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
if (!progressCache.has(id)) {
|
|
46
|
+
progressCache.set(id, progressBar)
|
|
47
|
+
progressBar.start(size, 1, payload)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
logger.on('progress_stop', ({ id }) => {
|
|
52
|
+
progressCache.get(id)?.stop()
|
|
53
|
+
logger.consola?.resumeLogs()
|
|
54
|
+
})
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
logger.on('progressed', ({ id, message = '' }) => {
|
|
57
|
+
const payload = { id, message }
|
|
53
58
|
|
|
54
|
-
|
|
59
|
+
progressCache.get(id)?.increment(1, payload)
|
|
55
60
|
})
|
|
56
|
-
|
|
57
|
-
performanceOpserver.observe({ type: 'measure' })
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
const inputPath = input ?? ('path' in userConfig.input ? userConfig.input.path : undefined)
|
|
62
|
-
|
|
63
|
-
spinner.start(`🚀 Building ${logLevel !== 'silent' ? c.dim(inputPath) : ''}`)
|
|
63
|
+
logger.emit('start', `Building ${logger.logLevel !== LogMapper.silent ? c.dim(inputPath) : ''}`)
|
|
64
64
|
|
|
65
65
|
const definedConfig: Config = {
|
|
66
66
|
root,
|
|
@@ -73,37 +73,50 @@ export async function generate({ input, config, args }: GenerateProps): Promise<
|
|
|
73
73
|
: userConfig.input,
|
|
74
74
|
output: {
|
|
75
75
|
write: true,
|
|
76
|
+
exportType: 'barrelNamed',
|
|
76
77
|
...userConfig.output,
|
|
77
78
|
},
|
|
78
79
|
}
|
|
79
|
-
const
|
|
80
|
+
const hrStart = process.hrtime()
|
|
81
|
+
const { pluginManager, files, error } = await safeBuild({
|
|
80
82
|
config: definedConfig,
|
|
81
83
|
logger,
|
|
82
84
|
})
|
|
83
85
|
|
|
86
|
+
if (logger.logLevel === LogMapper.debug) {
|
|
87
|
+
logger.consola?.start('Writing logs')
|
|
88
|
+
|
|
89
|
+
const logFiles = await logger.writeLogs()
|
|
90
|
+
|
|
91
|
+
logger.consola?.success(`Written logs: \n${logFiles.join('\n')}`)
|
|
92
|
+
}
|
|
93
|
+
|
|
84
94
|
const summary = getSummary({
|
|
95
|
+
filesCreated: files.length,
|
|
85
96
|
pluginManager,
|
|
86
97
|
config: definedConfig,
|
|
87
98
|
status: error ? 'failed' : 'success',
|
|
88
|
-
|
|
89
|
-
logger,
|
|
99
|
+
hrStart,
|
|
90
100
|
})
|
|
91
101
|
|
|
92
|
-
if (error) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
if (error && logger.consola) {
|
|
103
|
+
logger.consola?.resumeLogs()
|
|
104
|
+
logger.consola.error(`Build failed ${logger.logLevel !== LogMapper.silent ? c.dim(inputPath) : ''}`)
|
|
105
|
+
|
|
106
|
+
logger.consola.box({
|
|
107
|
+
title: `${config.name || ''}`,
|
|
108
|
+
message: summary.join(''),
|
|
109
|
+
style: {
|
|
110
|
+
padding: 2,
|
|
111
|
+
borderColor: 'red',
|
|
112
|
+
borderStyle: 'rounded',
|
|
113
|
+
},
|
|
114
|
+
})
|
|
102
115
|
|
|
103
116
|
const errors = getErrorCauses([error])
|
|
104
|
-
if (logger.consola && errors.length && logLevel ===
|
|
117
|
+
if (logger.consola && errors.length && logger.logLevel === LogMapper.debug) {
|
|
105
118
|
errors.forEach((err) => {
|
|
106
|
-
logger.consola
|
|
119
|
+
logger.consola?.error(err)
|
|
107
120
|
})
|
|
108
121
|
}
|
|
109
122
|
|
|
@@ -112,10 +125,19 @@ export async function generate({ input, config, args }: GenerateProps): Promise<
|
|
|
112
125
|
process.exit(0)
|
|
113
126
|
}
|
|
114
127
|
|
|
115
|
-
|
|
128
|
+
if (config.hooks) {
|
|
129
|
+
await executeHooks({ hooks: config.hooks, logger })
|
|
130
|
+
}
|
|
116
131
|
|
|
117
|
-
|
|
118
|
-
spinner.succeed(`🚀 Build completed ${logLevel !== 'silent' ? c.dim(inputPath) : ''}`)
|
|
132
|
+
logger.consola?.log(`⚡Build completed ${logger.logLevel !== LogMapper.silent ? c.dim(inputPath) : ''}`)
|
|
119
133
|
|
|
120
|
-
|
|
134
|
+
logger.consola?.box({
|
|
135
|
+
title: `${config.name || ''}`,
|
|
136
|
+
message: summary.join(''),
|
|
137
|
+
style: {
|
|
138
|
+
padding: 2,
|
|
139
|
+
borderColor: 'green',
|
|
140
|
+
borderStyle: 'rounded',
|
|
141
|
+
},
|
|
142
|
+
})
|
|
121
143
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { defineCommand, runCommand, runMain } from 'citty'
|
|
|
2
2
|
import getLatestVersion from 'latest-version'
|
|
3
3
|
import { lt } from 'semver'
|
|
4
4
|
|
|
5
|
-
import consola from 'consola'
|
|
6
5
|
import { version } from '../package.json'
|
|
6
|
+
import consola from 'consola'
|
|
7
7
|
|
|
8
8
|
const name = 'kubb'
|
|
9
9
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Writable } from 'node:stream'
|
|
2
|
+
|
|
3
|
+
import c from 'tinyrainbow'
|
|
4
|
+
|
|
5
|
+
import * as process from 'node:process'
|
|
6
|
+
import type { WritableOptions } from 'node:stream'
|
|
7
|
+
import type { ConsolaInstance } from 'consola'
|
|
8
|
+
|
|
9
|
+
export class ConsolaWritable extends Writable {
|
|
10
|
+
consola: ConsolaInstance | undefined
|
|
11
|
+
command: string
|
|
12
|
+
constructor(consola: ConsolaInstance | undefined, command: string, opts?: WritableOptions) {
|
|
13
|
+
super(opts)
|
|
14
|
+
|
|
15
|
+
this.command = command
|
|
16
|
+
this.consola = consola
|
|
17
|
+
}
|
|
18
|
+
_write(chunk: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
|
19
|
+
process.stdout.write(`${c.dim(chunk?.toString())}`)
|
|
20
|
+
|
|
21
|
+
callback()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,65 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Logger } from '@kubb/core/logger'
|
|
2
2
|
import { execa } from 'execa'
|
|
3
3
|
import { parseArgsStringToArgv } from 'string-argv'
|
|
4
4
|
import c from 'tinyrainbow'
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import { spinner } from './spinner.ts'
|
|
6
|
+
import { ConsolaWritable } from './Writables.ts'
|
|
8
7
|
|
|
9
|
-
import type { Writable } from 'node:stream'
|
|
10
8
|
import type { Config } from '@kubb/core'
|
|
9
|
+
import { LogMapper } from '@kubb/core/logger'
|
|
10
|
+
import PQueue from 'p-queue'
|
|
11
11
|
|
|
12
12
|
type ExecutingHooksProps = {
|
|
13
|
-
hooks: Config['hooks']
|
|
14
|
-
|
|
13
|
+
hooks: NonNullable<Config['hooks']>
|
|
14
|
+
logger: Logger
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export async function executeHooks({ hooks,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
17
|
+
export async function executeHooks({ hooks, logger }: ExecutingHooksProps): Promise<void> {
|
|
18
|
+
const commands = Array.isArray(hooks.done) ? hooks.done : [hooks.done].filter(Boolean)
|
|
19
|
+
const queue = new PQueue({ concurrency: 1 })
|
|
21
20
|
|
|
22
|
-
const
|
|
21
|
+
const promises = commands.map(async (command) => {
|
|
22
|
+
const consolaWritable = new ConsolaWritable(logger.consola!, command)
|
|
23
|
+
const [cmd, ..._args] = [...parseArgsStringToArgv(command)]
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (!cmd) {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const oraWritable = new OraWritable(spinner, command)
|
|
31
|
-
const abortController = new AbortController()
|
|
32
|
-
const [cmd, ..._args] = [...parseArgsStringToArgv(command)]
|
|
29
|
+
await queue.add(async () => {
|
|
30
|
+
logger?.emit('start', `Executing hook ${logger.logLevel !== LogMapper.silent ? c.dim(command) : ''}`)
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
return null
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
spinner.start(`Executing hook ${logLevel !== 'silent' ? c.dim(command) : ''}`)
|
|
39
|
-
|
|
40
|
-
const subProcess = await execa(cmd, _args, {
|
|
32
|
+
await execa(cmd, _args, {
|
|
41
33
|
detached: true,
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
stdout: logger?.logLevel === LogMapper.silent ? undefined : ['pipe', consolaWritable],
|
|
35
|
+
stripFinalNewline: true,
|
|
44
36
|
})
|
|
45
|
-
spinner.suffixText = ''
|
|
46
|
-
|
|
47
|
-
if (logLevel === LogLevel.silent) {
|
|
48
|
-
spinner.succeed(`Executing hook ${logLevel !== 'silent' ? c.dim(command) : ''}`)
|
|
49
|
-
|
|
50
|
-
if (subProcess) {
|
|
51
|
-
console.log(subProcess.stdout)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
37
|
|
|
55
|
-
|
|
56
|
-
return { subProcess, abort: abortController.abort.bind(abortController) }
|
|
38
|
+
logger?.emit('success', `Executed hook ${logger.logLevel !== LogMapper.silent ? c.dim(command) : ''}`)
|
|
57
39
|
})
|
|
58
|
-
|
|
40
|
+
})
|
|
59
41
|
|
|
60
|
-
await Promise.all(
|
|
42
|
+
await Promise.all(promises)
|
|
61
43
|
|
|
62
|
-
|
|
63
|
-
spinner.succeed('Executing hooks')
|
|
64
|
-
}
|
|
44
|
+
logger?.emit('success', 'Executed hooks')
|
|
65
45
|
}
|
package/src/utils/getPlugins.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { PackageManager } from '@kubb/core'
|
|
2
|
-
|
|
3
1
|
import type { UserConfig } from '@kubb/core'
|
|
4
2
|
|
|
5
3
|
function isJSONPlugins(plugins: UserConfig['plugins']) {
|
|
@@ -12,14 +10,6 @@ function isObjectPlugins(plugins: UserConfig['plugins']): plugins is any {
|
|
|
12
10
|
return plugins instanceof Object && !Array.isArray(plugins)
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
async function importPlugin(name: string, options: object): Promise<UserConfig['plugins']> {
|
|
16
|
-
const packageManager = new PackageManager(process.cwd())
|
|
17
|
-
|
|
18
|
-
const importedPlugin: any = process.env.NODE_ENV === 'test' ? await import(name) : await packageManager.import(name)
|
|
19
|
-
|
|
20
|
-
return importedPlugin?.default ? importedPlugin.default(options) : importedPlugin(options)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
13
|
export function getPlugins(plugins: UserConfig['plugins']): Promise<UserConfig['plugins']> {
|
|
24
14
|
if (isObjectPlugins(plugins)) {
|
|
25
15
|
throw new Error('Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')
|
package/src/utils/getSummary.ts
CHANGED
|
@@ -7,20 +7,18 @@ import c from 'tinyrainbow'
|
|
|
7
7
|
import { parseHrtimeToSeconds } from './parseHrtimeToSeconds.ts'
|
|
8
8
|
|
|
9
9
|
import type { Config, PluginManager } from '@kubb/core'
|
|
10
|
-
import type { Logger } from '@kubb/core/logger'
|
|
11
10
|
|
|
12
11
|
type SummaryProps = {
|
|
13
12
|
pluginManager: PluginManager
|
|
14
13
|
status: 'success' | 'failed'
|
|
15
|
-
|
|
14
|
+
hrStart: [number, number]
|
|
15
|
+
filesCreated: number
|
|
16
16
|
config: Config
|
|
17
|
-
logger: Logger
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
export function getSummary({ pluginManager, status,
|
|
21
|
-
const { logLevel } = logger
|
|
19
|
+
export function getSummary({ pluginManager, filesCreated, status, hrStart, config }: SummaryProps): string[] {
|
|
22
20
|
const logs: string[] = []
|
|
23
|
-
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(
|
|
21
|
+
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrStart))
|
|
24
22
|
|
|
25
23
|
const buildStartPlugins = pluginManager.executed
|
|
26
24
|
.filter((item) => item.hookName === 'buildStart' && item.plugin.name !== 'core')
|
|
@@ -30,48 +28,24 @@ export function getSummary({ pluginManager, status, hrstart, config, logger }: S
|
|
|
30
28
|
|
|
31
29
|
const failedPlugins = config.plugins?.filter((plugin) => !buildEndPlugins.includes(plugin.name))?.map((plugin) => plugin.name)
|
|
32
30
|
const pluginsCount = config.plugins?.length || 0
|
|
33
|
-
const files = pluginManager.fileManager.files.sort((a, b) => {
|
|
34
|
-
if (!a.meta?.pluginKey?.[0] || !b.meta?.pluginKey?.[0]) {
|
|
35
|
-
return 0
|
|
36
|
-
}
|
|
37
|
-
if (a.meta?.pluginKey?.[0]?.length < b.meta?.pluginKey?.[0]?.length) {
|
|
38
|
-
return 1
|
|
39
|
-
}
|
|
40
|
-
if (a.meta?.pluginKey?.[0]?.length > b.meta?.pluginKey?.[0]?.length) {
|
|
41
|
-
return -1
|
|
42
|
-
}
|
|
43
|
-
return 0
|
|
44
|
-
})
|
|
45
31
|
|
|
46
32
|
const meta = {
|
|
47
|
-
name: config.name,
|
|
48
33
|
plugins:
|
|
49
34
|
status === 'success'
|
|
50
35
|
? `${c.green(`${buildStartPlugins.length} successful`)}, ${pluginsCount} total`
|
|
51
36
|
: `${c.red(`${failedPlugins?.length ?? 1} failed`)}, ${pluginsCount} total`,
|
|
52
37
|
pluginsFailed: status === 'failed' ? failedPlugins?.map((name) => randomCliColour(name))?.join(', ') : undefined,
|
|
53
|
-
filesCreated:
|
|
54
|
-
time: c.yellow(`${elapsedSeconds}s`)
|
|
55
|
-
endTime: c.yellow(Date()),
|
|
38
|
+
filesCreated: filesCreated,
|
|
39
|
+
time: `${c.yellow(`${elapsedSeconds}s`)}`,
|
|
56
40
|
output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root,
|
|
57
41
|
} as const
|
|
58
42
|
|
|
59
|
-
logger.emit('debug', ['\nGenerated files:\n'])
|
|
60
|
-
logger.emit(
|
|
61
|
-
'debug',
|
|
62
|
-
files.map((file) => `${randomCliColour(JSON.stringify(file.meta?.pluginKey))} ${file.path}`),
|
|
63
|
-
)
|
|
64
|
-
|
|
65
43
|
logs.push(
|
|
66
44
|
[
|
|
67
|
-
['
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[`${c.bold('Generated:')} ${meta.filesCreated} files`, true],
|
|
72
|
-
[` ${c.bold('Time:')} ${meta.time}`, true],
|
|
73
|
-
[` ${c.bold('Ended:')} ${meta.endTime}`, true],
|
|
74
|
-
[` ${c.bold('Output:')} ${meta.output}`, true],
|
|
45
|
+
[`${c.bold('Plugins:')} ${meta.plugins}`, true],
|
|
46
|
+
[`${c.dim('Failed:')} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],
|
|
47
|
+
[`${c.bold('Generated:')} ${meta.filesCreated} files in ${meta.time}`, true],
|
|
48
|
+
[`${c.bold('Output:')} ${meta.output}`, true],
|
|
75
49
|
]
|
|
76
50
|
.map((item) => {
|
|
77
51
|
if (item.at(1)) {
|
package/src/utils/watcher.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import c from 'tinyrainbow'
|
|
2
|
-
|
|
3
|
-
import { spinner } from './spinner.ts'
|
|
2
|
+
import { createLogger } from '@kubb/core/logger'
|
|
4
3
|
|
|
5
4
|
export async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {
|
|
6
5
|
const { watch } = await import('chokidar')
|
|
6
|
+
const logger = createLogger()
|
|
7
7
|
|
|
8
8
|
const ignored = ['**/{.git,node_modules}/**']
|
|
9
9
|
|
|
@@ -12,14 +12,12 @@ export async function startWatcher(path: string[], cb: (path: string[]) => Promi
|
|
|
12
12
|
ignored,
|
|
13
13
|
})
|
|
14
14
|
watcher.on('all', (type, file) => {
|
|
15
|
-
|
|
16
|
-
// revert back
|
|
17
|
-
spinner.spinner = 'clock'
|
|
15
|
+
logger?.emit('info', c.yellow(c.bold(`Change detected: ${type} ${file}`)))
|
|
18
16
|
|
|
19
17
|
try {
|
|
20
18
|
cb(path)
|
|
21
19
|
} catch (e) {
|
|
22
|
-
|
|
20
|
+
logger?.emit('warning', c.red('Watcher failed'))
|
|
23
21
|
}
|
|
24
22
|
})
|
|
25
23
|
|