@kubb/cli 4.11.2 → 4.12.0

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 (52) hide show
  1. package/dist/generate-BujndwJK.cjs +1256 -0
  2. package/dist/generate-BujndwJK.cjs.map +1 -0
  3. package/dist/generate-BvrG5K00.js +1249 -0
  4. package/dist/generate-BvrG5K00.js.map +1 -0
  5. package/dist/index.cjs +9 -35
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +7 -30
  8. package/dist/index.js.map +1 -1
  9. package/dist/{mcp-BIRDY8xn.js → mcp-LLlOFV3c.js} +5 -6
  10. package/dist/mcp-LLlOFV3c.js.map +1 -0
  11. package/dist/{mcp-BQjDRDXR.cjs → mcp-N1IVyiXf.cjs} +5 -7
  12. package/dist/mcp-N1IVyiXf.cjs.map +1 -0
  13. package/dist/package-Bhc6C7cQ.js +6 -0
  14. package/dist/package-Bhc6C7cQ.js.map +1 -0
  15. package/dist/package-KuCpJxHt.cjs +12 -0
  16. package/dist/package-KuCpJxHt.cjs.map +1 -0
  17. package/dist/{validate-0i6Q9eIy.js → validate-BptoQ-63.js} +5 -6
  18. package/dist/validate-BptoQ-63.js.map +1 -0
  19. package/dist/{validate-6F-VPZR7.cjs → validate-Dn6hZ7Z4.cjs} +5 -7
  20. package/dist/validate-Dn6hZ7Z4.cjs.map +1 -0
  21. package/package.json +7 -7
  22. package/src/commands/generate.ts +52 -65
  23. package/src/commands/mcp.ts +4 -5
  24. package/src/commands/validate.ts +4 -5
  25. package/src/index.ts +8 -23
  26. package/src/loggers/clackLogger.ts +433 -0
  27. package/src/loggers/envDetection.ts +28 -0
  28. package/src/loggers/fileSystemLogger.ts +79 -0
  29. package/src/loggers/githubActionsLogger.ts +310 -0
  30. package/src/loggers/index.ts +7 -0
  31. package/src/loggers/plainLogger.ts +274 -0
  32. package/src/loggers/types.ts +1 -0
  33. package/src/loggers/utils.ts +49 -0
  34. package/src/runners/generate.ts +196 -208
  35. package/src/utils/Writables.ts +12 -8
  36. package/src/utils/executeHooks.ts +11 -18
  37. package/src/utils/getCosmiConfig.ts +6 -1
  38. package/src/utils/getSummary.ts +20 -42
  39. package/src/utils/randomColour.ts +26 -0
  40. package/src/utils/watcher.ts +2 -4
  41. package/dist/generate-CYBFB3tU.js +0 -221
  42. package/dist/generate-CYBFB3tU.js.map +0 -1
  43. package/dist/generate-CpBJ2Y-n.js +0 -342
  44. package/dist/generate-CpBJ2Y-n.js.map +0 -1
  45. package/dist/generate-DpHvARzf.cjs +0 -345
  46. package/dist/generate-DpHvARzf.cjs.map +0 -1
  47. package/dist/generate-KUqCSnZp.cjs +0 -225
  48. package/dist/generate-KUqCSnZp.cjs.map +0 -1
  49. package/dist/mcp-BIRDY8xn.js.map +0 -1
  50. package/dist/mcp-BQjDRDXR.cjs.map +0 -1
  51. package/dist/validate-0i6Q9eIy.js.map +0 -1
  52. package/dist/validate-6F-VPZR7.cjs.map +0 -1
@@ -1,8 +1,8 @@
1
1
  import path from 'node:path'
2
2
  import type { Config, Plugin } from '@kubb/core'
3
- import { randomCliColour } from '@kubb/core/logger'
4
3
  import pc from 'picocolors'
5
4
  import { parseHrtimeToSeconds } from './parseHrtimeToSeconds.ts'
5
+ import { randomCliColour } from './randomColour.ts'
6
6
 
7
7
  type SummaryProps = {
8
8
  failedPlugins: Set<{ plugin: Plugin; error: Error }>
@@ -14,7 +14,6 @@ type SummaryProps = {
14
14
  }
15
15
 
16
16
  export function getSummary({ failedPlugins, filesCreated, status, hrStart, config, pluginTimings }: SummaryProps): string[] {
17
- const logs = new Set<string>()
18
17
  const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(hrStart))
19
18
 
20
19
  const pluginsCount = config.plugins?.length || 0
@@ -27,69 +26,48 @@ export function getSummary({ failedPlugins, filesCreated, status, hrStart, confi
27
26
  : `${pc.green(`${successCount} successful`)}, ${pc.red(`${failedPlugins.size} failed`)}, ${pluginsCount} total`,
28
27
  pluginsFailed: status === 'failed' ? [...failedPlugins]?.map(({ plugin }) => randomCliColour(plugin.name))?.join(', ') : undefined,
29
28
  filesCreated: filesCreated,
30
- time: `${pc.yellow(`${elapsedSeconds}s`)}`,
29
+ time: `${elapsedSeconds}s`,
31
30
  output: path.isAbsolute(config.root) ? path.resolve(config.root, config.output.path) : config.root,
32
31
  } as const
33
32
 
34
- // Calculate label padding for perfect alignment
35
33
  const labels = {
36
34
  plugins: 'Plugins:',
37
35
  failed: 'Failed:',
38
36
  generated: 'Generated:',
37
+ pluginTimings: 'Plugin Timings:',
39
38
  output: 'Output:',
40
39
  }
41
- const maxLabelLength = Math.max(...Object.values(labels).map((l) => l.length))
40
+ const maxLength = Math.max(0, ...[...Object.values(labels), ...(pluginTimings ? Array.from(pluginTimings.keys()) : [])].map((s) => s.length))
42
41
 
43
- const summaryLines: Array<[string, boolean]> = [
44
- [`${pc.bold(labels.plugins.padEnd(maxLabelLength))} ${meta.plugins}`, true],
45
- [`${pc.dim(labels.failed.padEnd(maxLabelLength))} ${meta.pluginsFailed || 'none'}`, !!meta.pluginsFailed],
46
- [`${pc.bold(labels.generated.padEnd(maxLabelLength))} ${meta.filesCreated} files in ${meta.time}`, true],
47
- ]
42
+ const summaryLines: string[] = []
43
+ summaryLines.push(`${labels.plugins.padEnd(maxLength + 2)} ${meta.plugins}`)
48
44
 
49
- // Add plugin timing breakdown if available
50
- if (pluginTimings && pluginTimings.size > 0) {
51
- const MAX_TOP_PLUGINS = 5
52
- const TIME_SCALE_DIVISOR = 100 // Each 100ms = 1 bar character
53
- const MAX_BAR_LENGTH = 20
45
+ if (meta.pluginsFailed) {
46
+ summaryLines.push(`${labels.failed.padEnd(maxLength + 2)} ${meta.pluginsFailed}`)
47
+ }
54
48
 
55
- const sortedTimings = Array.from(pluginTimings.entries())
56
- .sort((a, b) => b[1] - a[1])
57
- .slice(0, MAX_TOP_PLUGINS)
49
+ summaryLines.push(`${labels.generated.padEnd(maxLength + 2)} ${meta.filesCreated} files in ${meta.time}`)
58
50
 
59
- if (sortedTimings.length > 0) {
60
- summaryLines.push(['Plugin Timings:', true])
51
+ if (pluginTimings && pluginTimings.size > 0) {
52
+ const TIME_SCALE_DIVISOR = 100
53
+ const MAX_BAR_LENGTH = 10
61
54
 
62
- // Find the longest plugin name for alignment
63
- const maxNameLength = Math.max(...sortedTimings.map(([name]) => name.length))
55
+ const sortedTimings = Array.from(pluginTimings.entries()).sort((a, b) => b[1] - a[1])
64
56
 
65
- // Indent plugin timing bars to align with summary values (e.g., "7 successful", "60 files")
66
- const indent = ' '.repeat(maxLabelLength + 1)
57
+ if (sortedTimings.length > 0) {
58
+ summaryLines.push(`${labels.pluginTimings}`)
67
59
 
68
60
  sortedTimings.forEach(([name, time]) => {
69
61
  const timeStr = time >= 1000 ? `${(time / 1000).toFixed(2)}s` : `${Math.round(time)}ms`
70
62
  const barLength = Math.min(Math.ceil(time / TIME_SCALE_DIVISOR), MAX_BAR_LENGTH)
71
- const bar = '█'.repeat(barLength)
63
+ const bar = pc.dim('█'.repeat(barLength))
72
64
 
73
- // Right-align plugin names, left-align bars, with consistent spacing
74
- const paddedName = name.padStart(maxNameLength, ' ')
75
- summaryLines.push([`${indent}${randomCliColour(paddedName)} ${pc.dim(bar)} ${pc.yellow(timeStr)}`, true])
65
+ summaryLines.push(`${pc.dim('•')} ${name.padEnd(maxLength + 1)}${bar} ${timeStr}`)
76
66
  })
77
67
  }
78
68
  }
79
69
 
80
- summaryLines.push([`${pc.bold(labels.output.padEnd(maxLabelLength))} ${meta.output}`, true])
81
-
82
- logs.add(
83
- summaryLines
84
- .map((item) => {
85
- if (item.at(1)) {
86
- return item.at(0)
87
- }
88
- return undefined
89
- })
90
- .filter(Boolean)
91
- .join('\n'),
92
- )
70
+ summaryLines.push(`${labels.output.padEnd(maxLength + 2)} ${meta.output}`)
93
71
 
94
- return [...logs]
72
+ return summaryLines
95
73
  }
@@ -0,0 +1,26 @@
1
+ import pc from 'picocolors'
2
+ import seedrandom from 'seedrandom'
3
+
4
+ export function randomColour(text?: string): 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' {
5
+ if (!text) {
6
+ return 'white'
7
+ }
8
+
9
+ const defaultColours = ['black', 'red', 'green', 'yellow', 'blue', 'red', 'green', 'magenta', 'cyan', 'gray'] as const
10
+
11
+ const random = seedrandom(text)
12
+ const colour = defaultColours.at(Math.floor(random() * defaultColours.length)) || 'white'
13
+
14
+ return colour
15
+ }
16
+
17
+ export function randomCliColour(text?: string): string {
18
+ if (!text) {
19
+ return ''
20
+ }
21
+
22
+ const colour = randomColour(text)
23
+
24
+ const fn = pc[colour]
25
+ return fn ? fn(text) : text
26
+ }
@@ -1,9 +1,7 @@
1
- import { createLogger } from '@kubb/core/logger'
2
1
  import pc from 'picocolors'
3
2
 
4
3
  export async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {
5
4
  const { watch } = await import('chokidar')
6
- const logger = createLogger()
7
5
 
8
6
  const ignored = '**/{.git,node_modules}/**'
9
7
 
@@ -12,12 +10,12 @@ export async function startWatcher(path: string[], cb: (path: string[]) => Promi
12
10
  ignored,
13
11
  })
14
12
  watcher.on('all', (type, file) => {
15
- logger?.emit('info', pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))
13
+ console.log(pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))
16
14
 
17
15
  try {
18
16
  cb(path)
19
17
  } catch (_e) {
20
- logger?.emit('warning', pc.red('Watcher failed'))
18
+ console.log(pc.red('Watcher failed'))
21
19
  }
22
20
  })
23
21
  }
@@ -1,221 +0,0 @@
1
- import { defineCommand, showUsage } from "citty";
2
- import path from "node:path";
3
- import * as process$1 from "node:process";
4
- import { PromiseManager, isInputPath } from "@kubb/core";
5
- import { LogMapper, createLogger } from "@kubb/core/logger";
6
- import pc from "picocolors";
7
- import { isPromise } from "@kubb/core/utils";
8
- import { cosmiconfig } from "cosmiconfig";
9
- import { createJiti } from "jiti";
10
-
11
- //#region src/utils/getPlugins.ts
12
- function isJSONPlugins(plugins) {
13
- return !!plugins?.some((plugin) => {
14
- return Array.isArray(plugin) && typeof plugin?.at(0) === "string";
15
- });
16
- }
17
- function isObjectPlugins(plugins) {
18
- return plugins instanceof Object && !Array.isArray(plugins);
19
- }
20
- function getPlugins(plugins) {
21
- if (isObjectPlugins(plugins)) throw new Error("Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
22
- if (isJSONPlugins(plugins)) throw new Error("JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
23
- return Promise.resolve(plugins);
24
- }
25
-
26
- //#endregion
27
- //#region src/utils/getConfig.ts
28
- /**
29
- * Converting UserConfig to Config without a change in the object beside the JSON convert.
30
- */
31
- async function getConfig(result, args) {
32
- const config = result?.config;
33
- let kubbUserConfig = Promise.resolve(config);
34
- if (typeof config === "function") {
35
- const possiblePromise = config(args);
36
- if (isPromise(possiblePromise)) kubbUserConfig = possiblePromise;
37
- kubbUserConfig = Promise.resolve(possiblePromise);
38
- }
39
- let JSONConfig = await kubbUserConfig;
40
- if (Array.isArray(JSONConfig)) {
41
- const results = [];
42
- for (const item of JSONConfig) {
43
- const plugins = item.plugins ? await getPlugins(item.plugins) : void 0;
44
- results.push({
45
- ...item,
46
- plugins
47
- });
48
- }
49
- return results;
50
- }
51
- JSONConfig = {
52
- ...JSONConfig,
53
- plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
54
- };
55
- return JSONConfig;
56
- }
57
-
58
- //#endregion
59
- //#region src/utils/getCosmiConfig.ts
60
- const tsLoader = async (configFile) => {
61
- return await createJiti(import.meta.url, {
62
- jsx: {
63
- runtime: "automatic",
64
- importSource: "@kubb/react-fabric"
65
- },
66
- sourceMaps: true
67
- }).import(configFile, { default: true });
68
- };
69
- async function getCosmiConfig(moduleName, config) {
70
- const searchPlaces = [
71
- "package.json",
72
- `.${moduleName}rc`,
73
- `.${moduleName}rc.json`,
74
- `.${moduleName}rc.yaml`,
75
- `.${moduleName}rc.yml`,
76
- `.${moduleName}rc.ts`,
77
- `.${moduleName}rc.js`,
78
- `.${moduleName}rc.mjs`,
79
- `.${moduleName}rc.cjs`,
80
- `${moduleName}.config.ts`,
81
- `${moduleName}.config.js`,
82
- `${moduleName}.config.mjs`,
83
- `${moduleName}.config.cjs`
84
- ];
85
- const explorer = cosmiconfig(moduleName, {
86
- cache: false,
87
- searchPlaces: [
88
- ...searchPlaces.map((searchPlace) => {
89
- return `.config/${searchPlace}`;
90
- }),
91
- ...searchPlaces.map((searchPlace) => {
92
- return `configs/${searchPlace}`;
93
- }),
94
- ...searchPlaces
95
- ],
96
- loaders: { ".ts": tsLoader }
97
- });
98
- const result = config ? await explorer.load(config) : await explorer.search();
99
- if (result?.isEmpty || !result || !result.config) throw new Error("Config not defined, create a kubb.config.js or pass through your config with the option --config");
100
- return result;
101
- }
102
-
103
- //#endregion
104
- //#region src/utils/watcher.ts
105
- async function startWatcher(path$1, cb) {
106
- const { watch } = await import("chokidar");
107
- const logger = createLogger();
108
- watch(path$1, {
109
- ignorePermissionErrors: true,
110
- ignored: "**/{.git,node_modules}/**"
111
- }).on("all", (type, file) => {
112
- logger?.emit("info", pc.yellow(pc.bold(`Change detected: ${type} ${file}`)));
113
- try {
114
- cb(path$1);
115
- } catch (_e) {
116
- logger?.emit("warning", pc.red("Watcher failed"));
117
- }
118
- });
119
- }
120
-
121
- //#endregion
122
- //#region src/commands/generate.ts
123
- const command = defineCommand({
124
- meta: {
125
- name: "generate",
126
- description: "[input] Generate files based on a 'kubb.config.ts' file"
127
- },
128
- args: {
129
- config: {
130
- type: "string",
131
- description: "Path to the Kubb config",
132
- alias: "c"
133
- },
134
- logLevel: {
135
- type: "string",
136
- description: "Info, silent, verbose or debug",
137
- alias: "l",
138
- default: "info",
139
- valueHint: "silent|info|verbose|debug"
140
- },
141
- watch: {
142
- type: "boolean",
143
- description: "Watch mode based on the input file",
144
- alias: "w",
145
- default: false
146
- },
147
- debug: {
148
- type: "boolean",
149
- description: "Override logLevel to debug",
150
- alias: "d",
151
- default: false
152
- },
153
- verbose: {
154
- type: "boolean",
155
- description: "Override logLevel to verbose",
156
- alias: "v",
157
- default: false
158
- },
159
- help: {
160
- type: "boolean",
161
- description: "Show help",
162
- alias: "h",
163
- default: false
164
- }
165
- },
166
- async run(commandContext) {
167
- const progressCache = /* @__PURE__ */ new Map();
168
- const { args } = commandContext;
169
- const input = args._[0];
170
- if (args.help) return showUsage(command);
171
- if (args.debug) args.logLevel = "debug";
172
- if (args.verbose) args.logLevel = "verbose";
173
- const logger = createLogger({ logLevel: LogMapper[args.logLevel] || 3 });
174
- const { generate } = await import("./generate-CpBJ2Y-n.js");
175
- logger.emit("start", "Loading config");
176
- const result = await getCosmiConfig("kubb", args.config);
177
- logger.emit("success", `Config loaded(${pc.dim(path.relative(process$1.cwd(), result.filepath))})`);
178
- const config = await getConfig(result, args);
179
- const start = async () => {
180
- if (Array.isArray(config)) {
181
- const promiseManager = new PromiseManager();
182
- const promises = config.map((c) => () => {
183
- progressCache.clear();
184
- return generate({
185
- input,
186
- config: c,
187
- args,
188
- progressCache
189
- });
190
- });
191
- await promiseManager.run("seq", promises);
192
- return;
193
- }
194
- progressCache.clear();
195
- await generate({
196
- input,
197
- config,
198
- progressCache,
199
- args
200
- });
201
- };
202
- if (args.watch) {
203
- if (Array.isArray(config)) throw new Error("Cannot use watcher with multiple Configs(array)");
204
- if (isInputPath(config)) return startWatcher([input || config.input.path], async (paths) => {
205
- await start();
206
- logger.emit("start", pc.yellow(pc.bold(`Watching for changes in ${paths.join(" and ")}`)));
207
- });
208
- }
209
- await start();
210
- if (globalThis.isDevtoolsEnabled) if (await logger.consola?.prompt("Restart(could be used to validate the profiler)?", {
211
- type: "confirm",
212
- initial: false
213
- })) await start();
214
- else process$1.exit(1);
215
- }
216
- });
217
- var generate_default = command;
218
-
219
- //#endregion
220
- export { generate_default as default };
221
- //# sourceMappingURL=generate-CYBFB3tU.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-CYBFB3tU.js","names":["results: Array<Config>","path","process"],"sources":["../src/utils/getPlugins.ts","../src/utils/getConfig.ts","../src/utils/getCosmiConfig.ts","../src/utils/watcher.ts","../src/commands/generate.ts"],"sourcesContent":["import type { UserConfig } from '@kubb/core'\n\nfunction isJSONPlugins(plugins: UserConfig['plugins']) {\n return !!(plugins as any)?.some((plugin: any) => {\n return Array.isArray(plugin) && typeof plugin?.at(0) === 'string'\n })\n}\n\nfunction isObjectPlugins(plugins: UserConfig['plugins']): plugins is any {\n return plugins instanceof Object && !Array.isArray(plugins)\n}\n\nexport function getPlugins(plugins: UserConfig['plugins']): Promise<UserConfig['plugins']> {\n if (isObjectPlugins(plugins)) {\n throw new Error('Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')\n }\n\n if (isJSONPlugins(plugins)) {\n throw new Error('JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json')\n }\n\n return Promise.resolve(plugins)\n}\n","import type { CLIOptions, Config, UserConfig } from '@kubb/core'\nimport { isPromise } from '@kubb/core/utils'\nimport type { Args } from '../commands/generate.ts'\nimport type { CosmiconfigResult } from './getCosmiConfig.ts'\nimport { getPlugins } from './getPlugins.ts'\n\n/**\n * Converting UserConfig to Config without a change in the object beside the JSON convert.\n */\nexport async function getConfig(result: CosmiconfigResult, args: Args): Promise<Array<Config> | Config> {\n const config = result?.config\n let kubbUserConfig = Promise.resolve(config) as Promise<UserConfig | Array<UserConfig>>\n\n // for ts or js files\n if (typeof config === 'function') {\n const possiblePromise = config(args as CLIOptions)\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise\n }\n kubbUserConfig = Promise.resolve(possiblePromise)\n }\n\n let JSONConfig = await kubbUserConfig\n\n if (Array.isArray(JSONConfig)) {\n const results: Array<Config> = []\n\n for (const item of JSONConfig) {\n const plugins = item.plugins ? await getPlugins(item.plugins) : undefined\n\n results.push({\n ...item,\n plugins,\n } as Config)\n }\n\n return results\n }\n\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : undefined,\n }\n\n return JSONConfig as Config\n}\n","import type { defineConfig, UserConfig } from '@kubb/core'\nimport { cosmiconfig } from 'cosmiconfig'\nimport { createJiti } from 'jiti'\n\nexport type CosmiconfigResult = {\n filepath: string\n isEmpty?: boolean\n config: ReturnType<typeof defineConfig> | UserConfig\n}\n\nconst tsLoader = async (configFile: string) => {\n const jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: 'automatic',\n importSource: '@kubb/react-fabric',\n },\n sourceMaps: true,\n })\n\n const mod = await jiti.import(configFile, { default: true })\n\n return mod\n}\n\nexport async function getCosmiConfig(moduleName: string, config?: string): Promise<CosmiconfigResult> {\n const searchPlaces = [\n 'package.json',\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n `.${moduleName}rc.yaml`,\n `.${moduleName}rc.yml`,\n\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.js`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n\n `${moduleName}.config.ts`,\n `${moduleName}.config.js`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ]\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n ...searchPlaces.map((searchPlace) => {\n return `.config/${searchPlace}`\n }),\n ...searchPlaces.map((searchPlace) => {\n return `configs/${searchPlace}`\n }),\n ...searchPlaces,\n ],\n loaders: {\n '.ts': tsLoader,\n },\n })\n\n const result = config ? await explorer.load(config) : await explorer.search()\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error('Config not defined, create a kubb.config.js or pass through your config with the option --config')\n }\n\n return result as CosmiconfigResult\n}\n","import { createLogger } from '@kubb/core/logger'\nimport pc from 'picocolors'\n\nexport async function startWatcher(path: string[], cb: (path: string[]) => Promise<void>): Promise<void> {\n const { watch } = await import('chokidar')\n const logger = createLogger()\n\n const ignored = '**/{.git,node_modules}/**'\n\n const watcher = watch(path, {\n ignorePermissionErrors: true,\n ignored,\n })\n watcher.on('all', (type, file) => {\n logger?.emit('info', pc.yellow(pc.bold(`Change detected: ${type} ${file}`)))\n\n try {\n cb(path)\n } catch (_e) {\n logger?.emit('warning', pc.red('Watcher failed'))\n }\n })\n}\n","import path from 'node:path'\nimport * as process from 'node:process'\nimport { isInputPath, PromiseManager } from '@kubb/core'\nimport { createLogger, LogMapper } from '@kubb/core/logger'\nimport type { ArgsDef, ParsedArgs } from 'citty'\nimport { defineCommand, showUsage } from 'citty'\nimport type { SingleBar } from 'cli-progress'\nimport pc from 'picocolors'\nimport { getConfig } from '../utils/getConfig.ts'\nimport { getCosmiConfig } from '../utils/getCosmiConfig.ts'\nimport { startWatcher } from '../utils/watcher.ts'\n\ndeclare global {\n var isDevtoolsEnabled: any\n}\n\nconst args = {\n config: {\n type: 'string',\n description: 'Path to the Kubb config',\n alias: 'c',\n },\n logLevel: {\n type: 'string',\n description: 'Info, silent, verbose or debug',\n alias: 'l',\n default: 'info',\n valueHint: 'silent|info|verbose|debug',\n },\n watch: {\n type: 'boolean',\n description: 'Watch mode based on the input file',\n alias: 'w',\n default: false,\n },\n debug: {\n type: 'boolean',\n description: 'Override logLevel to debug',\n alias: 'd',\n default: false,\n },\n verbose: {\n type: 'boolean',\n description: 'Override logLevel to verbose',\n alias: 'v',\n default: false,\n },\n help: {\n type: 'boolean',\n description: 'Show help',\n alias: 'h',\n default: false,\n },\n} as const satisfies ArgsDef\n\nexport type Args = ParsedArgs<typeof args>\n\nconst command = defineCommand({\n meta: {\n name: 'generate',\n description: \"[input] Generate files based on a 'kubb.config.ts' file\",\n },\n args,\n async run(commandContext) {\n const progressCache = new Map<string, SingleBar>()\n\n const { args } = commandContext\n\n const input = args._[0]\n\n if (args.help) {\n return showUsage(command)\n }\n\n if (args.debug) {\n args.logLevel = 'debug'\n }\n\n if (args.verbose) {\n args.logLevel = 'verbose'\n }\n\n const logLevel = LogMapper[args.logLevel as keyof typeof LogMapper] || 3\n const logger = createLogger({\n logLevel,\n })\n const { generate } = await import('../runners/generate.ts')\n\n logger.emit('start', 'Loading config')\n\n const result = await getCosmiConfig('kubb', args.config)\n logger.emit('success', `Config loaded(${pc.dim(path.relative(process.cwd(), result.filepath))})`)\n\n const config = await getConfig(result, args)\n\n const start = async () => {\n if (Array.isArray(config)) {\n const promiseManager = new PromiseManager()\n const promises = config.map((c) => () => {\n progressCache.clear()\n\n return generate({\n input,\n config: c,\n args,\n progressCache,\n })\n })\n\n await promiseManager.run('seq', promises)\n return\n }\n\n progressCache.clear()\n\n await generate({\n input,\n config,\n progressCache,\n args,\n })\n\n return\n }\n\n if (args.watch) {\n if (Array.isArray(config)) {\n throw new Error('Cannot use watcher with multiple Configs(array)')\n }\n\n if (isInputPath(config)) {\n return startWatcher([input || config.input.path], async (paths) => {\n await start()\n logger.emit('start', pc.yellow(pc.bold(`Watching for changes in ${paths.join(' and ')}`)))\n })\n }\n }\n\n await start()\n\n if (globalThis.isDevtoolsEnabled) {\n const canRestart = await logger.consola?.prompt('Restart(could be used to validate the profiler)?', {\n type: 'confirm',\n initial: false,\n })\n\n if (canRestart) {\n await start()\n } else {\n process.exit(1)\n }\n }\n },\n})\n\nexport default command\n"],"mappings":";;;;;;;;;;;AAEA,SAAS,cAAc,SAAgC;AACrD,QAAO,CAAC,CAAE,SAAiB,MAAM,WAAgB;AAC/C,SAAO,MAAM,QAAQ,OAAO,IAAI,OAAO,QAAQ,GAAG,EAAE,KAAK;GACzD;;AAGJ,SAAS,gBAAgB,SAAgD;AACvE,QAAO,mBAAmB,UAAU,CAAC,MAAM,QAAQ,QAAQ;;AAG7D,SAAgB,WAAW,SAAgE;AACzF,KAAI,gBAAgB,QAAQ,CAC1B,OAAM,IAAI,MAAM,uGAAuG;AAGzH,KAAI,cAAc,QAAQ,CACxB,OAAM,IAAI,MAAM,qGAAqG;AAGvH,QAAO,QAAQ,QAAQ,QAAQ;;;;;;;;ACZjC,eAAsB,UAAU,QAA2B,MAA6C;CACtG,MAAM,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