@kubb/cli 5.0.0-beta.75 → 5.0.0-beta.9
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 +177 -26
- package/dist/agent-C5F4itrc.js +68 -0
- package/dist/agent-C5F4itrc.js.map +1 -0
- package/dist/agent-d-lmeOr1.cjs +70 -0
- package/dist/agent-d-lmeOr1.cjs.map +1 -0
- package/dist/{chunk--u3MIqq1.js → chunk-BvFE5Tac.js} +1 -0
- package/dist/constants-B2JTeRBb.js +42 -0
- package/dist/constants-B2JTeRBb.js.map +1 -0
- package/dist/constants-BINTA5VZ.cjs +77 -0
- package/dist/constants-BINTA5VZ.cjs.map +1 -0
- package/dist/constants-BYGmiFs0.cjs +139 -0
- package/dist/constants-BYGmiFs0.cjs.map +1 -0
- package/dist/constants-DSJ-Xrbv.js +116 -0
- package/dist/constants-DSJ-Xrbv.js.map +1 -0
- package/dist/define-Bdn8j5VM.cjs.map +1 -1
- package/dist/{define-Ctii4bel.js → define-m_fp-Aqm.js} +2 -2
- package/dist/{define-Ctii4bel.js.map → define-m_fp-Aqm.js.map} +1 -1
- package/dist/{errors-CjPmyZHy.js → errors-CINO1EIv.js} +2 -2
- package/dist/{errors-CjPmyZHy.js.map → errors-CINO1EIv.js.map} +1 -1
- package/dist/errors-CLCjoSg0.cjs.map +1 -1
- package/dist/{generate-YPtfjsg4.js → generate-BhfRufgh.js} +12 -6
- package/dist/generate-BhfRufgh.js.map +1 -0
- package/dist/{generate-DDCwNQNo.cjs → generate-BvuSxNYj.cjs} +10 -4
- package/dist/generate-BvuSxNYj.cjs.map +1 -0
- package/dist/index.cjs +20 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -13
- package/dist/index.js.map +1 -1
- package/dist/init-DOSXtcyb.js +53 -0
- package/dist/init-DOSXtcyb.js.map +1 -0
- package/dist/init-bKtEOvhK.cjs +53 -0
- package/dist/init-bKtEOvhK.cjs.map +1 -0
- package/dist/mcp-CKkbG0kp.cjs +39 -0
- package/dist/mcp-CKkbG0kp.cjs.map +1 -0
- package/dist/mcp-DzOfqX_j.js +39 -0
- package/dist/mcp-DzOfqX_j.js.map +1 -0
- package/dist/package-BgAYWN7y.js +6 -0
- package/dist/package-BgAYWN7y.js.map +1 -0
- package/dist/{package-D5arPDnh.cjs → package-DHGhrRW-.cjs} +2 -2
- package/dist/package-DHGhrRW-.cjs.map +1 -0
- package/dist/{generate-K8MJ9aQF.cjs → run-BObDb2qe.cjs} +319 -334
- package/dist/run-BObDb2qe.cjs.map +1 -0
- package/dist/{agent-Ev5hU5hH.js → run-BzpYYOQs.js} +53 -44
- package/dist/run-BzpYYOQs.js.map +1 -0
- package/dist/run-CCZ24VKk.js +51 -0
- package/dist/run-CCZ24VKk.js.map +1 -0
- package/dist/{init-eNRlotJK.js → run-CF97BWVa.js} +102 -147
- package/dist/run-CF97BWVa.js.map +1 -0
- package/dist/run-CQbj3ley.cjs +52 -0
- package/dist/run-CQbj3ley.cjs.map +1 -0
- package/dist/run-D0hmRpHy.js +49 -0
- package/dist/run-D0hmRpHy.js.map +1 -0
- package/dist/{agent-B_pirbeB.cjs → run-DwdAwnLG.cjs} +51 -42
- package/dist/run-DwdAwnLG.cjs.map +1 -0
- package/dist/run-Lr0Ctnu0.cjs +50 -0
- package/dist/run-Lr0Ctnu0.cjs.map +1 -0
- package/dist/{generate-Cg8yufrw.js → run-P6D8TnXf.js} +322 -337
- package/dist/run-P6D8TnXf.js.map +1 -0
- package/dist/{init-CZ5Xq2Hd.cjs → run-YsoCk5we.cjs} +100 -145
- package/dist/run-YsoCk5we.cjs.map +1 -0
- package/dist/shell-475fQKaX.cjs.map +1 -1
- package/dist/{shell-DLzN4fRo.js → shell-CN6DNqeC.js} +2 -2
- package/dist/{shell-DLzN4fRo.js.map → shell-CN6DNqeC.js.map} +1 -1
- package/dist/{telemetry-DN95_2pF.cjs → telemetry-B2iWkY5e.cjs} +5 -7
- package/dist/telemetry-B2iWkY5e.cjs.map +1 -0
- package/dist/{telemetry-LgT_sdPe.js → telemetry-BkektVz6.js} +6 -8
- package/dist/telemetry-BkektVz6.js.map +1 -0
- package/dist/validate-Bj8vbvPt.cjs +26 -0
- package/dist/validate-Bj8vbvPt.cjs.map +1 -0
- package/dist/validate-bHUrnYBv.js +26 -0
- package/dist/validate-bHUrnYBv.js.map +1 -0
- package/package.json +22 -14
- package/src/commands/agent/start.ts +10 -7
- package/src/commands/agent.ts +3 -1
- package/src/commands/generate.ts +5 -3
- package/src/commands/init.ts +34 -3
- package/src/commands/mcp.ts +28 -4
- package/src/commands/validate.ts +6 -4
- package/src/constants.ts +2 -58
- package/src/index.ts +5 -3
- package/src/loggers/clackLogger.ts +45 -43
- package/src/loggers/fileSystemLogger.ts +26 -13
- package/src/loggers/githubActionsLogger.ts +13 -25
- package/src/loggers/plainLogger.ts +12 -23
- package/src/loggers/types.ts +6 -0
- package/src/loggers/utils.ts +155 -9
- package/src/runners/agent/run.ts +113 -0
- package/src/runners/agent/utils.ts +98 -0
- package/src/runners/generate/run.ts +276 -0
- package/src/runners/generate/utils.ts +209 -0
- package/src/runners/init/run.ts +211 -0
- package/src/{utils/packageManager.ts → runners/init/utils.ts} +10 -0
- package/src/runners/mcp/run.ts +55 -0
- package/src/runners/validate/run.ts +63 -0
- package/src/{utils/telemetry.ts → telemetry.ts} +12 -5
- package/dist/agent-BEgI2HXH.cjs +0 -58
- package/dist/agent-BEgI2HXH.cjs.map +0 -1
- package/dist/agent-B_pirbeB.cjs.map +0 -1
- package/dist/agent-CTdJEHEs.js +0 -56
- package/dist/agent-CTdJEHEs.js.map +0 -1
- package/dist/agent-Ev5hU5hH.js.map +0 -1
- package/dist/constants-CnDXa1R6.cjs +0 -148
- package/dist/constants-CnDXa1R6.cjs.map +0 -1
- package/dist/constants-aL3CP_Wq.js +0 -95
- package/dist/constants-aL3CP_Wq.js.map +0 -1
- package/dist/generate-Cg8yufrw.js.map +0 -1
- package/dist/generate-DDCwNQNo.cjs.map +0 -1
- package/dist/generate-K8MJ9aQF.cjs.map +0 -1
- package/dist/generate-YPtfjsg4.js.map +0 -1
- package/dist/init-Bu95ML_u.cjs +0 -25
- package/dist/init-Bu95ML_u.cjs.map +0 -1
- package/dist/init-CZ5Xq2Hd.cjs.map +0 -1
- package/dist/init-eNRlotJK.js.map +0 -1
- package/dist/init-ooJeOBGt.js +0 -25
- package/dist/init-ooJeOBGt.js.map +0 -1
- package/dist/mcp-C-d5N1wZ.js +0 -16
- package/dist/mcp-C-d5N1wZ.js.map +0 -1
- package/dist/mcp-CLcDV4Jm.cjs +0 -41
- package/dist/mcp-CLcDV4Jm.cjs.map +0 -1
- package/dist/mcp-D7EIR9fR.js +0 -40
- package/dist/mcp-D7EIR9fR.js.map +0 -1
- package/dist/mcp-Dpu8vzzj.cjs +0 -16
- package/dist/mcp-Dpu8vzzj.cjs.map +0 -1
- package/dist/package-D5arPDnh.cjs.map +0 -1
- package/dist/package-DqZsMLZ9.js +0 -6
- package/dist/package-DqZsMLZ9.js.map +0 -1
- package/dist/telemetry-DN95_2pF.cjs.map +0 -1
- package/dist/telemetry-LgT_sdPe.js.map +0 -1
- package/dist/validate-CIR3_lZI.js +0 -25
- package/dist/validate-CIR3_lZI.js.map +0 -1
- package/dist/validate-DcqUb4DM.cjs +0 -25
- package/dist/validate-DcqUb4DM.cjs.map +0 -1
- package/dist/validate-kLJoT_hi.js +0 -33
- package/dist/validate-kLJoT_hi.js.map +0 -1
- package/dist/validate-yKKzqEZ5.cjs +0 -34
- package/dist/validate-yKKzqEZ5.cjs.map +0 -1
- package/src/runners/agent.ts +0 -149
- package/src/runners/generate.ts +0 -333
- package/src/runners/init.ts +0 -296
- package/src/runners/mcp.ts +0 -45
- package/src/runners/validate.ts +0 -39
- package/src/types.ts +0 -11
- package/src/utils/Writables.ts +0 -17
- package/src/utils/executeHooks.ts +0 -45
- package/src/utils/flags.ts +0 -9
- package/src/utils/getConfig.ts +0 -10
- package/src/utils/getCosmiConfig.ts +0 -80
- package/src/utils/getSummary.ts +0 -68
- package/src/utils/runHook.ts +0 -91
- package/src/utils/watcher.ts +0 -19
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./chunk
|
|
2
|
-
import { t as spawnAsync } from "./shell-
|
|
3
|
-
import {
|
|
1
|
+
import "./chunk-BvFE5Tac.js";
|
|
2
|
+
import { t as spawnAsync } from "./shell-CN6DNqeC.js";
|
|
3
|
+
import { i as pluginDefaultConfigs, n as availablePlugins, r as initDefaults, t as KUBB_CONFIG_FILENAME } from "./constants-DSJ-Xrbv.js";
|
|
4
4
|
import { styleText } from "node:util";
|
|
5
5
|
import fs, { existsSync, readFileSync } from "node:fs";
|
|
6
6
|
import path, { join } from "node:path";
|
|
@@ -62,97 +62,8 @@ function detectPackageManager(cwd = process.cwd()) {
|
|
|
62
62
|
return packageManagers.npm;
|
|
63
63
|
}
|
|
64
64
|
//#endregion
|
|
65
|
-
//#region src/
|
|
66
|
-
function
|
|
67
|
-
return fs.existsSync(path.join(cwd, "package.json"));
|
|
68
|
-
}
|
|
69
|
-
async function initPackageJson(cwd, packageManager) {
|
|
70
|
-
await spawnAsync(packageManager.name, {
|
|
71
|
-
npm: ["init", "-y"],
|
|
72
|
-
pnpm: ["init"],
|
|
73
|
-
yarn: ["init", "-y"],
|
|
74
|
-
bun: ["init", "-y"]
|
|
75
|
-
}[packageManager.name], { cwd });
|
|
76
|
-
}
|
|
77
|
-
async function installPackages(packages, packageManager, cwd = process.cwd()) {
|
|
78
|
-
await spawnAsync(packageManager.name, [...packageManager.installCommand, ...packages], { cwd });
|
|
79
|
-
}
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/runners/init.ts
|
|
82
|
-
const availablePlugins = [
|
|
83
|
-
{
|
|
84
|
-
value: "plugin-ts",
|
|
85
|
-
label: "TypeScript",
|
|
86
|
-
hint: "Recommended",
|
|
87
|
-
packageName: "@kubb/plugin-ts",
|
|
88
|
-
importName: "pluginTs",
|
|
89
|
-
category: "types"
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
value: "plugin-client",
|
|
93
|
-
label: "Client (Fetch/Axios)",
|
|
94
|
-
packageName: "@kubb/plugin-client",
|
|
95
|
-
importName: "pluginClient",
|
|
96
|
-
category: "client"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
value: "plugin-react-query",
|
|
100
|
-
label: "React Query / TanStack Query",
|
|
101
|
-
packageName: "@kubb/plugin-react-query",
|
|
102
|
-
importName: "pluginReactQuery",
|
|
103
|
-
category: "framework"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
value: "plugin-vue-query",
|
|
107
|
-
label: "Vue Query",
|
|
108
|
-
packageName: "@kubb/plugin-vue-query",
|
|
109
|
-
importName: "pluginVueQuery",
|
|
110
|
-
category: "framework"
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
value: "plugin-zod",
|
|
114
|
-
label: "Zod Schemas",
|
|
115
|
-
packageName: "@kubb/plugin-zod",
|
|
116
|
-
importName: "pluginZod",
|
|
117
|
-
category: "validation"
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
value: "plugin-faker",
|
|
121
|
-
label: "Faker.js Mocks",
|
|
122
|
-
packageName: "@kubb/plugin-faker",
|
|
123
|
-
importName: "pluginFaker",
|
|
124
|
-
category: "mocks"
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
value: "plugin-msw",
|
|
128
|
-
label: "MSW Handlers",
|
|
129
|
-
packageName: "@kubb/plugin-msw",
|
|
130
|
-
importName: "pluginMsw",
|
|
131
|
-
category: "mocks"
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
value: "plugin-cypress",
|
|
135
|
-
label: "Cypress Tests",
|
|
136
|
-
packageName: "@kubb/plugin-cypress",
|
|
137
|
-
importName: "pluginCypress",
|
|
138
|
-
category: "testing"
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
value: "plugin-mcp",
|
|
142
|
-
label: "MCP Server (AI / Model Context Protocol)",
|
|
143
|
-
packageName: "@kubb/plugin-mcp",
|
|
144
|
-
importName: "pluginMcp",
|
|
145
|
-
category: "ai"
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
value: "plugin-redoc",
|
|
149
|
-
label: "ReDoc Documentation",
|
|
150
|
-
packageName: "@kubb/plugin-redoc",
|
|
151
|
-
importName: "pluginRedoc",
|
|
152
|
-
category: "documentation"
|
|
153
|
-
}
|
|
154
|
-
];
|
|
155
|
-
function generateConfigFile(selectedPlugins, inputPath, outputPath) {
|
|
65
|
+
//#region ../../internals/shared/src/init.ts
|
|
66
|
+
function generateConfigFile({ selectedPlugins, inputPath, outputPath }) {
|
|
156
67
|
return `import { defineConfig } from 'kubb'
|
|
157
68
|
${selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`).join("\n")}
|
|
158
69
|
|
|
@@ -173,15 +84,63 @@ ${selectedPlugins.map((plugin) => {
|
|
|
173
84
|
})
|
|
174
85
|
`;
|
|
175
86
|
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/runners/init/utils.ts
|
|
89
|
+
/**
|
|
90
|
+
* Returns `true` when a `package.json` exists at `cwd`.
|
|
91
|
+
*/
|
|
92
|
+
function hasPackageJson(cwd = process$1.cwd()) {
|
|
93
|
+
return fs.existsSync(path.join(cwd, "package.json"));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Initializes a new `package.json` at `cwd` using the detected package manager.
|
|
97
|
+
*/
|
|
98
|
+
async function initPackageJson(cwd, packageManager) {
|
|
99
|
+
await spawnAsync(packageManager.name, {
|
|
100
|
+
npm: ["init", "-y"],
|
|
101
|
+
pnpm: ["init"],
|
|
102
|
+
yarn: ["init", "-y"],
|
|
103
|
+
bun: ["init", "-y"]
|
|
104
|
+
}[packageManager.name], { cwd });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Installs the given packages at `cwd` using the detected package manager.
|
|
108
|
+
*/
|
|
109
|
+
async function installPackages(packages, packageManager, cwd = process$1.cwd()) {
|
|
110
|
+
await spawnAsync(packageManager.name, [...packageManager.installCommand, ...packages], { cwd });
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/runners/init/run.ts
|
|
176
114
|
function cancelAndExit(message = "Operation cancelled.") {
|
|
177
115
|
clack.cancel(message);
|
|
178
116
|
process$1.exit(0);
|
|
179
117
|
}
|
|
180
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Runs the interactive Kubb scaffolding wizard.
|
|
120
|
+
* Detects the package manager, prompts for input/output paths and plugins, installs packages, and writes `kubb.config.ts`.
|
|
121
|
+
* Pass `yes: true` to skip all prompts and use defaults.
|
|
122
|
+
*/
|
|
123
|
+
async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag }) {
|
|
181
124
|
const cwd = process$1.cwd();
|
|
182
125
|
clack.intro(styleText("bgCyan", styleText("black", " Kubb Init ")));
|
|
126
|
+
/**
|
|
127
|
+
* Returns `flag` when provided, the `defaultValue` when `yes` is set,
|
|
128
|
+
* or calls `prompt()` for interactive input. Exits on cancellation.
|
|
129
|
+
*/
|
|
130
|
+
async function resolveOrPrompt(flag, defaultValue, logLabel, prompt) {
|
|
131
|
+
if (flag !== void 0) {
|
|
132
|
+
clack.log.info(`${logLabel}: ${styleText("cyan", String(flag))}`);
|
|
133
|
+
return flag;
|
|
134
|
+
}
|
|
135
|
+
if (yes) {
|
|
136
|
+
clack.log.info(`${logLabel}: ${styleText("cyan", String(defaultValue))}`);
|
|
137
|
+
return defaultValue;
|
|
138
|
+
}
|
|
139
|
+
const result = await prompt();
|
|
140
|
+
if (clack.isCancel(result)) cancelAndExit();
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
183
143
|
try {
|
|
184
|
-
let packageManager;
|
|
185
144
|
if (!hasPackageJson(cwd)) {
|
|
186
145
|
if (!yes) {
|
|
187
146
|
const shouldInit = await clack.confirm({
|
|
@@ -190,64 +149,56 @@ async function runInit({ yes, version }) {
|
|
|
190
149
|
});
|
|
191
150
|
if (clack.isCancel(shouldInit) || !shouldInit) cancelAndExit();
|
|
192
151
|
}
|
|
193
|
-
packageManager = detectPackageManager(cwd);
|
|
152
|
+
const packageManager = detectPackageManager(cwd);
|
|
194
153
|
const spinner = clack.spinner();
|
|
195
154
|
spinner.start(`Initializing package.json with ${packageManager.name}`);
|
|
196
155
|
await initPackageJson(cwd, packageManager);
|
|
197
156
|
spinner.stop(`Created package.json with ${packageManager.name}`);
|
|
198
|
-
} else {
|
|
199
|
-
packageManager = detectPackageManager(cwd);
|
|
200
|
-
clack.log.info(`Detected package manager: ${styleText("cyan", packageManager.name)}`);
|
|
201
|
-
}
|
|
202
|
-
let inputPath;
|
|
203
|
-
if (yes) {
|
|
204
|
-
inputPath = initDefaults.inputPath;
|
|
205
|
-
clack.log.info(`Using input path: ${styleText("cyan", inputPath)}`);
|
|
206
|
-
} else {
|
|
207
|
-
const inputPathResult = await clack.text({
|
|
208
|
-
message: "Where is your OpenAPI specification located?",
|
|
209
|
-
placeholder: initDefaults.inputPath,
|
|
210
|
-
defaultValue: initDefaults.inputPath,
|
|
211
|
-
validate: (value) => {
|
|
212
|
-
if (!value) return "Input path is required";
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
if (clack.isCancel(inputPathResult)) cancelAndExit();
|
|
216
|
-
inputPath = inputPathResult;
|
|
217
|
-
}
|
|
218
|
-
let outputPath;
|
|
219
|
-
if (yes) {
|
|
220
|
-
outputPath = initDefaults.outputPath;
|
|
221
|
-
clack.log.info(`Using output path: ${styleText("cyan", outputPath)}`);
|
|
222
|
-
} else {
|
|
223
|
-
const outputPathResult = await clack.text({
|
|
224
|
-
message: "Where should the generated files be output?",
|
|
225
|
-
placeholder: initDefaults.outputPath,
|
|
226
|
-
defaultValue: initDefaults.outputPath,
|
|
227
|
-
validate: (value) => {
|
|
228
|
-
if (!value) return "Output path is required";
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
if (clack.isCancel(outputPathResult)) cancelAndExit();
|
|
232
|
-
outputPath = outputPathResult;
|
|
233
157
|
}
|
|
158
|
+
const packageManager = detectPackageManager(cwd);
|
|
159
|
+
if (hasPackageJson(cwd)) clack.log.info(`Detected package manager: ${styleText("cyan", packageManager.name)}`);
|
|
160
|
+
const inputPath = await resolveOrPrompt(inputFlag, initDefaults.inputPath, "Using input path", () => clack.text({
|
|
161
|
+
message: "Where is your OpenAPI specification located?",
|
|
162
|
+
placeholder: initDefaults.inputPath,
|
|
163
|
+
defaultValue: initDefaults.inputPath,
|
|
164
|
+
validate: (value) => {
|
|
165
|
+
if (!value) return "Input path is required";
|
|
166
|
+
}
|
|
167
|
+
}));
|
|
168
|
+
const outputPath = await resolveOrPrompt(outputFlag, initDefaults.outputPath, "Using output path", () => clack.text({
|
|
169
|
+
message: "Where should the generated files be output?",
|
|
170
|
+
placeholder: initDefaults.outputPath,
|
|
171
|
+
defaultValue: initDefaults.outputPath,
|
|
172
|
+
validate: (value) => {
|
|
173
|
+
if (!value) return "Output path is required";
|
|
174
|
+
}
|
|
175
|
+
}));
|
|
176
|
+
const defaultPlugins = availablePlugins.filter((p) => initDefaults.plugins.includes(p.value));
|
|
177
|
+
const pluginLabel = (plugins) => styleText("cyan", plugins.map((p) => p.label).join(", "));
|
|
234
178
|
let selectedPlugins;
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
|
|
179
|
+
if (pluginsFlag) {
|
|
180
|
+
const requested = pluginsFlag.split(",").map((v) => v.trim()).filter(Boolean);
|
|
181
|
+
selectedPlugins = availablePlugins.filter((p) => requested.includes(p.value));
|
|
182
|
+
if (selectedPlugins.length === 0) {
|
|
183
|
+
selectedPlugins = defaultPlugins;
|
|
184
|
+
clack.log.warn(`No valid plugins found in --plugins value; falling back to default: ${pluginLabel(defaultPlugins)}`);
|
|
185
|
+
} else clack.log.info(`Using plugins: ${pluginLabel(selectedPlugins)}`);
|
|
186
|
+
} else if (yes) {
|
|
187
|
+
selectedPlugins = defaultPlugins;
|
|
188
|
+
clack.log.info(`Using plugins: ${pluginLabel(defaultPlugins)}`);
|
|
238
189
|
} else {
|
|
239
|
-
const
|
|
190
|
+
const values = await clack.multiselect({
|
|
240
191
|
message: "Select plugins to use:",
|
|
241
|
-
options: availablePlugins.map((
|
|
242
|
-
value
|
|
243
|
-
label
|
|
244
|
-
hint
|
|
192
|
+
options: availablePlugins.map(({ value, label, hint }) => ({
|
|
193
|
+
value,
|
|
194
|
+
label,
|
|
195
|
+
hint
|
|
245
196
|
})),
|
|
246
197
|
initialValues: [...initDefaults.plugins],
|
|
247
198
|
required: true
|
|
248
199
|
});
|
|
249
|
-
if (clack.isCancel(
|
|
250
|
-
selectedPlugins = availablePlugins.filter((
|
|
200
|
+
if (clack.isCancel(values)) cancelAndExit();
|
|
201
|
+
selectedPlugins = availablePlugins.filter((p) => values.includes(p.value));
|
|
251
202
|
}
|
|
252
203
|
const packagesToInstall = ["kubb", ...selectedPlugins.map((p) => p.packageName)];
|
|
253
204
|
const spinner = clack.spinner();
|
|
@@ -261,7 +212,11 @@ async function runInit({ yes, version }) {
|
|
|
261
212
|
}
|
|
262
213
|
const configSpinner = clack.spinner();
|
|
263
214
|
configSpinner.start(`Creating ${KUBB_CONFIG_FILENAME}`);
|
|
264
|
-
const configContent = generateConfigFile(
|
|
215
|
+
const configContent = generateConfigFile({
|
|
216
|
+
selectedPlugins,
|
|
217
|
+
inputPath,
|
|
218
|
+
outputPath
|
|
219
|
+
});
|
|
265
220
|
const configPath = path.join(cwd, KUBB_CONFIG_FILENAME);
|
|
266
221
|
if (fs.existsSync(configPath)) {
|
|
267
222
|
configSpinner.stop(`${KUBB_CONFIG_FILENAME} already exists`);
|
|
@@ -274,9 +229,9 @@ async function runInit({ yes, version }) {
|
|
|
274
229
|
}
|
|
275
230
|
configSpinner.start(`Overwriting ${KUBB_CONFIG_FILENAME}`);
|
|
276
231
|
}
|
|
277
|
-
fs.
|
|
232
|
+
await fs.promises.writeFile(configPath, configContent, "utf-8");
|
|
278
233
|
configSpinner.stop(`Created ${KUBB_CONFIG_FILENAME}`);
|
|
279
|
-
clack.outro(styleText("green", "✓ All set!") + "\n\n" + styleText("dim", "Next steps:") + "\n" + styleText("cyan", ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) + "\n" + styleText("cyan", " 2. Generate code with: npx kubb generate") + "\n" + styleText("cyan", " Or start a stream server with: npx kubb start") + "\n" + styleText("cyan", ` 3. Find generated files in: ${outputPath}`) + "\n\n" + styleText("dim", `Using ${packageManager.name} • Kubb v${version}`));
|
|
234
|
+
clack.outro(styleText("green", "✓ All set!") + "\n\n" + styleText("dim", "Next steps:") + "\n" + styleText("cyan", ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) + "\n" + styleText("cyan", " 2. Generate code with: npx kubb generate") + "\n" + styleText("cyan", " Or start a stream server with: npx kubb agent start") + "\n" + styleText("cyan", ` 3. Find generated files in: ${outputPath}`) + "\n\n" + styleText("dim", `Using ${packageManager.name} • Kubb v${version}`));
|
|
280
235
|
} catch (error) {
|
|
281
236
|
clack.log.error(styleText("red", "An error occurred during initialization"));
|
|
282
237
|
if (error instanceof Error) clack.log.error(error.message);
|
|
@@ -284,6 +239,6 @@ async function runInit({ yes, version }) {
|
|
|
284
239
|
}
|
|
285
240
|
}
|
|
286
241
|
//#endregion
|
|
287
|
-
export {
|
|
242
|
+
export { run };
|
|
288
243
|
|
|
289
|
-
//# sourceMappingURL=
|
|
244
|
+
//# sourceMappingURL=run-CF97BWVa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-CF97BWVa.js","names":["process","process"],"sources":["../../../internals/utils/src/packageManager.ts","../../../internals/shared/src/init.ts","../src/runners/init/utils.ts","../src/runners/init/run.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { join } from 'node:path'\n\n/**\n * Supported package manager identifiers.\n *\n * @example\n * ```ts\n * const pm: PackageManagerName = 'pnpm'\n * ```\n */\nexport type PackageManagerName = 'npm' | 'pnpm' | 'yarn' | 'bun'\n\n/**\n * Metadata describing a package manager's lock file and install command.\n */\nexport interface PackageManagerInfo {\n /**\n * Identifier used in CLI commands, e.g. `pnpm`, `yarn`.\n */\n name: PackageManagerName\n /**\n * Lock file name that uniquely identifies this package manager in a project root.\n */\n lockFile: string\n /**\n * Subcommands passed to the package manager binary to install a dev dependency.\n */\n installCommand: ReadonlyArray<string>\n}\n/**\n * Metadata for each supported package manager, keyed by its short name.\n *\n * @example\n * ```ts\n * packageManagers.pnpm.installCommand // ['add', '-D']\n * packageManagers.npm.lockFile // 'package-lock.json'\n * ```\n */\nconst packageManagers: Record<PackageManagerName, PackageManagerInfo> = {\n pnpm: {\n name: 'pnpm',\n lockFile: 'pnpm-lock.yaml',\n installCommand: ['add', '-D'],\n },\n yarn: {\n name: 'yarn',\n lockFile: 'yarn.lock',\n installCommand: ['add', '-D'],\n },\n bun: {\n name: 'bun',\n lockFile: 'bun.lockb',\n installCommand: ['add', '-d'],\n },\n npm: {\n name: 'npm',\n lockFile: 'package-lock.json',\n installCommand: ['install', '--save-dev'],\n },\n}\n\n/**\n * Minimal shape of `package.json` fields read during detection.\n */\ntype PackageJson = {\n /**\n * The `packageManager` field from `package.json` (e.g. `\"pnpm@9.0.0\"`).\n */\n packageManager?: string\n}\n\n/**\n * Detects the active package manager for the given directory.\n * Resolution order: `packageManager` field in `package.json`, then presence of a lock file.\n * Falls back to `npm` when no signal is found.\n *\n * @example\n * ```ts\n * detectPackageManager('/my/project') // { name: 'pnpm', lockFile: 'pnpm-lock.yaml', ... }\n * detectPackageManager() // falls back to npm when no lock file is found\n * ```\n */\nexport function detectPackageManager(cwd: string = process.cwd()): PackageManagerInfo {\n const packageJsonPath = join(cwd, 'package.json')\n if (existsSync(packageJsonPath)) {\n try {\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as PackageJson\n const pmField = packageJson.packageManager\n if (typeof pmField === 'string') {\n const name = pmField.split('@')[0]\n if (name && name in packageManagers) {\n return packageManagers[name as PackageManagerName]\n }\n }\n } catch {\n // Continue to lock file detection\n }\n }\n\n for (const pm of Object.values(packageManagers)) {\n if (existsSync(join(cwd, pm.lockFile))) {\n return pm\n }\n }\n\n return packageManagers.npm\n}\n","import { pluginDefaultConfigs } from './constants.ts'\nimport type { PluginOption } from './types.ts'\n\nexport function generateConfigFile({\n selectedPlugins,\n inputPath,\n outputPath,\n}: {\n selectedPlugins: PluginOption[]\n inputPath: string\n outputPath: string\n}): string {\n const imports = selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`).join('\\n')\n\n const pluginConfigs = selectedPlugins\n .map((plugin) => {\n const config = (pluginDefaultConfigs as Record<string, string>)[plugin.value] ?? `${plugin.importName}()`\n return ` ${config},`\n })\n .join('\\n')\n\n return `import { defineConfig } from 'kubb'\n${imports}\n\nexport default defineConfig({\n root: '.',\n input: {\n path: '${inputPath}',\n },\n output: {\n path: '${outputPath}',\n clean: true,\n },\n plugins: [\n${pluginConfigs}\n ],\n})\n`\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport type { PackageManagerInfo, PackageManagerName } from '@internals/utils'\nimport { spawnAsync } from '@internals/utils'\n\n/**\n * Returns `true` when a `package.json` exists at `cwd`.\n */\nexport function hasPackageJson(cwd: string = process.cwd()): boolean {\n return fs.existsSync(path.join(cwd, 'package.json'))\n}\n\n/**\n * Initializes a new `package.json` at `cwd` using the detected package manager.\n */\nexport async function initPackageJson(cwd: string, packageManager: PackageManagerInfo): Promise<void> {\n const commands: Record<PackageManagerName, string[]> = {\n npm: ['init', '-y'],\n pnpm: ['init'],\n yarn: ['init', '-y'],\n bun: ['init', '-y'],\n }\n\n await spawnAsync(packageManager.name, commands[packageManager.name], { cwd })\n}\n\n/**\n * Installs the given packages at `cwd` using the detected package manager.\n */\nexport async function installPackages(packages: string[], packageManager: PackageManagerInfo, cwd: string = process.cwd()): Promise<void> {\n await spawnAsync(packageManager.name, [...packageManager.installCommand, ...packages], { cwd })\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { detectPackageManager } from '@internals/utils'\nimport { availablePlugins, generateConfigFile, initDefaults, KUBB_CONFIG_FILENAME, type PluginOption } from '@internals/shared'\nimport { hasPackageJson, initPackageJson, installPackages } from './utils.ts'\n\nfunction cancelAndExit(message = 'Operation cancelled.'): never {\n clack.cancel(message)\n process.exit(0)\n}\n\ntype InitOptions = {\n /**\n * When `true`, skips all interactive prompts and uses default values.\n */\n yes: boolean\n /**\n * Current `@kubb/cli` version string, shown in the outro and used for package installation.\n */\n version: string\n /**\n * Input path flag value from `--input`. When provided, skips the input prompt.\n */\n input?: string\n /**\n * Output directory flag value from `--output`. When provided, skips the output prompt.\n */\n output?: string\n /**\n * Comma-separated plugin list from `--plugins`, e.g. `'plugin-ts,plugin-zod'`. When provided, skips the plugin selection prompt.\n */\n plugins?: string\n}\n\n/**\n * Runs the interactive Kubb scaffolding wizard.\n * Detects the package manager, prompts for input/output paths and plugins, installs packages, and writes `kubb.config.ts`.\n * Pass `yes: true` to skip all prompts and use defaults.\n */\nexport async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag }: InitOptions): Promise<void> {\n const cwd = process.cwd()\n\n clack.intro(styleText('bgCyan', styleText('black', ' Kubb Init ')))\n\n /**\n * Returns `flag` when provided, the `defaultValue` when `yes` is set,\n * or calls `prompt()` for interactive input. Exits on cancellation.\n */\n async function resolveOrPrompt<T>(flag: T | undefined, defaultValue: T, logLabel: string, prompt: () => Promise<T | symbol>): Promise<T> {\n if (flag !== undefined) {\n clack.log.info(`${logLabel}: ${styleText('cyan', String(flag))}`)\n return flag\n }\n if (yes) {\n clack.log.info(`${logLabel}: ${styleText('cyan', String(defaultValue))}`)\n return defaultValue\n }\n const result = await prompt()\n if (clack.isCancel(result)) cancelAndExit()\n return result as T\n }\n\n try {\n // Check/create package.json — detect package manager once after the block\n if (!hasPackageJson(cwd)) {\n if (!yes) {\n const shouldInit = await clack.confirm({\n message: 'No package.json found. Would you like to create one?',\n initialValue: true,\n })\n\n if (clack.isCancel(shouldInit) || !shouldInit) {\n cancelAndExit()\n }\n }\n\n const packageManager = detectPackageManager(cwd)\n const spinner = clack.spinner()\n spinner.start(`Initializing package.json with ${packageManager.name}`)\n await initPackageJson(cwd, packageManager)\n spinner.stop(`Created package.json with ${packageManager.name}`)\n }\n\n const packageManager = detectPackageManager(cwd)\n if (hasPackageJson(cwd)) {\n clack.log.info(`Detected package manager: ${styleText('cyan', packageManager.name)}`)\n }\n\n // Prompt for OpenAPI spec path\n const inputPath = await resolveOrPrompt(inputFlag, initDefaults.inputPath, 'Using input path', () =>\n clack.text({\n message: 'Where is your OpenAPI specification located?',\n placeholder: initDefaults.inputPath,\n defaultValue: initDefaults.inputPath,\n validate: (value) => {\n if (!value) return 'Input path is required'\n },\n }),\n )\n\n // Prompt for output directory\n const outputPath = await resolveOrPrompt(outputFlag, initDefaults.outputPath, 'Using output path', () =>\n clack.text({\n message: 'Where should the generated files be output?',\n placeholder: initDefaults.outputPath,\n defaultValue: initDefaults.outputPath,\n validate: (value) => {\n if (!value) return 'Output path is required'\n },\n }),\n )\n\n // Plugin selection\n const defaultPlugins = availablePlugins.filter((p) => (initDefaults.plugins as readonly string[]).includes(p.value))\n const pluginLabel = (plugins: PluginOption[]) => styleText('cyan', plugins.map((p) => p.label).join(', '))\n\n let selectedPlugins: PluginOption[]\n if (pluginsFlag) {\n const requested = pluginsFlag\n .split(',')\n .map((v) => v.trim())\n .filter(Boolean)\n selectedPlugins = availablePlugins.filter((p) => requested.includes(p.value))\n if (selectedPlugins.length === 0) {\n selectedPlugins = defaultPlugins\n clack.log.warn(`No valid plugins found in --plugins value; falling back to default: ${pluginLabel(defaultPlugins)}`)\n } else {\n clack.log.info(`Using plugins: ${pluginLabel(selectedPlugins)}`)\n }\n } else if (yes) {\n selectedPlugins = defaultPlugins\n clack.log.info(`Using plugins: ${pluginLabel(defaultPlugins)}`)\n } else {\n const values = await clack.multiselect({\n message: 'Select plugins to use:',\n options: availablePlugins.map(({ value, label, hint }) => ({ value, label, hint })),\n initialValues: [...initDefaults.plugins],\n required: true,\n })\n if (clack.isCancel(values)) cancelAndExit()\n selectedPlugins = availablePlugins.filter((p) => (values as string[]).includes(p.value))\n }\n\n // Install packages\n const packagesToInstall = ['kubb', ...selectedPlugins.map((p) => p.packageName)]\n\n const spinner = clack.spinner()\n spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`)\n\n try {\n await installPackages(packagesToInstall, packageManager, cwd)\n spinner.stop(`Installed ${packagesToInstall.length} packages`)\n } catch (error) {\n spinner.stop('Installation failed')\n throw error\n }\n\n // Generate config file\n const configSpinner = clack.spinner()\n configSpinner.start(`Creating ${KUBB_CONFIG_FILENAME}`)\n\n const configContent = generateConfigFile({ selectedPlugins, inputPath, outputPath })\n const configPath = path.join(cwd, KUBB_CONFIG_FILENAME)\n\n if (fs.existsSync(configPath)) {\n configSpinner.stop(`${KUBB_CONFIG_FILENAME} already exists`)\n\n if (!yes) {\n const shouldOverwrite = await clack.confirm({\n message: `${KUBB_CONFIG_FILENAME} already exists. Overwrite?`,\n initialValue: false,\n })\n\n if (clack.isCancel(shouldOverwrite) || !shouldOverwrite) {\n cancelAndExit('Keeping existing configuration. Packages have been installed.')\n }\n }\n\n configSpinner.start(`Overwriting ${KUBB_CONFIG_FILENAME}`)\n }\n\n await fs.promises.writeFile(configPath, configContent, 'utf-8')\n\n configSpinner.stop(`Created ${KUBB_CONFIG_FILENAME}`)\n\n clack.outro(\n styleText('green', '✓ All set!') +\n '\\n\\n' +\n styleText('dim', 'Next steps:') +\n '\\n' +\n styleText('cyan', ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) +\n '\\n' +\n styleText('cyan', ' 2. Generate code with: npx kubb generate') +\n '\\n' +\n styleText('cyan', ' Or start a stream server with: npx kubb agent start') +\n '\\n' +\n styleText('cyan', ` 3. Find generated files in: ${outputPath}`) +\n '\\n\\n' +\n styleText('dim', `Using ${packageManager.name} • Kubb v${version}`),\n )\n } catch (error) {\n clack.log.error(styleText('red', 'An error occurred during initialization'))\n if (error instanceof Error) {\n clack.log.error(error.message)\n }\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuCA,MAAM,kBAAkE;CACtE,MAAM;EACJ,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OAAO,KAAK;EAC9B;CACD,MAAM;EACJ,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OAAO,KAAK;EAC9B;CACD,KAAK;EACH,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,OAAO,KAAK;EAC9B;CACD,KAAK;EACH,MAAM;EACN,UAAU;EACV,gBAAgB,CAAC,WAAW,aAAa;EAC1C;CACF;;;;;;;;;;;;AAuBD,SAAgB,qBAAqB,MAAc,QAAQ,KAAK,EAAsB;CACpF,MAAM,kBAAkB,KAAK,KAAK,eAAe;CACjD,IAAI,WAAW,gBAAgB,EAC7B,IAAI;EAEF,MAAM,UADc,KAAK,MAAM,aAAa,iBAAiB,QAAQ,CAC1C,CAAC;EAC5B,IAAI,OAAO,YAAY,UAAU;GAC/B,MAAM,OAAO,QAAQ,MAAM,IAAI,CAAC;GAChC,IAAI,QAAQ,QAAQ,iBAClB,OAAO,gBAAgB;;SAGrB;CAKV,KAAK,MAAM,MAAM,OAAO,OAAO,gBAAgB,EAC7C,IAAI,WAAW,KAAK,KAAK,GAAG,SAAS,CAAC,EACpC,OAAO;CAIX,OAAO,gBAAgB;;;;ACvGzB,SAAgB,mBAAmB,EACjC,iBACA,WACA,cAKS;CAUT,OAAO;EATS,gBAAgB,KAAK,WAAW,YAAY,OAAO,WAAW,WAAW,OAAO,YAAY,GAAG,CAAC,KAAK,KAU9G,CAAC;;;;;aAKG,UAAU;;;aAGV,WAAW;;;;EAhBA,gBACnB,KAAK,WAAW;EAEf,OAAO,OADS,qBAAgD,OAAO,UAAU,GAAG,OAAO,WAAW,IACjF;GACrB,CACD,KAAK,KAeK,CAAC;;;;;;;;;;ACzBhB,SAAgB,eAAe,MAAcA,UAAQ,KAAK,EAAW;CACnE,OAAO,GAAG,WAAW,KAAK,KAAK,KAAK,eAAe,CAAC;;;;;AAMtD,eAAsB,gBAAgB,KAAa,gBAAmD;CAQpG,MAAM,WAAW,eAAe,MAAM;EANpC,KAAK,CAAC,QAAQ,KAAK;EACnB,MAAM,CAAC,OAAO;EACd,MAAM,CAAC,QAAQ,KAAK;EACpB,KAAK,CAAC,QAAQ,KAAK;EAGyB,CAAC,eAAe,OAAO,EAAE,KAAK,CAAC;;;;;AAM/E,eAAsB,gBAAgB,UAAoB,gBAAoC,MAAcA,UAAQ,KAAK,EAAiB;CACxI,MAAM,WAAW,eAAe,MAAM,CAAC,GAAG,eAAe,gBAAgB,GAAG,SAAS,EAAE,EAAE,KAAK,CAAC;;;;ACtBjG,SAAS,cAAc,UAAU,wBAA+B;CAC9D,MAAM,OAAO,QAAQ;CACrB,UAAQ,KAAK,EAAE;;;;;;;AA+BjB,eAAsB,IAAI,EAAE,KAAK,SAAS,OAAO,WAAW,QAAQ,YAAY,SAAS,eAA2C;CAClI,MAAM,MAAMC,UAAQ,KAAK;CAEzB,MAAM,MAAM,UAAU,UAAU,UAAU,SAAS,cAAc,CAAC,CAAC;;;;;CAMnE,eAAe,gBAAmB,MAAqB,cAAiB,UAAkB,QAA+C;EACvI,IAAI,SAAS,KAAA,GAAW;GACtB,MAAM,IAAI,KAAK,GAAG,SAAS,IAAI,UAAU,QAAQ,OAAO,KAAK,CAAC,GAAG;GACjE,OAAO;;EAET,IAAI,KAAK;GACP,MAAM,IAAI,KAAK,GAAG,SAAS,IAAI,UAAU,QAAQ,OAAO,aAAa,CAAC,GAAG;GACzE,OAAO;;EAET,MAAM,SAAS,MAAM,QAAQ;EAC7B,IAAI,MAAM,SAAS,OAAO,EAAE,eAAe;EAC3C,OAAO;;CAGT,IAAI;EAEF,IAAI,CAAC,eAAe,IAAI,EAAE;GACxB,IAAI,CAAC,KAAK;IACR,MAAM,aAAa,MAAM,MAAM,QAAQ;KACrC,SAAS;KACT,cAAc;KACf,CAAC;IAEF,IAAI,MAAM,SAAS,WAAW,IAAI,CAAC,YACjC,eAAe;;GAInB,MAAM,iBAAiB,qBAAqB,IAAI;GAChD,MAAM,UAAU,MAAM,SAAS;GAC/B,QAAQ,MAAM,kCAAkC,eAAe,OAAO;GACtE,MAAM,gBAAgB,KAAK,eAAe;GAC1C,QAAQ,KAAK,6BAA6B,eAAe,OAAO;;EAGlE,MAAM,iBAAiB,qBAAqB,IAAI;EAChD,IAAI,eAAe,IAAI,EACrB,MAAM,IAAI,KAAK,6BAA6B,UAAU,QAAQ,eAAe,KAAK,GAAG;EAIvF,MAAM,YAAY,MAAM,gBAAgB,WAAW,aAAa,WAAW,0BACzE,MAAM,KAAK;GACT,SAAS;GACT,aAAa,aAAa;GAC1B,cAAc,aAAa;GAC3B,WAAW,UAAU;IACnB,IAAI,CAAC,OAAO,OAAO;;GAEtB,CAAC,CACH;EAGD,MAAM,aAAa,MAAM,gBAAgB,YAAY,aAAa,YAAY,2BAC5E,MAAM,KAAK;GACT,SAAS;GACT,aAAa,aAAa;GAC1B,cAAc,aAAa;GAC3B,WAAW,UAAU;IACnB,IAAI,CAAC,OAAO,OAAO;;GAEtB,CAAC,CACH;EAGD,MAAM,iBAAiB,iBAAiB,QAAQ,MAAO,aAAa,QAA8B,SAAS,EAAE,MAAM,CAAC;EACpH,MAAM,eAAe,YAA4B,UAAU,QAAQ,QAAQ,KAAK,MAAM,EAAE,MAAM,CAAC,KAAK,KAAK,CAAC;EAE1G,IAAI;EACJ,IAAI,aAAa;GACf,MAAM,YAAY,YACf,MAAM,IAAI,CACV,KAAK,MAAM,EAAE,MAAM,CAAC,CACpB,OAAO,QAAQ;GAClB,kBAAkB,iBAAiB,QAAQ,MAAM,UAAU,SAAS,EAAE,MAAM,CAAC;GAC7E,IAAI,gBAAgB,WAAW,GAAG;IAChC,kBAAkB;IAClB,MAAM,IAAI,KAAK,uEAAuE,YAAY,eAAe,GAAG;UAEpH,MAAM,IAAI,KAAK,kBAAkB,YAAY,gBAAgB,GAAG;SAE7D,IAAI,KAAK;GACd,kBAAkB;GAClB,MAAM,IAAI,KAAK,kBAAkB,YAAY,eAAe,GAAG;SAC1D;GACL,MAAM,SAAS,MAAM,MAAM,YAAY;IACrC,SAAS;IACT,SAAS,iBAAiB,KAAK,EAAE,OAAO,OAAO,YAAY;KAAE;KAAO;KAAO;KAAM,EAAE;IACnF,eAAe,CAAC,GAAG,aAAa,QAAQ;IACxC,UAAU;IACX,CAAC;GACF,IAAI,MAAM,SAAS,OAAO,EAAE,eAAe;GAC3C,kBAAkB,iBAAiB,QAAQ,MAAO,OAAoB,SAAS,EAAE,MAAM,CAAC;;EAI1F,MAAM,oBAAoB,CAAC,QAAQ,GAAG,gBAAgB,KAAK,MAAM,EAAE,YAAY,CAAC;EAEhF,MAAM,UAAU,MAAM,SAAS;EAC/B,QAAQ,MAAM,cAAc,kBAAkB,OAAO,iBAAiB,eAAe,OAAO;EAE5F,IAAI;GACF,MAAM,gBAAgB,mBAAmB,gBAAgB,IAAI;GAC7D,QAAQ,KAAK,aAAa,kBAAkB,OAAO,WAAW;WACvD,OAAO;GACd,QAAQ,KAAK,sBAAsB;GACnC,MAAM;;EAIR,MAAM,gBAAgB,MAAM,SAAS;EACrC,cAAc,MAAM,YAAY,uBAAuB;EAEvD,MAAM,gBAAgB,mBAAmB;GAAE;GAAiB;GAAW;GAAY,CAAC;EACpF,MAAM,aAAa,KAAK,KAAK,KAAK,qBAAqB;EAEvD,IAAI,GAAG,WAAW,WAAW,EAAE;GAC7B,cAAc,KAAK,GAAG,qBAAqB,iBAAiB;GAE5D,IAAI,CAAC,KAAK;IACR,MAAM,kBAAkB,MAAM,MAAM,QAAQ;KAC1C,SAAS,GAAG,qBAAqB;KACjC,cAAc;KACf,CAAC;IAEF,IAAI,MAAM,SAAS,gBAAgB,IAAI,CAAC,iBACtC,cAAc,gEAAgE;;GAIlF,cAAc,MAAM,eAAe,uBAAuB;;EAG5D,MAAM,GAAG,SAAS,UAAU,YAAY,eAAe,QAAQ;EAE/D,cAAc,KAAK,WAAW,uBAAuB;EAErD,MAAM,MACJ,UAAU,SAAS,aAAa,GAC9B,SACA,UAAU,OAAO,cAAc,GAC/B,OACA,UAAU,QAAQ,2CAA2C,YAAY,GACzE,OACA,UAAU,QAAQ,6CAA6C,GAC/D,OACA,UAAU,QAAQ,2DAA2D,GAC7E,OACA,UAAU,QAAQ,iCAAiC,aAAa,GAChE,SACA,UAAU,OAAO,SAAS,eAAe,KAAK,WAAW,UAAU,CACtE;UACM,OAAO;EACd,MAAM,IAAI,MAAM,UAAU,OAAO,0CAA0C,CAAC;EAC5E,IAAI,iBAAiB,OACnB,MAAM,IAAI,MAAM,MAAM,QAAQ;EAEhC,UAAQ,KAAK,EAAE"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
|
+
const require_errors = require("./errors-CLCjoSg0.cjs");
|
|
3
|
+
const require_telemetry = require("./telemetry-B2iWkY5e.cjs");
|
|
4
|
+
let node_util = require("node:util");
|
|
5
|
+
let node_process = require("node:process");
|
|
6
|
+
node_process = require_chunk.__toESM(node_process, 1);
|
|
7
|
+
//#region src/runners/validate/run.ts
|
|
8
|
+
/**
|
|
9
|
+
* Dynamically loads `@kubb/adapter-oas` for OpenAPI validation.
|
|
10
|
+
*/
|
|
11
|
+
function loadValidateModule() {
|
|
12
|
+
return import("@kubb/adapter-oas");
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Validates an OpenAPI/Swagger file at `input` using `@kubb/adapter-oas`.
|
|
16
|
+
* Exits the process with code 1 on validation failure or missing dependency.
|
|
17
|
+
*/
|
|
18
|
+
async function run({ input, version }, dependencies = { loadValidateModule }) {
|
|
19
|
+
const hrStart = node_process.default.hrtime();
|
|
20
|
+
const report = (status) => require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
|
|
21
|
+
command: "validate",
|
|
22
|
+
kubbVersion: version,
|
|
23
|
+
hrStart,
|
|
24
|
+
status
|
|
25
|
+
}));
|
|
26
|
+
try {
|
|
27
|
+
const { adapterOas } = await dependencies.loadValidateModule();
|
|
28
|
+
const adapter = adapterOas();
|
|
29
|
+
if (!adapter.validate) throw new Error("The loaded adapter does not support validation.");
|
|
30
|
+
await adapter.validate(input, { throwOnError: true });
|
|
31
|
+
await report("success");
|
|
32
|
+
console.log("✅ Validation success");
|
|
33
|
+
} catch (error) {
|
|
34
|
+
await report("failed");
|
|
35
|
+
if (error instanceof Error && /@kubb\/adapter-oas/.test(error.message)) {
|
|
36
|
+
console.error((0, node_util.styleText)("red", "The @kubb/adapter-oas package is not installed."));
|
|
37
|
+
console.error("");
|
|
38
|
+
console.error("Install it with:");
|
|
39
|
+
console.error((0, node_util.styleText)("cyan", " npm install @kubb/adapter-oas"));
|
|
40
|
+
console.error((0, node_util.styleText)("cyan", " # or"));
|
|
41
|
+
console.error((0, node_util.styleText)("cyan", " pnpm install @kubb/adapter-oas"));
|
|
42
|
+
console.error("");
|
|
43
|
+
}
|
|
44
|
+
console.error("❌ Validation failed");
|
|
45
|
+
console.error(require_errors.getErrorMessage(error));
|
|
46
|
+
node_process.default.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.run = run;
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=run-CQbj3ley.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-CQbj3ley.cjs","names":["process","sendTelemetry","buildTelemetryEvent","getErrorMessage"],"sources":["../src/runners/validate/run.ts"],"sourcesContent":["import process from 'node:process'\nimport { styleText } from 'node:util'\nimport { getErrorMessage } from '@internals/utils'\nimport { buildTelemetryEvent, sendTelemetry } from '../../telemetry.ts'\n\ntype ValidateOptions = {\n /**\n * Path or URL to the OpenAPI/Swagger file to validate.\n */\n input: string\n /**\n * Current `@kubb/cli` version string, used for the telemetry payload.\n */\n version: string\n}\n\ntype ValidateModule = typeof import('@kubb/adapter-oas')\ntype ValidateDependencies = {\n /**\n * Loads `@kubb/adapter-oas`. Injected so tests can substitute a mock.\n */\n loadValidateModule: () => Promise<ValidateModule>\n}\n\n/**\n * Dynamically loads `@kubb/adapter-oas` for OpenAPI validation.\n */\nexport function loadValidateModule(): Promise<ValidateModule> {\n return import('@kubb/adapter-oas') as Promise<ValidateModule>\n}\n\n/**\n * Validates an OpenAPI/Swagger file at `input` using `@kubb/adapter-oas`.\n * Exits the process with code 1 on validation failure or missing dependency.\n */\nexport async function run({ input, version }: ValidateOptions, dependencies: ValidateDependencies = { loadValidateModule }): Promise<void> {\n const hrStart = process.hrtime()\n const report = (status: 'success' | 'failed') => sendTelemetry(buildTelemetryEvent({ command: 'validate', kubbVersion: version, hrStart, status }))\n try {\n const { adapterOas } = await dependencies.loadValidateModule()\n const adapter = adapterOas()\n if (!adapter.validate) {\n throw new Error('The loaded adapter does not support validation.')\n }\n await adapter.validate(input, { throwOnError: true })\n await report('success')\n console.log('✅ Validation success')\n } catch (error) {\n await report('failed')\n if (error instanceof Error && /@kubb\\/adapter-oas/.test(error.message)) {\n console.error(styleText('red', 'The @kubb/adapter-oas package is not installed.'))\n console.error('')\n console.error('Install it with:')\n console.error(styleText('cyan', ' npm install @kubb/adapter-oas'))\n console.error(styleText('cyan', ' # or'))\n console.error(styleText('cyan', ' pnpm install @kubb/adapter-oas'))\n console.error('')\n }\n console.error('❌ Validation failed')\n console.error(getErrorMessage(error))\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;AA2BA,SAAgB,qBAA8C;CAC5D,OAAO,OAAO;;;;;;AAOhB,eAAsB,IAAI,EAAE,OAAO,WAA4B,eAAqC,EAAE,oBAAoB,EAAiB;CACzI,MAAM,UAAUA,aAAAA,QAAQ,QAAQ;CAChC,MAAM,UAAU,WAAiCC,kBAAAA,cAAcC,kBAAAA,oBAAoB;EAAE,SAAS;EAAY,aAAa;EAAS;EAAS;EAAQ,CAAC,CAAC;CACnJ,IAAI;EACF,MAAM,EAAE,eAAe,MAAM,aAAa,oBAAoB;EAC9D,MAAM,UAAU,YAAY;EAC5B,IAAI,CAAC,QAAQ,UACX,MAAM,IAAI,MAAM,kDAAkD;EAEpE,MAAM,QAAQ,SAAS,OAAO,EAAE,cAAc,MAAM,CAAC;EACrD,MAAM,OAAO,UAAU;EACvB,QAAQ,IAAI,uBAAuB;UAC5B,OAAO;EACd,MAAM,OAAO,SAAS;EACtB,IAAI,iBAAiB,SAAS,qBAAqB,KAAK,MAAM,QAAQ,EAAE;GACtE,QAAQ,OAAA,GAAA,UAAA,WAAgB,OAAO,kDAAkD,CAAC;GAClF,QAAQ,MAAM,GAAG;GACjB,QAAQ,MAAM,mBAAmB;GACjC,QAAQ,OAAA,GAAA,UAAA,WAAgB,QAAQ,kCAAkC,CAAC;GACnE,QAAQ,OAAA,GAAA,UAAA,WAAgB,QAAQ,SAAS,CAAC;GAC1C,QAAQ,OAAA,GAAA,UAAA,WAAgB,QAAQ,mCAAmC,CAAC;GACpE,QAAQ,MAAM,GAAG;;EAEnB,QAAQ,MAAM,sBAAsB;EACpC,QAAQ,MAAMC,eAAAA,gBAAgB,MAAM,CAAC;EACrC,aAAA,QAAQ,KAAK,EAAE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import "./chunk-BvFE5Tac.js";
|
|
2
|
+
import { t as getErrorMessage } from "./errors-CINO1EIv.js";
|
|
3
|
+
import { r as sendTelemetry, t as buildTelemetryEvent } from "./telemetry-BkektVz6.js";
|
|
4
|
+
import { styleText } from "node:util";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
//#region src/runners/mcp/run.ts
|
|
7
|
+
/**
|
|
8
|
+
* Starts the Kubb MCP server using `@kubb/mcp`.
|
|
9
|
+
* Exits the process with code 1 if `@kubb/mcp` is not installed.
|
|
10
|
+
*/
|
|
11
|
+
async function run({ version, port, host }) {
|
|
12
|
+
let mod;
|
|
13
|
+
try {
|
|
14
|
+
mod = await import("@kubb/mcp");
|
|
15
|
+
} catch (_e) {
|
|
16
|
+
console.error(styleText("red", "The @kubb/mcp package is not installed."));
|
|
17
|
+
console.error("");
|
|
18
|
+
console.error("Install it with:");
|
|
19
|
+
console.error(styleText("cyan", " npm install @kubb/mcp"));
|
|
20
|
+
console.error(styleText("cyan", " # or"));
|
|
21
|
+
console.error(styleText("cyan", " pnpm install @kubb/mcp"));
|
|
22
|
+
console.error("");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
const { run: startMcpServer } = mod;
|
|
26
|
+
const hrStart = process.hrtime();
|
|
27
|
+
const report = (status) => sendTelemetry(buildTelemetryEvent({
|
|
28
|
+
command: "mcp",
|
|
29
|
+
kubbVersion: version,
|
|
30
|
+
hrStart,
|
|
31
|
+
status
|
|
32
|
+
}));
|
|
33
|
+
try {
|
|
34
|
+
console.log(styleText("cyan", "⏳ Starting MCP server..."));
|
|
35
|
+
console.warn(styleText("yellow", "This feature is still under development, use with caution"));
|
|
36
|
+
await startMcpServer(void 0, {
|
|
37
|
+
port: port !== void 0 ? Number(port) : void 0,
|
|
38
|
+
host
|
|
39
|
+
});
|
|
40
|
+
await report("success");
|
|
41
|
+
} catch (error) {
|
|
42
|
+
await report("failed");
|
|
43
|
+
console.error(getErrorMessage(error));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { run };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=run-D0hmRpHy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-D0hmRpHy.js","names":[],"sources":["../src/runners/mcp/run.ts"],"sourcesContent":["import process from 'node:process'\nimport { styleText } from 'node:util'\nimport { getErrorMessage } from '@internals/utils'\nimport type * as McpModule from '@kubb/mcp'\nimport { buildTelemetryEvent, sendTelemetry } from '../../telemetry.ts'\n\ntype McpOptions = {\n /**\n * Current `@kubb/cli` version string, used for the telemetry payload.\n */\n version: string\n /**\n * TCP port for the HTTP MCP server. When `undefined`, the server uses stdio transport.\n */\n port?: string\n /**\n * Hostname to bind to when running in HTTP mode.\n *\n * @default 'localhost'\n */\n host?: string\n}\n\n/**\n * Starts the Kubb MCP server using `@kubb/mcp`.\n * Exits the process with code 1 if `@kubb/mcp` is not installed.\n */\nexport async function run({ version, port, host }: McpOptions): Promise<void> {\n let mod: typeof McpModule\n try {\n mod = (await import('@kubb/mcp')) as typeof McpModule\n } catch (_e) {\n console.error(styleText('red', 'The @kubb/mcp package is not installed.'))\n console.error('')\n console.error('Install it with:')\n console.error(styleText('cyan', ' npm install @kubb/mcp'))\n console.error(styleText('cyan', ' # or'))\n console.error(styleText('cyan', ' pnpm install @kubb/mcp'))\n console.error('')\n process.exit(1)\n }\n\n const { run: startMcpServer } = mod\n const hrStart = process.hrtime()\n const report = (status: 'success' | 'failed') => sendTelemetry(buildTelemetryEvent({ command: 'mcp', kubbVersion: version, hrStart, status }))\n try {\n console.log(styleText('cyan', '⏳ Starting MCP server...'))\n console.warn(styleText('yellow', 'This feature is still under development, use with caution'))\n await startMcpServer(undefined, { port: port !== undefined ? Number(port) : undefined, host })\n await report('success')\n } catch (error) {\n await report('failed')\n console.error(getErrorMessage(error))\n }\n}\n"],"mappings":";;;;;;;;;;AA2BA,eAAsB,IAAI,EAAE,SAAS,MAAM,QAAmC;CAC5E,IAAI;CACJ,IAAI;EACF,MAAO,MAAM,OAAO;UACb,IAAI;EACX,QAAQ,MAAM,UAAU,OAAO,0CAA0C,CAAC;EAC1E,QAAQ,MAAM,GAAG;EACjB,QAAQ,MAAM,mBAAmB;EACjC,QAAQ,MAAM,UAAU,QAAQ,0BAA0B,CAAC;EAC3D,QAAQ,MAAM,UAAU,QAAQ,SAAS,CAAC;EAC1C,QAAQ,MAAM,UAAU,QAAQ,2BAA2B,CAAC;EAC5D,QAAQ,MAAM,GAAG;EACjB,QAAQ,KAAK,EAAE;;CAGjB,MAAM,EAAE,KAAK,mBAAmB;CAChC,MAAM,UAAU,QAAQ,QAAQ;CAChC,MAAM,UAAU,WAAiC,cAAc,oBAAoB;EAAE,SAAS;EAAO,aAAa;EAAS;EAAS;EAAQ,CAAC,CAAC;CAC9I,IAAI;EACF,QAAQ,IAAI,UAAU,QAAQ,2BAA2B,CAAC;EAC1D,QAAQ,KAAK,UAAU,UAAU,4DAA4D,CAAC;EAC9F,MAAM,eAAe,KAAA,GAAW;GAAE,MAAM,SAAS,KAAA,IAAY,OAAO,KAAK,GAAG,KAAA;GAAW;GAAM,CAAC;EAC9F,MAAM,OAAO,UAAU;UAChB,OAAO;EACd,MAAM,OAAO,SAAS;EACtB,QAAQ,MAAM,gBAAgB,MAAM,CAAC"}
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
const
|
|
2
|
+
const require_errors = require("./errors-CLCjoSg0.cjs");
|
|
3
|
+
const require_telemetry = require("./telemetry-B2iWkY5e.cjs");
|
|
3
4
|
const require_shell = require("./shell-475fQKaX.cjs");
|
|
4
|
-
const require_constants = require("./constants-
|
|
5
|
+
const require_constants = require("./constants-BINTA5VZ.cjs");
|
|
5
6
|
let node_util = require("node:util");
|
|
6
7
|
let node_path = require("node:path");
|
|
7
8
|
node_path = require_chunk.__toESM(node_path, 1);
|
|
8
9
|
let node_process = require("node:process");
|
|
9
10
|
node_process = require_chunk.__toESM(node_process, 1);
|
|
10
|
-
let
|
|
11
|
-
node_net = require_chunk.__toESM(node_net, 1);
|
|
12
|
-
let node_url = require("node:url");
|
|
11
|
+
let node_module = require("node:module");
|
|
13
12
|
let _clack_prompts = require("@clack/prompts");
|
|
14
13
|
_clack_prompts = require_chunk.__toESM(_clack_prompts, 1);
|
|
15
|
-
|
|
14
|
+
let node_net = require("node:net");
|
|
15
|
+
node_net = require_chunk.__toESM(node_net, 1);
|
|
16
|
+
//#region src/runners/agent/utils.ts
|
|
16
17
|
/**
|
|
17
18
|
* Resolves the environment passed to the detached agent process using CLI values first, then environment values, then CLI defaults.
|
|
18
19
|
*/
|
|
19
20
|
function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allowAll }) {
|
|
20
|
-
const resolvedPort = port ?? node_process.env.PORT ?? require_constants.agentDefaults.port;
|
|
21
|
-
const resolvedHost = host !== require_constants.agentDefaults.host ? host : node_process.env.HOST ?? require_constants.agentDefaults.host;
|
|
22
|
-
const resolvedAllowAll = allowAll || node_process.env.KUBB_AGENT_ALLOW_ALL === "true";
|
|
23
|
-
const resolvedAllowWrite = resolvedAllowAll || allowWrite || node_process.env.KUBB_AGENT_ALLOW_WRITE === "true";
|
|
24
|
-
const agentRoot = node_process.env.KUBB_AGENT_ROOT ?? node_process.cwd();
|
|
25
|
-
const agentConfigPath = node_path.default.resolve(node_process.cwd(), configPath || node_process.env.KUBB_AGENT_CONFIG || require_constants.agentDefaults.configFile);
|
|
21
|
+
const resolvedPort = port ?? node_process.default.env.PORT ?? require_constants.agentDefaults.port;
|
|
22
|
+
const resolvedHost = host !== require_constants.agentDefaults.host ? host : node_process.default.env.HOST ?? require_constants.agentDefaults.host;
|
|
23
|
+
const resolvedAllowAll = allowAll || node_process.default.env.KUBB_AGENT_ALLOW_ALL === "true";
|
|
24
|
+
const resolvedAllowWrite = resolvedAllowAll || allowWrite || node_process.default.env.KUBB_AGENT_ALLOW_WRITE === "true";
|
|
25
|
+
const agentRoot = node_process.default.env.KUBB_AGENT_ROOT ?? node_process.default.cwd();
|
|
26
|
+
const agentConfigPath = node_path.default.resolve(node_process.default.cwd(), configPath || node_process.default.env.KUBB_AGENT_CONFIG || require_constants.agentDefaults.configFile);
|
|
26
27
|
return {
|
|
27
28
|
port: resolvedPort,
|
|
28
29
|
host: resolvedHost,
|
|
@@ -30,16 +31,16 @@ function resolveAgentStartEnvironment({ port, host, configPath, allowWrite, allo
|
|
|
30
31
|
allowAll: resolvedAllowAll,
|
|
31
32
|
agentConfigPath,
|
|
32
33
|
env: {
|
|
33
|
-
...node_process.env,
|
|
34
|
+
...node_process.default.env,
|
|
34
35
|
PORT: resolvedPort,
|
|
35
36
|
HOST: resolvedHost,
|
|
36
37
|
KUBB_AGENT_ROOT: agentRoot,
|
|
37
38
|
KUBB_AGENT_CONFIG: agentConfigPath,
|
|
38
39
|
KUBB_AGENT_ALLOW_WRITE: String(resolvedAllowWrite),
|
|
39
40
|
KUBB_AGENT_ALLOW_ALL: String(resolvedAllowAll),
|
|
40
|
-
KUBB_AGENT_TOKEN: node_process.env.KUBB_AGENT_TOKEN,
|
|
41
|
-
KUBB_AGENT_RETRY_TIMEOUT: node_process.env.KUBB_AGENT_RETRY_TIMEOUT ?? require_constants.agentDefaults.retryTimeout,
|
|
42
|
-
KUBB_STUDIO_URL: node_process.env.KUBB_STUDIO_URL ?? require_constants.agentDefaults.studioUrl
|
|
41
|
+
KUBB_AGENT_TOKEN: node_process.default.env.KUBB_AGENT_TOKEN,
|
|
42
|
+
KUBB_AGENT_RETRY_TIMEOUT: node_process.default.env.KUBB_AGENT_RETRY_TIMEOUT ?? require_constants.agentDefaults.retryTimeout,
|
|
43
|
+
KUBB_STUDIO_URL: node_process.default.env.KUBB_STUDIO_URL ?? require_constants.agentDefaults.studioUrl
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
}
|
|
@@ -54,20 +55,38 @@ function isPortAvailable(port, host) {
|
|
|
54
55
|
server.listen(port, host);
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/runners/agent/run.ts
|
|
60
|
+
/**
|
|
61
|
+
* Spawns the Kubb Agent HTTP server as a Node.js subprocess.
|
|
62
|
+
* Resolves config from CLI flags and environment variables, validates the port, and exits with code 1 on failure.
|
|
63
|
+
*/
|
|
64
|
+
async function run({ port, host, configPath, allowWrite, allowAll, version }) {
|
|
65
|
+
const hrStart = node_process.default.hrtime();
|
|
66
|
+
const report = (status) => require_telemetry.sendTelemetry(require_telemetry.buildTelemetryEvent({
|
|
67
|
+
command: "agent",
|
|
68
|
+
kubbVersion: version,
|
|
69
|
+
hrStart,
|
|
70
|
+
status
|
|
71
|
+
}));
|
|
59
72
|
try {
|
|
60
73
|
try {
|
|
61
|
-
node_process.loadEnvFile();
|
|
74
|
+
node_process.default.loadEnvFile();
|
|
62
75
|
} catch {}
|
|
63
|
-
|
|
76
|
+
const require = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
77
|
+
let agentPkgPath;
|
|
64
78
|
try {
|
|
65
|
-
|
|
79
|
+
agentPkgPath = require.resolve("@kubb/agent/package.json");
|
|
66
80
|
} catch (_e) {
|
|
67
|
-
console.error(
|
|
68
|
-
|
|
81
|
+
console.error((0, node_util.styleText)("red", "The @kubb/agent package is not installed."));
|
|
82
|
+
console.error("");
|
|
83
|
+
console.error("Install it with:");
|
|
84
|
+
console.error((0, node_util.styleText)("cyan", " npm install @kubb/agent"));
|
|
85
|
+
console.error((0, node_util.styleText)("cyan", " # or"));
|
|
86
|
+
console.error((0, node_util.styleText)("cyan", " pnpm install @kubb/agent"));
|
|
87
|
+
console.error("");
|
|
88
|
+
node_process.default.exit(1);
|
|
69
89
|
}
|
|
70
|
-
const agentPkgPath = (0, node_url.fileURLToPath)(agentPkgUrl);
|
|
71
90
|
const agentDir = node_path.default.dirname(agentPkgPath);
|
|
72
91
|
const serverPath = node_path.default.join(agentDir, require_constants.agentDefaults.serverEntryPath);
|
|
73
92
|
const resolvedEnv = resolveAgentStartEnvironment({
|
|
@@ -86,31 +105,21 @@ async function runAgentStart({ port, host, configPath, allowWrite, allowAll, ver
|
|
|
86
105
|
if (!resolvedEnv.allowWrite && !resolvedEnv.allowAll) _clack_prompts.log.warn((0, node_util.styleText)("yellow", "Filesystem writes disabled. Use --allow-write or --allow-all to enable."));
|
|
87
106
|
if (!await isPortAvailable(numericPort, resolvedEnv.host)) {
|
|
88
107
|
_clack_prompts.log.error((0, node_util.styleText)("red", `Port ${resolvedEnv.port} is already in use. Stop the existing process or choose a different port with --port.`));
|
|
89
|
-
node_process.exit(1);
|
|
108
|
+
node_process.default.exit(1);
|
|
90
109
|
}
|
|
91
110
|
await require_shell.spawnAsync("node", [serverPath], {
|
|
92
111
|
env: resolvedEnv.env,
|
|
93
|
-
cwd: node_process.cwd()
|
|
112
|
+
cwd: node_process.default.cwd()
|
|
94
113
|
});
|
|
95
|
-
await
|
|
96
|
-
command: "agent",
|
|
97
|
-
kubbVersion: version,
|
|
98
|
-
hrStart,
|
|
99
|
-
status: "success"
|
|
100
|
-
}));
|
|
114
|
+
await report("success");
|
|
101
115
|
} catch (error) {
|
|
102
|
-
await
|
|
103
|
-
command: "agent",
|
|
104
|
-
kubbVersion: version,
|
|
105
|
-
hrStart,
|
|
106
|
-
status: "failed"
|
|
107
|
-
}));
|
|
116
|
+
await report("failed");
|
|
108
117
|
_clack_prompts.log.error((0, node_util.styleText)("red", "Failed to start agent server"));
|
|
109
|
-
|
|
110
|
-
node_process.exit(1);
|
|
118
|
+
_clack_prompts.log.error(require_errors.getErrorMessage(error));
|
|
119
|
+
node_process.default.exit(1);
|
|
111
120
|
}
|
|
112
121
|
}
|
|
113
122
|
//#endregion
|
|
114
|
-
exports.
|
|
123
|
+
exports.run = run;
|
|
115
124
|
|
|
116
|
-
//# sourceMappingURL=
|
|
125
|
+
//# sourceMappingURL=run-DwdAwnLG.cjs.map
|