@kubb/core 2.0.0-beta.10 → 2.0.0-beta.12
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/Queue-2-6pMcCx.d.cts +32 -0
- package/dist/Queue-2-6pMcCx.d.ts +32 -0
- package/dist/fs.cjs +2383 -0
- package/dist/fs.cjs.map +1 -0
- package/dist/fs.d.cts +5 -0
- package/dist/fs.d.ts +5 -0
- package/dist/fs.js +2380 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.cjs +3336 -191
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -69
- package/dist/index.d.ts +18 -69
- package/dist/index.js +3655 -226
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +148 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +31 -0
- package/dist/logger.d.ts +31 -0
- package/dist/logger.js +140 -0
- package/dist/logger.js.map +1 -0
- package/dist/transformers.cjs +79 -9
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.js +82 -8
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +86 -766
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +3 -595
- package/dist/utils.d.ts +3 -595
- package/dist/utils.js +87 -727
- package/dist/utils.js.map +1 -1
- package/dist/write-46ytbnu9.d.cts +7 -0
- package/dist/write-46ytbnu9.d.ts +7 -0
- package/package.json +21 -11
- package/src/FileManager.ts +34 -62
- package/src/PluginManager.ts +20 -15
- package/src/build.ts +11 -12
- package/src/fs/index.ts +3 -0
- package/src/index.ts +4 -4
- package/src/{utils/logger.ts → logger.ts} +38 -3
- package/src/plugin.ts +1 -1
- package/src/transformers/casing.ts +3 -3
- package/src/types.ts +1 -1
- package/src/utils/index.ts +10 -18
- package/src/utils/randomColour.ts +0 -39
- package/src/utils/throttle.ts +0 -30
- /package/src/{utils → fs}/clean.ts +0 -0
- /package/src/{utils → fs}/read.ts +0 -0
- /package/src/{utils → fs}/write.ts +0 -0
package/src/build.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import c from 'tinyrainbow'
|
|
2
2
|
|
|
3
|
-
import { clean } from './
|
|
4
|
-
import {
|
|
5
|
-
import { randomPicoColour } from './utils/randomColour.ts'
|
|
6
|
-
import { read } from './utils/read.ts'
|
|
3
|
+
import { clean } from './fs/clean.ts'
|
|
4
|
+
import { read } from './fs/read.ts'
|
|
7
5
|
import { URLPath } from './utils/URLPath.ts'
|
|
8
6
|
import { isInputPath } from './config.ts'
|
|
9
7
|
import { FileManager } from './FileManager.ts'
|
|
8
|
+
import { createLogger, LogLevel, randomCliColour } from './logger.ts'
|
|
10
9
|
import { PluginManager } from './PluginManager.ts'
|
|
11
10
|
import { isPromise } from './PromiseManager.ts'
|
|
12
11
|
|
|
13
12
|
import type { KubbFile } from './FileManager.ts'
|
|
13
|
+
import type { Logger } from './logger.ts'
|
|
14
14
|
import type { KubbPlugin, PluginContext, PluginParameter, TransformResult } from './types.ts'
|
|
15
|
-
import type { Logger } from './utils/logger.ts'
|
|
16
15
|
import type { QueueJob } from './utils/Queue.ts'
|
|
17
16
|
|
|
18
17
|
type BuildOptions = {
|
|
@@ -51,7 +50,7 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
|
|
|
51
50
|
} catch (e) {
|
|
52
51
|
if (isInputPath(config)) {
|
|
53
52
|
throw new Error(
|
|
54
|
-
'Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config ' +
|
|
53
|
+
'Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config ' + c.dim(config.input.path),
|
|
55
54
|
{
|
|
56
55
|
cause: e,
|
|
57
56
|
},
|
|
@@ -117,20 +116,20 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
|
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
if (logger.logLevel === LogLevel.debug) {
|
|
120
|
-
logger.info(`PluginKey ${
|
|
119
|
+
logger.info(`PluginKey ${c.dim(JSON.stringify(plugin.key))} \nwith source\n\n${code}`)
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
122
|
})
|
|
124
123
|
|
|
125
124
|
pluginManager.on('executed', (executer) => {
|
|
126
125
|
const { hookName, plugin, output, parameters } = executer
|
|
127
|
-
const messsage = `${
|
|
126
|
+
const messsage = `${randomCliColour(plugin.name)} Executing ${hookName}`
|
|
128
127
|
|
|
129
128
|
if (logger.logLevel === LogLevel.info && logger.spinner) {
|
|
130
129
|
if (hookName === 'writeFile') {
|
|
131
130
|
const [_code, path] = parameters as PluginParameter<'writeFile'>
|
|
132
131
|
|
|
133
|
-
logger.spinner.suffixText =
|
|
132
|
+
logger.spinner.suffixText = c.dim(path)
|
|
134
133
|
} else {
|
|
135
134
|
logger.spinner.suffixText = messsage
|
|
136
135
|
}
|
|
@@ -139,9 +138,9 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
|
|
|
139
138
|
if (logger.logLevel === LogLevel.debug) {
|
|
140
139
|
logger.info(messsage)
|
|
141
140
|
const logs = [
|
|
142
|
-
parameters && `${
|
|
141
|
+
parameters && `${c.bgWhite(`Parameters`)} ${randomCliColour(plugin.name)} ${hookName}`,
|
|
143
142
|
JSON.stringify(parameters, undefined, 2),
|
|
144
|
-
output && `${
|
|
143
|
+
output && `${c.bgWhite('Output')} ${randomCliColour(plugin.name)} ${hookName}`,
|
|
145
144
|
output,
|
|
146
145
|
].filter(Boolean)
|
|
147
146
|
|
package/src/fs/index.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -3,16 +3,16 @@ import { build } from './build.ts'
|
|
|
3
3
|
import type { ObjValueTuple, TupleToUnion } from '@kubb/types'
|
|
4
4
|
|
|
5
5
|
export { build, safeBuild } from './build.ts'
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
6
|
+
export { defineConfig, isInputPath } from './config.ts'
|
|
7
|
+
export { Warning } from './errors.ts'
|
|
8
|
+
export { FileManager, KubbFile } from './FileManager.ts'
|
|
9
9
|
export { Generator } from './Generator.ts'
|
|
10
10
|
export { PackageManager } from './PackageManager.ts'
|
|
11
11
|
// dprint-ignore
|
|
12
12
|
export { createPlugin, pluginName as name, pluginName } from './plugin.ts'
|
|
13
13
|
export { PluginManager } from './PluginManager.ts'
|
|
14
14
|
export { PromiseManager } from './PromiseManager.ts'
|
|
15
|
-
export * from './types.ts'
|
|
15
|
+
export type * from './types.ts'
|
|
16
16
|
|
|
17
17
|
export interface _Register {}
|
|
18
18
|
export type Plugins = _Register
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import seedrandom from 'seedrandom'
|
|
2
|
+
import c, { createColors } from 'tinyrainbow'
|
|
2
3
|
|
|
3
4
|
import type { Ora } from 'ora'
|
|
5
|
+
import type { Formatter } from 'tinyrainbow'
|
|
4
6
|
|
|
5
7
|
export const LogLevel = {
|
|
6
8
|
silent: 'silent',
|
|
@@ -47,7 +49,7 @@ export function createLogger({ logLevel, name, spinner }: Props): Logger {
|
|
|
47
49
|
|
|
48
50
|
const warn: Logger['warn'] = (message) => {
|
|
49
51
|
if (message && spinner) {
|
|
50
|
-
spinner.warn(
|
|
52
|
+
spinner.warn(c.yellow(message))
|
|
51
53
|
logs.push(message)
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -73,4 +75,37 @@ export function createLogger({ logLevel, name, spinner }: Props): Logger {
|
|
|
73
75
|
return logger
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
const defaultColours = ['black', 'blue', 'darkBlue', 'cyan', 'gray', 'green', 'darkGreen', 'magenta', 'red', 'darkRed', 'yellow', 'darkYellow'] as const
|
|
79
|
+
|
|
80
|
+
export function randomColour(text?: string, colours = defaultColours): string {
|
|
81
|
+
if (!text) {
|
|
82
|
+
return 'white'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const random = seedrandom(text)
|
|
86
|
+
const colour = colours.at(Math.floor(random() * colours.length)) || 'white'
|
|
87
|
+
|
|
88
|
+
return colour
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function randomCliColour(text?: string, colors = defaultColours): string {
|
|
92
|
+
const colours = createColors(true)
|
|
93
|
+
|
|
94
|
+
if (!text) {
|
|
95
|
+
return colours.white(text)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const colour = randomColour(text, colors)
|
|
99
|
+
const isDark = colour.includes('dark')
|
|
100
|
+
const key = colour.replace('dark', '').toLowerCase() as keyof typeof colours
|
|
101
|
+
const formatter: Formatter = colours[key] as Formatter
|
|
102
|
+
|
|
103
|
+
if (isDark) {
|
|
104
|
+
return c.bold(formatter(text))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (typeof formatter !== 'function') {
|
|
108
|
+
throw new Error('Formatter for picoColor is not of type function/Formatter')
|
|
109
|
+
}
|
|
110
|
+
return formatter(text)
|
|
111
|
+
}
|
package/src/plugin.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { camelCase as changeCaseCamel,
|
|
1
|
+
import { camelCase as changeCaseCamel, pascalCase as changePascalCase } from 'change-case'
|
|
2
2
|
|
|
3
3
|
export function camelCase(text: string): string {
|
|
4
|
-
return changeCaseCamel(text, { delimiter: '',
|
|
4
|
+
return changeCaseCamel(text, { delimiter: '', mergeAmbiguousCharacters: true })
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export function pascalCase(text: string): string {
|
|
8
|
-
return changePascalCase(text, { delimiter: '',
|
|
8
|
+
return changePascalCase(text, { delimiter: '', mergeAmbiguousCharacters: true })
|
|
9
9
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { PossiblePromise } from '@kubb/types'
|
|
2
2
|
import type { FileManager, KubbFile } from './FileManager.ts'
|
|
3
3
|
import type { OptionsPlugins, PluginUnion } from './index.ts'
|
|
4
|
+
import type { Logger, LogLevel } from './logger.ts'
|
|
4
5
|
import type { PluginManager } from './PluginManager.ts'
|
|
5
6
|
import type { Cache } from './utils/cache.ts'
|
|
6
|
-
import type { Logger, LogLevel } from './utils/logger.ts'
|
|
7
7
|
|
|
8
8
|
// config
|
|
9
9
|
|
package/src/utils/index.ts
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export * from './read.ts'
|
|
12
|
-
export * from './renderTemplate.ts'
|
|
13
|
-
export * from './throttle.ts'
|
|
14
|
-
export * from './timeout.ts'
|
|
15
|
-
export * from './TreeNode.ts'
|
|
16
|
-
export * from './uniqueName.ts'
|
|
17
|
-
export * from './URLPath.ts'
|
|
18
|
-
export * from './write.ts'
|
|
1
|
+
export type { FunctionParamsAST } from './FunctionParams.ts'
|
|
2
|
+
export { FunctionParams } from './FunctionParams.ts'
|
|
3
|
+
export { isPromise, isPromiseFulfilledResult, isPromiseRejectedResult } from './promise.ts'
|
|
4
|
+
export type { QueueJob } from './Queue.ts'
|
|
5
|
+
export { Queue } from './Queue.ts'
|
|
6
|
+
export { renderTemplate } from './renderTemplate.ts'
|
|
7
|
+
export { timeout } from './timeout.ts'
|
|
8
|
+
export { getUniqueName, setUniqueName } from './uniqueName.ts'
|
|
9
|
+
export type { URLObject } from './URLPath.ts'
|
|
10
|
+
export { URLPath } from './URLPath.ts'
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import pc from 'picocolors'
|
|
2
|
-
import seedrandom from 'seedrandom'
|
|
3
|
-
|
|
4
|
-
import type { Formatter } from 'picocolors/types.ts'
|
|
5
|
-
|
|
6
|
-
const defaultColours = ['black', 'blue', 'darkBlue', 'cyan', 'gray', 'green', 'darkGreen', 'magenta', 'red', 'darkRed', 'yellow', 'darkYellow'] as const
|
|
7
|
-
|
|
8
|
-
export function randomColour(text?: string, colours = defaultColours): string {
|
|
9
|
-
if (!text) {
|
|
10
|
-
return 'white'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const random = seedrandom(text)
|
|
14
|
-
const colour = colours.at(Math.floor(random() * colours.length)) || 'white'
|
|
15
|
-
|
|
16
|
-
return colour
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function randomPicoColour(text?: string, colors = defaultColours): string {
|
|
20
|
-
const colours = pc.createColors(true)
|
|
21
|
-
|
|
22
|
-
if (!text) {
|
|
23
|
-
return colours.white(text)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const colour = randomColour(text, colors)
|
|
27
|
-
const isDark = colour.includes('dark')
|
|
28
|
-
const key = colour.replace('dark', '').toLowerCase() as keyof typeof colours
|
|
29
|
-
const formatter: Formatter = colours[key] as Formatter
|
|
30
|
-
|
|
31
|
-
if (isDark) {
|
|
32
|
-
return pc.bold(formatter(text))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (typeof formatter !== 'function') {
|
|
36
|
-
throw new Error('Formatter for picoColor is not of type function/Formatter')
|
|
37
|
-
}
|
|
38
|
-
return formatter(text)
|
|
39
|
-
}
|
package/src/utils/throttle.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const throttle = <R, A extends any[]>(fn: (...args: A) => R, delay: number): [(...args: A) => R | undefined, () => void] => {
|
|
2
|
-
let wait = false
|
|
3
|
-
let timeout: NodeJS.Timeout
|
|
4
|
-
let cancelled = false
|
|
5
|
-
|
|
6
|
-
return [
|
|
7
|
-
(...args: A) => {
|
|
8
|
-
if (cancelled) {
|
|
9
|
-
return undefined
|
|
10
|
-
}
|
|
11
|
-
if (wait) {
|
|
12
|
-
return undefined
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const val = fn(...args)
|
|
16
|
-
|
|
17
|
-
wait = true
|
|
18
|
-
|
|
19
|
-
timeout = setTimeout(() => {
|
|
20
|
-
wait = false
|
|
21
|
-
}, delay)
|
|
22
|
-
|
|
23
|
-
return val
|
|
24
|
-
},
|
|
25
|
-
() => {
|
|
26
|
-
cancelled = true
|
|
27
|
-
clearTimeout(timeout)
|
|
28
|
-
},
|
|
29
|
-
]
|
|
30
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|