@kubb/cli 1.15.0-canary.20231112T135054 → 2.0.0-alpha.10
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/README.md +1 -1
- package/bin/kubb.js +2 -2
- package/dist/index.cjs +148 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +133 -128
- package/dist/index.js.map +1 -1
- package/package.json +16 -8
- package/src/generate.ts +137 -0
- package/src/index.ts +96 -0
- package/src/init.ts +94 -0
- package/src/utils/OraWritable.ts +27 -0
- package/src/utils/getConfig.ts +37 -0
- package/src/utils/getCosmiConfig.ts +82 -0
- package/src/utils/getPlugins.ts +41 -0
- package/src/utils/getSummary.ts +84 -0
- package/src/utils/parseHrtimeToSeconds.ts +4 -0
- package/src/utils/renderErrors.ts +55 -0
- package/src/utils/spinner.ts +5 -0
- package/src/utils/watcher.ts +27 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
4
|
+
|
|
5
|
+
import { LogLevel } from '@kubb/core/utils'
|
|
6
|
+
|
|
7
|
+
import PrettyError from 'pretty-error'
|
|
8
|
+
|
|
9
|
+
export const prettyError = new PrettyError()
|
|
10
|
+
.skipPackage('commander')
|
|
11
|
+
.skip(function callback(traceLine: any) {
|
|
12
|
+
// exclude renderErrors.ts
|
|
13
|
+
const pattern = new RegExp('renderErrors')
|
|
14
|
+
|
|
15
|
+
const hasMatch = traceLine?.file?.match(pattern)
|
|
16
|
+
|
|
17
|
+
if (typeof traceLine.packageName !== 'undefined' && hasMatch) {
|
|
18
|
+
return true
|
|
19
|
+
}
|
|
20
|
+
} as PrettyError.Callback)
|
|
21
|
+
.start()
|
|
22
|
+
|
|
23
|
+
function getErrorCauses(errors: Error[]): string[] {
|
|
24
|
+
return errors
|
|
25
|
+
.reduce((prev, error) => {
|
|
26
|
+
const causedError = error?.cause as Error
|
|
27
|
+
if (causedError) {
|
|
28
|
+
prev = [...prev, ...getErrorCauses([causedError])]
|
|
29
|
+
}
|
|
30
|
+
prev = [...prev, prettyError.render(error)]
|
|
31
|
+
|
|
32
|
+
return prev
|
|
33
|
+
}, [] as string[])
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function renderErrors(error: Error | undefined, { logLevel = LogLevel.silent }: { logLevel?: LogLevel }): string {
|
|
38
|
+
if (!error) {
|
|
39
|
+
return ''
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (logLevel === LogLevel.silent) {
|
|
43
|
+
// skip when no debug is set
|
|
44
|
+
prettyError.skipNodeFiles()
|
|
45
|
+
prettyError.skip(function skip() {
|
|
46
|
+
return true
|
|
47
|
+
} as PrettyError.Callback)
|
|
48
|
+
|
|
49
|
+
return [prettyError.render(error)].filter(Boolean).join('\n')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const errors = getErrorCauses([error])
|
|
53
|
+
|
|
54
|
+
return errors.filter(Boolean).join('\n')
|
|
55
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import pc from 'picocolors'
|
|
2
|
+
|
|
3
|
+
import { spinner } from './spinner.ts'
|
|
4
|
+
|
|
5
|
+
export async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {
|
|
6
|
+
const { watch } = await import('chokidar')
|
|
7
|
+
|
|
8
|
+
const ignored = ['**/{.git,node_modules}/**']
|
|
9
|
+
|
|
10
|
+
const watcher = watch(path, {
|
|
11
|
+
ignorePermissionErrors: true,
|
|
12
|
+
ignored,
|
|
13
|
+
})
|
|
14
|
+
watcher.on('all', (type, file) => {
|
|
15
|
+
spinner.succeed(pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))
|
|
16
|
+
// revert back
|
|
17
|
+
spinner.spinner = 'clock'
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
cb(path)
|
|
21
|
+
} catch (e) {
|
|
22
|
+
spinner.warn(pc.red('Watcher failed'))
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
return
|
|
27
|
+
}
|