@kubb/cli 3.18.2 → 4.0.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.
- package/dist/{generate-CKnWsDnu.cjs → generate-BALD2C5T.cjs} +84 -92
- package/dist/generate-BALD2C5T.cjs.map +1 -0
- package/dist/{generate-Bu9WyH1N.cjs → generate-CBoWFhG2.cjs} +84 -83
- package/dist/generate-CBoWFhG2.cjs.map +1 -0
- package/dist/{generate-jMDBjxTU.js → generate-CFatuxgj.js} +64 -73
- package/dist/generate-CFatuxgj.js.map +1 -0
- package/dist/{generate-DvSF6lmv.js → generate-vHDmA5Mm.js} +44 -72
- package/dist/generate-vHDmA5Mm.js.map +1 -0
- package/dist/index.cjs +16 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/{mcp-DcaOAt6B.js → mcp-C4KjGtQv.js} +9 -10
- package/dist/mcp-C4KjGtQv.js.map +1 -0
- package/dist/{mcp-Cmiw4RpU.cjs → mcp-CLmIdoaC.cjs} +17 -14
- package/dist/mcp-CLmIdoaC.cjs.map +1 -0
- package/dist/{validate-DD5UaudC.js → validate-8i6chavn.js} +18 -20
- package/dist/validate-8i6chavn.js.map +1 -0
- package/dist/{validate-ClewPP5U.cjs → validate-DNbDDWp4.cjs} +26 -24
- package/dist/validate-DNbDDWp4.cjs.map +1 -0
- package/package.json +9 -9
- package/src/index.ts +4 -4
- package/dist/generate-Bu9WyH1N.cjs.map +0 -1
- package/dist/generate-CKnWsDnu.cjs.map +0 -1
- package/dist/generate-DvSF6lmv.js.map +0 -1
- package/dist/generate-jMDBjxTU.js.map +0 -1
- package/dist/mcp-Cmiw4RpU.cjs.map +0 -1
- package/dist/mcp-DcaOAt6B.js.map +0 -1
- package/dist/validate-ClewPP5U.cjs.map +0 -1
- package/dist/validate-DD5UaudC.js.map +0 -1
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-DWy1uDak.cjs');
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
let citty = require("citty");
|
|
3
|
+
citty = require_chunk.__toESM(citty);
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
node_path = require_chunk.__toESM(node_path);
|
|
6
|
+
let node_process = require("node:process");
|
|
7
|
+
node_process = require_chunk.__toESM(node_process);
|
|
8
|
+
let __kubb_core = require("@kubb/core");
|
|
9
|
+
__kubb_core = require_chunk.__toESM(__kubb_core);
|
|
10
|
+
let __kubb_core_logger = require("@kubb/core/logger");
|
|
11
|
+
__kubb_core_logger = require_chunk.__toESM(__kubb_core_logger);
|
|
12
|
+
let open = require("open");
|
|
13
|
+
open = require_chunk.__toESM(open);
|
|
14
|
+
let picocolors = require("picocolors");
|
|
15
|
+
picocolors = require_chunk.__toESM(picocolors);
|
|
16
|
+
let __kubb_core_utils = require("@kubb/core/utils");
|
|
17
|
+
__kubb_core_utils = require_chunk.__toESM(__kubb_core_utils);
|
|
18
|
+
let cosmiconfig = require("cosmiconfig");
|
|
19
|
+
cosmiconfig = require_chunk.__toESM(cosmiconfig);
|
|
20
|
+
let jiti = require("jiti");
|
|
21
|
+
jiti = require_chunk.__toESM(jiti);
|
|
12
22
|
|
|
13
23
|
//#region src/utils/getPlugins.ts
|
|
14
24
|
function isJSONPlugins(plugins) {
|
|
@@ -30,11 +40,11 @@ function getPlugins(plugins) {
|
|
|
30
40
|
/**
|
|
31
41
|
* Converting UserConfig to Config without a change in the object beside the JSON convert.
|
|
32
42
|
*/
|
|
33
|
-
async function getConfig(result, args
|
|
43
|
+
async function getConfig(result, args) {
|
|
34
44
|
const config = result?.config;
|
|
35
45
|
let kubbUserConfig = Promise.resolve(config);
|
|
36
46
|
if (typeof config === "function") {
|
|
37
|
-
const possiblePromise = config(args
|
|
47
|
+
const possiblePromise = config(args);
|
|
38
48
|
if ((0, __kubb_core_utils.isPromise)(possiblePromise)) kubbUserConfig = possiblePromise;
|
|
39
49
|
kubbUserConfig = Promise.resolve(possiblePromise);
|
|
40
50
|
}
|
|
@@ -60,15 +70,13 @@ async function getConfig(result, args$1) {
|
|
|
60
70
|
//#endregion
|
|
61
71
|
//#region src/utils/getCosmiConfig.ts
|
|
62
72
|
const tsLoader = async (configFile) => {
|
|
63
|
-
|
|
73
|
+
return await (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, {
|
|
64
74
|
jsx: {
|
|
65
75
|
runtime: "automatic",
|
|
66
76
|
importSource: "@kubb/react"
|
|
67
77
|
},
|
|
68
78
|
sourceMaps: true
|
|
69
|
-
});
|
|
70
|
-
const mod = await jiti$1.import(configFile, { default: true });
|
|
71
|
-
return mod;
|
|
79
|
+
}).import(configFile, { default: true });
|
|
72
80
|
};
|
|
73
81
|
async function getCosmiConfig(moduleName, config) {
|
|
74
82
|
const searchPlaces = [
|
|
@@ -109,12 +117,10 @@ async function getCosmiConfig(moduleName, config) {
|
|
|
109
117
|
async function startWatcher(path$1, cb) {
|
|
110
118
|
const { watch } = await import("chokidar");
|
|
111
119
|
const logger = (0, __kubb_core_logger.createLogger)();
|
|
112
|
-
|
|
113
|
-
const watcher = watch(path$1, {
|
|
120
|
+
watch(path$1, {
|
|
114
121
|
ignorePermissionErrors: true,
|
|
115
|
-
ignored
|
|
116
|
-
})
|
|
117
|
-
watcher.on("all", (type, file) => {
|
|
122
|
+
ignored: "**/{.git,node_modules}/**"
|
|
123
|
+
}).on("all", (type, file) => {
|
|
118
124
|
logger?.emit("info", picocolors.default.yellow(picocolors.default.bold(`Change detected: ${type} ${file}`)));
|
|
119
125
|
try {
|
|
120
126
|
cb(path$1);
|
|
@@ -126,64 +132,63 @@ async function startWatcher(path$1, cb) {
|
|
|
126
132
|
|
|
127
133
|
//#endregion
|
|
128
134
|
//#region src/commands/generate.ts
|
|
129
|
-
const args = {
|
|
130
|
-
config: {
|
|
131
|
-
type: "string",
|
|
132
|
-
description: "Path to the Kubb config",
|
|
133
|
-
alias: "c"
|
|
134
|
-
},
|
|
135
|
-
logLevel: {
|
|
136
|
-
type: "string",
|
|
137
|
-
description: "Info, silent or debug",
|
|
138
|
-
alias: "l",
|
|
139
|
-
default: "info",
|
|
140
|
-
valueHint: "silent|info|debug"
|
|
141
|
-
},
|
|
142
|
-
watch: {
|
|
143
|
-
type: "boolean",
|
|
144
|
-
description: "Watch mode based on the input file",
|
|
145
|
-
alias: "w",
|
|
146
|
-
default: false
|
|
147
|
-
},
|
|
148
|
-
debug: {
|
|
149
|
-
type: "boolean",
|
|
150
|
-
description: "Override logLevel to debug",
|
|
151
|
-
alias: "d",
|
|
152
|
-
default: false
|
|
153
|
-
},
|
|
154
|
-
ui: {
|
|
155
|
-
type: "boolean",
|
|
156
|
-
description: "Open ui",
|
|
157
|
-
alias: "u",
|
|
158
|
-
default: false
|
|
159
|
-
},
|
|
160
|
-
help: {
|
|
161
|
-
type: "boolean",
|
|
162
|
-
description: "Show help",
|
|
163
|
-
alias: "h",
|
|
164
|
-
default: false
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
135
|
const command = (0, citty.defineCommand)({
|
|
168
136
|
meta: {
|
|
169
137
|
name: "generate",
|
|
170
138
|
description: "[input] Generate files based on a 'kubb.config.ts' file"
|
|
171
139
|
},
|
|
172
|
-
args
|
|
140
|
+
args: {
|
|
141
|
+
config: {
|
|
142
|
+
type: "string",
|
|
143
|
+
description: "Path to the Kubb config",
|
|
144
|
+
alias: "c"
|
|
145
|
+
},
|
|
146
|
+
logLevel: {
|
|
147
|
+
type: "string",
|
|
148
|
+
description: "Info, silent or debug",
|
|
149
|
+
alias: "l",
|
|
150
|
+
default: "info",
|
|
151
|
+
valueHint: "silent|info|debug"
|
|
152
|
+
},
|
|
153
|
+
watch: {
|
|
154
|
+
type: "boolean",
|
|
155
|
+
description: "Watch mode based on the input file",
|
|
156
|
+
alias: "w",
|
|
157
|
+
default: false
|
|
158
|
+
},
|
|
159
|
+
debug: {
|
|
160
|
+
type: "boolean",
|
|
161
|
+
description: "Override logLevel to debug",
|
|
162
|
+
alias: "d",
|
|
163
|
+
default: false
|
|
164
|
+
},
|
|
165
|
+
ui: {
|
|
166
|
+
type: "boolean",
|
|
167
|
+
description: "Open ui",
|
|
168
|
+
alias: "u",
|
|
169
|
+
default: false
|
|
170
|
+
},
|
|
171
|
+
help: {
|
|
172
|
+
type: "boolean",
|
|
173
|
+
description: "Show help",
|
|
174
|
+
alias: "h",
|
|
175
|
+
default: false
|
|
176
|
+
}
|
|
177
|
+
},
|
|
173
178
|
async run(commandContext) {
|
|
174
179
|
let name = "";
|
|
175
180
|
const progressCache = /* @__PURE__ */ new Map();
|
|
176
|
-
const { args
|
|
177
|
-
const input = args
|
|
178
|
-
if (args
|
|
179
|
-
if (args
|
|
180
|
-
const logLevel = __kubb_core_logger.LogMapper[args
|
|
181
|
+
const { args } = commandContext;
|
|
182
|
+
const input = args._[0];
|
|
183
|
+
if (args.help) return (0, citty.showUsage)(command);
|
|
184
|
+
if (args.debug) args.logLevel = "debug";
|
|
185
|
+
const logLevel = __kubb_core_logger.LogMapper[args.logLevel] || 3;
|
|
181
186
|
const logger = (0, __kubb_core_logger.createLogger)({ logLevel });
|
|
182
|
-
const { generate } = await Promise.resolve().then(() => require("./generate-
|
|
187
|
+
const { generate } = await Promise.resolve().then(() => require("./generate-BALD2C5T.cjs"));
|
|
183
188
|
logger.emit("start", "Loading config");
|
|
184
|
-
const result = await getCosmiConfig("kubb", args
|
|
189
|
+
const result = await getCosmiConfig("kubb", args.config);
|
|
185
190
|
logger.emit("success", `Config loaded(${picocolors.default.dim(node_path.default.relative(node_process.cwd(), result.filepath))})`);
|
|
186
|
-
const config = await getConfig(result, args
|
|
191
|
+
const config = await getConfig(result, args);
|
|
187
192
|
const start = async () => {
|
|
188
193
|
if (Array.isArray(config)) {
|
|
189
194
|
const promiseManager = new __kubb_core.PromiseManager();
|
|
@@ -193,7 +198,7 @@ const command = (0, citty.defineCommand)({
|
|
|
193
198
|
return generate({
|
|
194
199
|
input,
|
|
195
200
|
config: c,
|
|
196
|
-
args
|
|
201
|
+
args,
|
|
197
202
|
progressCache
|
|
198
203
|
});
|
|
199
204
|
});
|
|
@@ -205,17 +210,16 @@ const command = (0, citty.defineCommand)({
|
|
|
205
210
|
input,
|
|
206
211
|
config,
|
|
207
212
|
progressCache,
|
|
208
|
-
args
|
|
213
|
+
args
|
|
209
214
|
});
|
|
210
215
|
};
|
|
211
|
-
if (args
|
|
216
|
+
if (args.ui) {
|
|
212
217
|
const { startServer } = await import("@kubb/ui");
|
|
213
218
|
await startServer({
|
|
214
219
|
stop: () => node_process.exit(1),
|
|
215
220
|
restart: () => start(),
|
|
216
221
|
getMeta: () => {
|
|
217
|
-
const
|
|
218
|
-
const percentages = entries.reduce((acc, [key, singleBar]) => {
|
|
222
|
+
const percentages = [...progressCache.entries()].reduce((acc, [key, singleBar]) => {
|
|
219
223
|
acc[key] = singleBar.getProgress();
|
|
220
224
|
return acc;
|
|
221
225
|
}, {});
|
|
@@ -230,7 +234,7 @@ const command = (0, citty.defineCommand)({
|
|
|
230
234
|
(0, open.default)(url);
|
|
231
235
|
});
|
|
232
236
|
}
|
|
233
|
-
if (args
|
|
237
|
+
if (args.watch) {
|
|
234
238
|
if (Array.isArray(config)) throw new Error("Cannot use watcher with multiple Configs(array)");
|
|
235
239
|
if ((0, __kubb_core.isInputPath)(config)) return startWatcher([input || config.input.path], async (paths) => {
|
|
236
240
|
await start();
|
|
@@ -238,18 +242,15 @@ const command = (0, citty.defineCommand)({
|
|
|
238
242
|
});
|
|
239
243
|
}
|
|
240
244
|
await start();
|
|
241
|
-
if (globalThis.isDevtoolsEnabled) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (canRestart) await start();
|
|
247
|
-
else node_process.exit(1);
|
|
248
|
-
}
|
|
245
|
+
if (globalThis.isDevtoolsEnabled) if (await logger.consola?.prompt("Restart(could be used to validate the profiler)?", {
|
|
246
|
+
type: "confirm",
|
|
247
|
+
initial: false
|
|
248
|
+
})) await start();
|
|
249
|
+
else node_process.exit(1);
|
|
249
250
|
}
|
|
250
251
|
});
|
|
251
252
|
var generate_default = command;
|
|
252
253
|
|
|
253
254
|
//#endregion
|
|
254
255
|
exports.default = generate_default;
|
|
255
|
-
//# sourceMappingURL=generate-
|
|
256
|
+
//# sourceMappingURL=generate-CBoWFhG2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-CBoWFhG2.cjs","names":["results: Array<Config>","path","pc","LogMapper","pc","path","process","PromiseManager"],"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 { isPromise } from '@kubb/core/utils'\n\nimport { getPlugins } from './getPlugins.ts'\n\nimport type { Config, UserConfig } from '@kubb/core'\nimport type { Args } from '../commands/generate.ts'\nimport type { CosmiconfigResult } from './getCosmiConfig.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)\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',\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 open from 'open'\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 or debug',\n alias: 'l',\n default: 'info',\n valueHint: 'silent|info|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 ui: {\n type: 'boolean',\n description: 'Open ui',\n alias: 'u',\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 let name = ''\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 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 name = c.name || ''\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.ui) {\n const { startServer } = await import('@kubb/ui')\n\n await startServer(\n {\n stop: () => process.exit(1),\n restart: () => start(),\n getMeta: () => {\n const entries = [...progressCache.entries()]\n\n const percentages = entries.reduce(\n (acc, [key, singleBar]) => {\n acc[key] = singleBar.getProgress()\n\n return acc\n },\n {} as Record<string, number>,\n )\n\n return {\n name,\n percentages,\n }\n },\n },\n (info) => {\n const url = `${info.address}:${info.port}`.replace('::', 'http://localhost')\n logger.consola?.start(`Starting ui on ${url}`)\n\n open(url)\n },\n )\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;;;;;;;;ACVjC,eAAsB,UAAU,QAA2B,MAA6C;CACtG,MAAM,SAAS,QAAQ;CACvB,IAAI,iBAAiB,QAAQ,QAAQ,OAAO;AAG5C,KAAI,OAAO,WAAW,YAAY;EAChC,MAAM,kBAAkB,OAAO,KAAK;AACpC,uCAAc,gBAAgB,CAC5B,kBAAiB;AAEnB,mBAAiB,QAAQ,QAAQ,gBAAgB;;CAGnD,IAAI,aAAa,MAAM;AAEvB,KAAI,MAAM,QAAQ,WAAW,EAAE;EAC7B,MAAMA,UAAyB,EAAE;AAEjC,OAAK,MAAM,QAAQ,YAAY;GAC7B,MAAM,UAAU,KAAK,UAAU,MAAM,WAAW,KAAK,QAAQ,GAAG;AAEhE,WAAQ,KAAK;IACX,GAAG;IACH;IACD,CAAW;;AAGd,SAAO;;AAGT,cAAa;EACX,GAAG;EACH,SAAS,WAAW,UAAU,MAAM,WAAW,WAAW,QAAQ,GAAG;EACtE;AAED,QAAO;;;;;ACpCT,MA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,SAAS;AACzC;;AAGF,iBAAc,OAAO;AAErB,SAAM,SAAS;IACb;IACA;IACA;IACA;IACD,CAAC;;AAKJ,MAAI,KAAK,IAAI;GACX,MAAM,EAAE,gBAAgB,MAAM,OAAO;AAErC,SAAM,YACJ;IACE,YAAYD,aAAQ,KAAK,EAAE;IAC3B,eAAe,OAAO;IACtB,eAAe;KAGb,MAAM,cAFU,CAAC,GAAG,cAAc,SAAS,CAAC,CAEhB,QACzB,KAAK,CAAC,KAAK,eAAe;AACzB,UAAI,OAAO,UAAU,aAAa;AAElC,aAAO;QAET,EAAE,CACH;AAED,YAAO;MACL;MACA;MACD;;IAEJ,GACA,SAAS;IACR,MAAM,MAAM,GAAG,KAAK,QAAQ,GAAG,KAAK,OAAO,QAAQ,MAAM,mBAAmB;AAC5E,WAAO,SAAS,MAAM,kBAAkB,MAAM;AAE9C,sBAAK,IAAI;KAEZ;;AAGH,MAAI,KAAK,OAAO;AACd,OAAI,MAAM,QAAQ,OAAO,CACvB,OAAM,IAAI,MAAM,kDAAkD;AAGpE,oCAAgB,OAAO,CACrB,QAAO,aAAa,CAAC,SAAS,OAAO,MAAM,KAAK,EAAE,OAAO,UAAU;AACjE,UAAM,OAAO;AACb,WAAO,KAAK,SAASF,mBAAG,OAAOA,mBAAG,KAAK,2BAA2B,MAAM,KAAK,QAAQ,GAAG,CAAC,CAAC;KAC1F;;AAIN,QAAM,OAAO;AAEb,MAAI,WAAW,kBAMb,KALmB,MAAM,OAAO,SAAS,OAAO,oDAAoD;GAClG,MAAM;GACN,SAAS;GACV,CAAC,CAGA,OAAM,OAAO;MAEb,cAAQ,KAAK,EAAE;;CAItB,CAAC;AAEF,uBAAe"}
|
|
@@ -29,11 +29,11 @@ function getPlugins(plugins) {
|
|
|
29
29
|
/**
|
|
30
30
|
* Converting UserConfig to Config without a change in the object beside the JSON convert.
|
|
31
31
|
*/
|
|
32
|
-
async function getConfig(result, args
|
|
32
|
+
async function getConfig(result, args) {
|
|
33
33
|
const config = result?.config;
|
|
34
34
|
let kubbUserConfig = Promise.resolve(config);
|
|
35
35
|
if (typeof config === "function") {
|
|
36
|
-
const possiblePromise = config(args
|
|
36
|
+
const possiblePromise = config(args);
|
|
37
37
|
if (isPromise(possiblePromise)) kubbUserConfig = possiblePromise;
|
|
38
38
|
kubbUserConfig = Promise.resolve(possiblePromise);
|
|
39
39
|
}
|
|
@@ -59,15 +59,13 @@ async function getConfig(result, args$1) {
|
|
|
59
59
|
//#endregion
|
|
60
60
|
//#region src/utils/getCosmiConfig.ts
|
|
61
61
|
const tsLoader = async (configFile) => {
|
|
62
|
-
|
|
62
|
+
return await createJiti(import.meta.url, {
|
|
63
63
|
jsx: {
|
|
64
64
|
runtime: "automatic",
|
|
65
65
|
importSource: "@kubb/react"
|
|
66
66
|
},
|
|
67
67
|
sourceMaps: true
|
|
68
|
-
});
|
|
69
|
-
const mod = await jiti.import(configFile, { default: true });
|
|
70
|
-
return mod;
|
|
68
|
+
}).import(configFile, { default: true });
|
|
71
69
|
};
|
|
72
70
|
async function getCosmiConfig(moduleName, config) {
|
|
73
71
|
const searchPlaces = [
|
|
@@ -108,12 +106,10 @@ async function getCosmiConfig(moduleName, config) {
|
|
|
108
106
|
async function startWatcher(path$1, cb) {
|
|
109
107
|
const { watch } = await import("chokidar");
|
|
110
108
|
const logger = createLogger();
|
|
111
|
-
|
|
112
|
-
const watcher = watch(path$1, {
|
|
109
|
+
watch(path$1, {
|
|
113
110
|
ignorePermissionErrors: true,
|
|
114
|
-
ignored
|
|
115
|
-
})
|
|
116
|
-
watcher.on("all", (type, file) => {
|
|
111
|
+
ignored: "**/{.git,node_modules}/**"
|
|
112
|
+
}).on("all", (type, file) => {
|
|
117
113
|
logger?.emit("info", pc.yellow(pc.bold(`Change detected: ${type} ${file}`)));
|
|
118
114
|
try {
|
|
119
115
|
cb(path$1);
|
|
@@ -125,64 +121,63 @@ async function startWatcher(path$1, cb) {
|
|
|
125
121
|
|
|
126
122
|
//#endregion
|
|
127
123
|
//#region src/commands/generate.ts
|
|
128
|
-
const 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 or debug",
|
|
137
|
-
alias: "l",
|
|
138
|
-
default: "info",
|
|
139
|
-
valueHint: "silent|info|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
|
-
ui: {
|
|
154
|
-
type: "boolean",
|
|
155
|
-
description: "Open ui",
|
|
156
|
-
alias: "u",
|
|
157
|
-
default: false
|
|
158
|
-
},
|
|
159
|
-
help: {
|
|
160
|
-
type: "boolean",
|
|
161
|
-
description: "Show help",
|
|
162
|
-
alias: "h",
|
|
163
|
-
default: false
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
124
|
const command = defineCommand({
|
|
167
125
|
meta: {
|
|
168
126
|
name: "generate",
|
|
169
127
|
description: "[input] Generate files based on a 'kubb.config.ts' file"
|
|
170
128
|
},
|
|
171
|
-
args
|
|
129
|
+
args: {
|
|
130
|
+
config: {
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "Path to the Kubb config",
|
|
133
|
+
alias: "c"
|
|
134
|
+
},
|
|
135
|
+
logLevel: {
|
|
136
|
+
type: "string",
|
|
137
|
+
description: "Info, silent or debug",
|
|
138
|
+
alias: "l",
|
|
139
|
+
default: "info",
|
|
140
|
+
valueHint: "silent|info|debug"
|
|
141
|
+
},
|
|
142
|
+
watch: {
|
|
143
|
+
type: "boolean",
|
|
144
|
+
description: "Watch mode based on the input file",
|
|
145
|
+
alias: "w",
|
|
146
|
+
default: false
|
|
147
|
+
},
|
|
148
|
+
debug: {
|
|
149
|
+
type: "boolean",
|
|
150
|
+
description: "Override logLevel to debug",
|
|
151
|
+
alias: "d",
|
|
152
|
+
default: false
|
|
153
|
+
},
|
|
154
|
+
ui: {
|
|
155
|
+
type: "boolean",
|
|
156
|
+
description: "Open ui",
|
|
157
|
+
alias: "u",
|
|
158
|
+
default: false
|
|
159
|
+
},
|
|
160
|
+
help: {
|
|
161
|
+
type: "boolean",
|
|
162
|
+
description: "Show help",
|
|
163
|
+
alias: "h",
|
|
164
|
+
default: false
|
|
165
|
+
}
|
|
166
|
+
},
|
|
172
167
|
async run(commandContext) {
|
|
173
168
|
let name = "";
|
|
174
169
|
const progressCache = /* @__PURE__ */ new Map();
|
|
175
|
-
const { args
|
|
176
|
-
const input = args
|
|
177
|
-
if (args
|
|
178
|
-
if (args
|
|
179
|
-
const logLevel = LogMapper[args
|
|
170
|
+
const { args } = commandContext;
|
|
171
|
+
const input = args._[0];
|
|
172
|
+
if (args.help) return showUsage(command);
|
|
173
|
+
if (args.debug) args.logLevel = "debug";
|
|
174
|
+
const logLevel = LogMapper[args.logLevel] || 3;
|
|
180
175
|
const logger = createLogger({ logLevel });
|
|
181
|
-
const { generate } = await import("./generate-
|
|
176
|
+
const { generate } = await import("./generate-vHDmA5Mm.js");
|
|
182
177
|
logger.emit("start", "Loading config");
|
|
183
|
-
const result = await getCosmiConfig("kubb", args
|
|
178
|
+
const result = await getCosmiConfig("kubb", args.config);
|
|
184
179
|
logger.emit("success", `Config loaded(${pc.dim(path.relative(process$1.cwd(), result.filepath))})`);
|
|
185
|
-
const config = await getConfig(result, args
|
|
180
|
+
const config = await getConfig(result, args);
|
|
186
181
|
const start = async () => {
|
|
187
182
|
if (Array.isArray(config)) {
|
|
188
183
|
const promiseManager = new PromiseManager();
|
|
@@ -192,7 +187,7 @@ const command = defineCommand({
|
|
|
192
187
|
return generate({
|
|
193
188
|
input,
|
|
194
189
|
config: c,
|
|
195
|
-
args
|
|
190
|
+
args,
|
|
196
191
|
progressCache
|
|
197
192
|
});
|
|
198
193
|
});
|
|
@@ -204,17 +199,16 @@ const command = defineCommand({
|
|
|
204
199
|
input,
|
|
205
200
|
config,
|
|
206
201
|
progressCache,
|
|
207
|
-
args
|
|
202
|
+
args
|
|
208
203
|
});
|
|
209
204
|
};
|
|
210
|
-
if (args
|
|
205
|
+
if (args.ui) {
|
|
211
206
|
const { startServer } = await import("@kubb/ui");
|
|
212
207
|
await startServer({
|
|
213
208
|
stop: () => process$1.exit(1),
|
|
214
209
|
restart: () => start(),
|
|
215
210
|
getMeta: () => {
|
|
216
|
-
const
|
|
217
|
-
const percentages = entries.reduce((acc, [key, singleBar]) => {
|
|
211
|
+
const percentages = [...progressCache.entries()].reduce((acc, [key, singleBar]) => {
|
|
218
212
|
acc[key] = singleBar.getProgress();
|
|
219
213
|
return acc;
|
|
220
214
|
}, {});
|
|
@@ -229,7 +223,7 @@ const command = defineCommand({
|
|
|
229
223
|
open(url);
|
|
230
224
|
});
|
|
231
225
|
}
|
|
232
|
-
if (args
|
|
226
|
+
if (args.watch) {
|
|
233
227
|
if (Array.isArray(config)) throw new Error("Cannot use watcher with multiple Configs(array)");
|
|
234
228
|
if (isInputPath(config)) return startWatcher([input || config.input.path], async (paths) => {
|
|
235
229
|
await start();
|
|
@@ -237,18 +231,15 @@ const command = defineCommand({
|
|
|
237
231
|
});
|
|
238
232
|
}
|
|
239
233
|
await start();
|
|
240
|
-
if (globalThis.isDevtoolsEnabled) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (canRestart) await start();
|
|
246
|
-
else process$1.exit(1);
|
|
247
|
-
}
|
|
234
|
+
if (globalThis.isDevtoolsEnabled) if (await logger.consola?.prompt("Restart(could be used to validate the profiler)?", {
|
|
235
|
+
type: "confirm",
|
|
236
|
+
initial: false
|
|
237
|
+
})) await start();
|
|
238
|
+
else process$1.exit(1);
|
|
248
239
|
}
|
|
249
240
|
});
|
|
250
241
|
var generate_default = command;
|
|
251
242
|
|
|
252
243
|
//#endregion
|
|
253
244
|
export { generate_default as default };
|
|
254
|
-
//# sourceMappingURL=generate-
|
|
245
|
+
//# sourceMappingURL=generate-CFatuxgj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-CFatuxgj.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 { isPromise } from '@kubb/core/utils'\n\nimport { getPlugins } from './getPlugins.ts'\n\nimport type { Config, UserConfig } from '@kubb/core'\nimport type { Args } from '../commands/generate.ts'\nimport type { CosmiconfigResult } from './getCosmiConfig.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)\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',\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 open from 'open'\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 or debug',\n alias: 'l',\n default: 'info',\n valueHint: 'silent|info|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 ui: {\n type: 'boolean',\n description: 'Open ui',\n alias: 'u',\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 let name = ''\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 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 name = c.name || ''\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.ui) {\n const { startServer } = await import('@kubb/ui')\n\n await startServer(\n {\n stop: () => process.exit(1),\n restart: () => start(),\n getMeta: () => {\n const entries = [...progressCache.entries()]\n\n const percentages = entries.reduce(\n (acc, [key, singleBar]) => {\n acc[key] = singleBar.getProgress()\n\n return acc\n },\n {} as Record<string, number>,\n )\n\n return {\n name,\n percentages,\n }\n },\n },\n (info) => {\n const url = `${info.address}:${info.port}`.replace('::', 'http://localhost')\n logger.consola?.start(`Starting ui on ${url}`)\n\n open(url)\n },\n )\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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