@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.
Files changed (48) hide show
  1. package/dist/Queue-2-6pMcCx.d.cts +32 -0
  2. package/dist/Queue-2-6pMcCx.d.ts +32 -0
  3. package/dist/fs.cjs +2383 -0
  4. package/dist/fs.cjs.map +1 -0
  5. package/dist/fs.d.cts +5 -0
  6. package/dist/fs.d.ts +5 -0
  7. package/dist/fs.js +2380 -0
  8. package/dist/fs.js.map +1 -0
  9. package/dist/index.cjs +3336 -191
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +18 -69
  12. package/dist/index.d.ts +18 -69
  13. package/dist/index.js +3655 -226
  14. package/dist/index.js.map +1 -1
  15. package/dist/logger.cjs +148 -0
  16. package/dist/logger.cjs.map +1 -0
  17. package/dist/logger.d.cts +31 -0
  18. package/dist/logger.d.ts +31 -0
  19. package/dist/logger.js +140 -0
  20. package/dist/logger.js.map +1 -0
  21. package/dist/transformers.cjs +79 -9
  22. package/dist/transformers.cjs.map +1 -1
  23. package/dist/transformers.js +82 -8
  24. package/dist/transformers.js.map +1 -1
  25. package/dist/utils.cjs +86 -766
  26. package/dist/utils.cjs.map +1 -1
  27. package/dist/utils.d.cts +3 -595
  28. package/dist/utils.d.ts +3 -595
  29. package/dist/utils.js +87 -727
  30. package/dist/utils.js.map +1 -1
  31. package/dist/write-46ytbnu9.d.cts +7 -0
  32. package/dist/write-46ytbnu9.d.ts +7 -0
  33. package/package.json +21 -11
  34. package/src/FileManager.ts +34 -62
  35. package/src/PluginManager.ts +20 -15
  36. package/src/build.ts +11 -12
  37. package/src/fs/index.ts +3 -0
  38. package/src/index.ts +4 -4
  39. package/src/{utils/logger.ts → logger.ts} +38 -3
  40. package/src/plugin.ts +1 -1
  41. package/src/transformers/casing.ts +3 -3
  42. package/src/types.ts +1 -1
  43. package/src/utils/index.ts +10 -18
  44. package/src/utils/randomColour.ts +0 -39
  45. package/src/utils/throttle.ts +0 -30
  46. /package/src/{utils → fs}/clean.ts +0 -0
  47. /package/src/{utils → fs}/read.ts +0 -0
  48. /package/src/{utils → fs}/write.ts +0 -0
package/src/build.ts CHANGED
@@ -1,18 +1,17 @@
1
- import pc from 'picocolors'
1
+ import c from 'tinyrainbow'
2
2
 
3
- import { clean } from './utils/clean.ts'
4
- import { createLogger, LogLevel } from './utils/logger.ts'
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 ' + pc.dim(config.input.path),
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 ${pc.dim(JSON.stringify(plugin.key))} \nwith source\n\n${code}`)
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 = `${randomPicoColour(plugin.name)} Executing ${hookName}`
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 = pc.dim(path)
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 && `${pc.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
141
+ parameters && `${c.bgWhite(`Parameters`)} ${randomCliColour(plugin.name)} ${hookName}`,
143
142
  JSON.stringify(parameters, undefined, 2),
144
- output && `${pc.bgWhite('Output')} ${randomPicoColour(plugin.name)} ${hookName}`,
143
+ output && `${c.bgWhite('Output')} ${randomCliColour(plugin.name)} ${hookName}`,
145
144
  output,
146
145
  ].filter(Boolean)
147
146
 
@@ -0,0 +1,3 @@
1
+ export { clean } from './clean.ts'
2
+ export { getRelativePath, read, readSync } from './read.ts'
3
+ export { write } from './write.ts'
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 * from './config.ts'
7
- export * from './errors.ts'
8
- export * from './FileManager.ts'
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 pc from 'picocolors'
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(pc.yellow(message))
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
- export { default as pc } from 'picocolors'
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
@@ -21,7 +21,7 @@ type Options = {
21
21
  resolvePath: PluginContext['resolvePath']
22
22
  resolveName: PluginContext['resolveName']
23
23
  logger: PluginContext['logger']
24
- getPlugins: () => KubbPlugin[]
24
+ getPlugins: () => Array<KubbPlugin>
25
25
  plugin?: PluginContext['plugin']
26
26
  }
27
27
 
@@ -1,9 +1,9 @@
1
- import { camelCase as changeCaseCamel, camelCaseTransformMerge, pascalCase as changePascalCase, pascalCaseTransformMerge } from 'change-case'
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: '', stripRegexp: /[^A-Z0-9$]/gi, transform: camelCaseTransformMerge })
4
+ return changeCaseCamel(text, { delimiter: '', mergeAmbiguousCharacters: true })
5
5
  }
6
6
 
7
7
  export function pascalCase(text: string): string {
8
- return changePascalCase(text, { delimiter: '', stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge })
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
 
@@ -1,18 +1,10 @@
1
- export * from './cache.ts'
2
- export * from './cache.ts'
3
- export * from './clean.ts'
4
- export * from './FunctionParams.ts'
5
- export * from './FunctionParams.ts'
6
- export * from './logger.ts'
7
- export * from './promise.ts'
8
- export * from './Queue.ts'
9
- export * from './Queue.ts'
10
- export * from './randomColour.ts'
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
- }
@@ -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