@kubb/cli 5.0.0-alpha.9 → 5.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -27
- package/bin/kubb.js +6 -0
- package/dist/agent-Bx2yllmS.js +68 -0
- package/dist/agent-Bx2yllmS.js.map +1 -0
- package/dist/agent-CeLwj5im.cjs +70 -0
- package/dist/agent-CeLwj5im.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 +54 -0
- package/dist/define-Bdn8j5VM.cjs.map +1 -0
- package/dist/define-m_fp-Aqm.js +43 -0
- package/dist/define-m_fp-Aqm.js.map +1 -0
- package/dist/errors-CINO1EIv.js +43 -0
- package/dist/errors-CINO1EIv.js.map +1 -0
- package/dist/{errors-DBW0N9w4.cjs → errors-CLCjoSg0.cjs} +22 -6
- package/dist/errors-CLCjoSg0.cjs.map +1 -0
- package/dist/{generate-Rly1EXBN.js → generate-BLvcvoIj.js} +12 -6
- package/dist/generate-BLvcvoIj.js.map +1 -0
- package/dist/{generate-DU5zzc54.cjs → generate-drLxTAnz.cjs} +11 -5
- package/dist/generate-drLxTAnz.cjs.map +1 -0
- package/dist/index.cjs +52 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +53 -22
- package/dist/index.js.map +1 -1
- package/dist/init-CGu7JZEF.js +53 -0
- package/dist/init-CGu7JZEF.js.map +1 -0
- package/dist/init-CyCjvIEF.cjs +53 -0
- package/dist/init-CyCjvIEF.cjs.map +1 -0
- package/dist/mcp-Cq2sylQC.js +39 -0
- package/dist/mcp-Cq2sylQC.js.map +1 -0
- package/dist/mcp-DSF5gpI-.cjs +39 -0
- package/dist/mcp-DSF5gpI-.cjs.map +1 -0
- package/dist/{package-BJ6ionm6.cjs → package-DZ-6zAIO.cjs} +2 -2
- package/dist/package-DZ-6zAIO.cjs.map +1 -0
- package/dist/package-OLYIpjqw.js +6 -0
- package/dist/package-OLYIpjqw.js.map +1 -0
- package/dist/{generate-BHNyeQXl.js → run-Bfbr3RaM.js} +781 -502
- package/dist/run-Bfbr3RaM.js.map +1 -0
- package/dist/run-BzpYYOQs.js +121 -0
- 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/run-CF97BWVa.js +244 -0
- 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/{generate-Cq5RDTBL.cjs → run-CVlrIZoW.cjs} +786 -507
- package/dist/run-CVlrIZoW.cjs.map +1 -0
- package/dist/run-D0hmRpHy.js +49 -0
- package/dist/run-D0hmRpHy.js.map +1 -0
- package/dist/run-DwdAwnLG.cjs +125 -0
- 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/run-YsoCk5we.cjs +248 -0
- package/dist/run-YsoCk5we.cjs.map +1 -0
- package/dist/{shell-7HPrTCJ5.cjs → shell-475fQKaX.cjs} +8 -3
- package/dist/shell-475fQKaX.cjs.map +1 -0
- package/dist/{shell-DqqWsHCD.js → shell-CN6DNqeC.js} +9 -4
- package/dist/shell-CN6DNqeC.js.map +1 -0
- package/dist/{telemetry-DZ7IrLAU.cjs → telemetry-B2iWkY5e.cjs} +53 -13
- package/dist/telemetry-B2iWkY5e.cjs.map +1 -0
- package/dist/{telemetry-BF3SMlH6.js → telemetry-BkektVz6.js} +52 -12
- package/dist/telemetry-BkektVz6.js.map +1 -0
- package/dist/validate-CAUqLaGt.js +26 -0
- package/dist/validate-CAUqLaGt.js.map +1 -0
- package/dist/validate-J6AEd5zK.cjs +26 -0
- package/dist/validate-J6AEd5zK.cjs.map +1 -0
- package/package.json +57 -48
- package/src/commands/agent/start.ts +27 -8
- package/src/commands/agent.ts +3 -1
- package/src/commands/generate.ts +39 -8
- package/src/commands/init.ts +40 -4
- package/src/commands/mcp.ts +28 -4
- package/src/commands/validate.ts +11 -4
- package/src/constants.ts +5 -80
- package/src/index.ts +12 -13
- package/src/loggers/clackLogger.ts +98 -88
- package/src/loggers/fileSystemLogger.ts +37 -25
- package/src/loggers/githubActionsLogger.ts +35 -48
- package/src/loggers/plainLogger.ts +33 -45
- 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} +28 -8
- package/bin/kubb.cjs +0 -18
- package/dist/agent-5mmp7QzF.js +0 -56
- package/dist/agent-5mmp7QzF.js.map +0 -1
- package/dist/agent-BKphjOIF.cjs +0 -58
- package/dist/agent-BKphjOIF.cjs.map +0 -1
- package/dist/agent-BapvKB4r.cjs +0 -92
- package/dist/agent-BapvKB4r.cjs.map +0 -1
- package/dist/agent-CBrpIMMU.js +0 -88
- package/dist/agent-CBrpIMMU.js.map +0 -1
- package/dist/constants-D0XHAHeZ.cjs +0 -178
- package/dist/constants-D0XHAHeZ.cjs.map +0 -1
- package/dist/constants-DJM9zCXm.js +0 -131
- package/dist/constants-DJM9zCXm.js.map +0 -1
- package/dist/define--M_JMcDC.js +0 -25
- package/dist/define--M_JMcDC.js.map +0 -1
- package/dist/define-D6Kfm7-Z.cjs +0 -36
- package/dist/define-D6Kfm7-Z.cjs.map +0 -1
- package/dist/errors-6mF_WKxg.js +0 -27
- package/dist/errors-6mF_WKxg.js.map +0 -1
- package/dist/errors-DBW0N9w4.cjs.map +0 -1
- package/dist/generate-BHNyeQXl.js.map +0 -1
- package/dist/generate-Cq5RDTBL.cjs.map +0 -1
- package/dist/generate-DU5zzc54.cjs.map +0 -1
- package/dist/generate-Rly1EXBN.js.map +0 -1
- package/dist/init-BK6inBTR.cjs +0 -306
- package/dist/init-BK6inBTR.cjs.map +0 -1
- package/dist/init-BQ6zfsnw.js +0 -302
- package/dist/init-BQ6zfsnw.js.map +0 -1
- package/dist/init-CN1JFyGX.cjs +0 -25
- package/dist/init-CN1JFyGX.cjs.map +0 -1
- package/dist/init-iN7e1XwI.js +0 -25
- package/dist/init-iN7e1XwI.js.map +0 -1
- package/dist/jiti-Cd3S0xwr.cjs +0 -16
- package/dist/jiti-Cd3S0xwr.cjs.map +0 -1
- package/dist/jiti-e08mD2Ph.js +0 -11
- package/dist/jiti-e08mD2Ph.js.map +0 -1
- package/dist/mcp-BiGUvbWP.js +0 -41
- package/dist/mcp-BiGUvbWP.js.map +0 -1
- package/dist/mcp-CONmm_xT.cjs +0 -42
- package/dist/mcp-CONmm_xT.cjs.map +0 -1
- package/dist/mcp-T7Q4nWbT.cjs +0 -16
- package/dist/mcp-T7Q4nWbT.cjs.map +0 -1
- package/dist/mcp-eP1S40LZ.js +0 -16
- package/dist/mcp-eP1S40LZ.js.map +0 -1
- package/dist/package-BJ6ionm6.cjs.map +0 -1
- package/dist/package-BKZ0H3Zf.js +0 -6
- package/dist/package-BKZ0H3Zf.js.map +0 -1
- package/dist/shell-7HPrTCJ5.cjs.map +0 -1
- package/dist/shell-DqqWsHCD.js.map +0 -1
- package/dist/telemetry-BF3SMlH6.js.map +0 -1
- package/dist/telemetry-DZ7IrLAU.cjs.map +0 -1
- package/dist/validate-BImbbx1t.js +0 -41
- package/dist/validate-BImbbx1t.js.map +0 -1
- package/dist/validate-DAZdX_0i.js +0 -25
- package/dist/validate-DAZdX_0i.js.map +0 -1
- package/dist/validate-DucFMytl.cjs +0 -25
- package/dist/validate-DucFMytl.cjs.map +0 -1
- package/dist/validate-ujLCYSWU.cjs +0 -42
- package/dist/validate-ujLCYSWU.cjs.map +0 -1
- package/src/runners/agent.ts +0 -102
- package/src/runners/generate.ts +0 -343
- package/src/runners/init.ts +0 -323
- package/src/runners/mcp.ts +0 -32
- package/src/runners/validate.ts +0 -35
- 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 -10
- package/src/utils/getCosmiConfig.ts +0 -71
- package/src/utils/getSummary.ts +0 -68
- package/src/utils/jiti.ts +0 -9
- package/src/utils/runHook.ts +0 -75
- package/src/utils/watcher.ts +0 -19
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
|
+
const require_shell = require("./shell-475fQKaX.cjs");
|
|
3
|
+
const require_constants = require("./constants-BYGmiFs0.cjs");
|
|
4
|
+
let node_util = require("node:util");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
node_fs = require_chunk.__toESM(node_fs, 1);
|
|
7
|
+
let node_path = require("node:path");
|
|
8
|
+
node_path = require_chunk.__toESM(node_path, 1);
|
|
9
|
+
let node_process = require("node:process");
|
|
10
|
+
node_process = require_chunk.__toESM(node_process, 1);
|
|
11
|
+
let _clack_prompts = require("@clack/prompts");
|
|
12
|
+
_clack_prompts = require_chunk.__toESM(_clack_prompts, 1);
|
|
13
|
+
//#region ../../internals/utils/src/packageManager.ts
|
|
14
|
+
/**
|
|
15
|
+
* Metadata for each supported package manager, keyed by its short name.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* packageManagers.pnpm.installCommand // ['add', '-D']
|
|
20
|
+
* packageManagers.npm.lockFile // 'package-lock.json'
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const packageManagers = {
|
|
24
|
+
pnpm: {
|
|
25
|
+
name: "pnpm",
|
|
26
|
+
lockFile: "pnpm-lock.yaml",
|
|
27
|
+
installCommand: ["add", "-D"]
|
|
28
|
+
},
|
|
29
|
+
yarn: {
|
|
30
|
+
name: "yarn",
|
|
31
|
+
lockFile: "yarn.lock",
|
|
32
|
+
installCommand: ["add", "-D"]
|
|
33
|
+
},
|
|
34
|
+
bun: {
|
|
35
|
+
name: "bun",
|
|
36
|
+
lockFile: "bun.lockb",
|
|
37
|
+
installCommand: ["add", "-d"]
|
|
38
|
+
},
|
|
39
|
+
npm: {
|
|
40
|
+
name: "npm",
|
|
41
|
+
lockFile: "package-lock.json",
|
|
42
|
+
installCommand: ["install", "--save-dev"]
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Detects the active package manager for the given directory.
|
|
47
|
+
* Resolution order: `packageManager` field in `package.json`, then presence of a lock file.
|
|
48
|
+
* Falls back to `npm` when no signal is found.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* detectPackageManager('/my/project') // { name: 'pnpm', lockFile: 'pnpm-lock.yaml', ... }
|
|
53
|
+
* detectPackageManager() // falls back to npm when no lock file is found
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function detectPackageManager(cwd = process.cwd()) {
|
|
57
|
+
const packageJsonPath = (0, node_path.join)(cwd, "package.json");
|
|
58
|
+
if ((0, node_fs.existsSync)(packageJsonPath)) try {
|
|
59
|
+
const pmField = JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf-8")).packageManager;
|
|
60
|
+
if (typeof pmField === "string") {
|
|
61
|
+
const name = pmField.split("@")[0];
|
|
62
|
+
if (name && name in packageManagers) return packageManagers[name];
|
|
63
|
+
}
|
|
64
|
+
} catch {}
|
|
65
|
+
for (const pm of Object.values(packageManagers)) if ((0, node_fs.existsSync)((0, node_path.join)(cwd, pm.lockFile))) return pm;
|
|
66
|
+
return packageManagers.npm;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region ../../internals/shared/src/init.ts
|
|
70
|
+
function generateConfigFile({ selectedPlugins, inputPath, outputPath }) {
|
|
71
|
+
return `import { defineConfig } from 'kubb'
|
|
72
|
+
${selectedPlugins.map((plugin) => `import { ${plugin.importName} } from '${plugin.packageName}'`).join("\n")}
|
|
73
|
+
|
|
74
|
+
export default defineConfig({
|
|
75
|
+
root: '.',
|
|
76
|
+
input: {
|
|
77
|
+
path: '${inputPath}',
|
|
78
|
+
},
|
|
79
|
+
output: {
|
|
80
|
+
path: '${outputPath}',
|
|
81
|
+
clean: true,
|
|
82
|
+
},
|
|
83
|
+
plugins: [
|
|
84
|
+
${selectedPlugins.map((plugin) => {
|
|
85
|
+
return ` ${require_constants.pluginDefaultConfigs[plugin.value] ?? `${plugin.importName}()`},`;
|
|
86
|
+
}).join("\n")}
|
|
87
|
+
],
|
|
88
|
+
})
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/runners/init/utils.ts
|
|
93
|
+
/**
|
|
94
|
+
* Returns `true` when a `package.json` exists at `cwd`.
|
|
95
|
+
*/
|
|
96
|
+
function hasPackageJson(cwd = node_process.default.cwd()) {
|
|
97
|
+
return node_fs.default.existsSync(node_path.default.join(cwd, "package.json"));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Initializes a new `package.json` at `cwd` using the detected package manager.
|
|
101
|
+
*/
|
|
102
|
+
async function initPackageJson(cwd, packageManager) {
|
|
103
|
+
await require_shell.spawnAsync(packageManager.name, {
|
|
104
|
+
npm: ["init", "-y"],
|
|
105
|
+
pnpm: ["init"],
|
|
106
|
+
yarn: ["init", "-y"],
|
|
107
|
+
bun: ["init", "-y"]
|
|
108
|
+
}[packageManager.name], { cwd });
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Installs the given packages at `cwd` using the detected package manager.
|
|
112
|
+
*/
|
|
113
|
+
async function installPackages(packages, packageManager, cwd = node_process.default.cwd()) {
|
|
114
|
+
await require_shell.spawnAsync(packageManager.name, [...packageManager.installCommand, ...packages], { cwd });
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/runners/init/run.ts
|
|
118
|
+
function cancelAndExit(message = "Operation cancelled.") {
|
|
119
|
+
_clack_prompts.cancel(message);
|
|
120
|
+
node_process.default.exit(0);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Runs the interactive Kubb scaffolding wizard.
|
|
124
|
+
* Detects the package manager, prompts for input/output paths and plugins, installs packages, and writes `kubb.config.ts`.
|
|
125
|
+
* Pass `yes: true` to skip all prompts and use defaults.
|
|
126
|
+
*/
|
|
127
|
+
async function run({ yes, version, input: inputFlag, output: outputFlag, plugins: pluginsFlag }) {
|
|
128
|
+
const cwd = node_process.default.cwd();
|
|
129
|
+
_clack_prompts.intro((0, node_util.styleText)("bgCyan", (0, node_util.styleText)("black", " Kubb Init ")));
|
|
130
|
+
/**
|
|
131
|
+
* Returns `flag` when provided, the `defaultValue` when `yes` is set,
|
|
132
|
+
* or calls `prompt()` for interactive input. Exits on cancellation.
|
|
133
|
+
*/
|
|
134
|
+
async function resolveOrPrompt(flag, defaultValue, logLabel, prompt) {
|
|
135
|
+
if (flag !== void 0) {
|
|
136
|
+
_clack_prompts.log.info(`${logLabel}: ${(0, node_util.styleText)("cyan", String(flag))}`);
|
|
137
|
+
return flag;
|
|
138
|
+
}
|
|
139
|
+
if (yes) {
|
|
140
|
+
_clack_prompts.log.info(`${logLabel}: ${(0, node_util.styleText)("cyan", String(defaultValue))}`);
|
|
141
|
+
return defaultValue;
|
|
142
|
+
}
|
|
143
|
+
const result = await prompt();
|
|
144
|
+
if (_clack_prompts.isCancel(result)) cancelAndExit();
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
if (!hasPackageJson(cwd)) {
|
|
149
|
+
if (!yes) {
|
|
150
|
+
const shouldInit = await _clack_prompts.confirm({
|
|
151
|
+
message: "No package.json found. Would you like to create one?",
|
|
152
|
+
initialValue: true
|
|
153
|
+
});
|
|
154
|
+
if (_clack_prompts.isCancel(shouldInit) || !shouldInit) cancelAndExit();
|
|
155
|
+
}
|
|
156
|
+
const packageManager = detectPackageManager(cwd);
|
|
157
|
+
const spinner = _clack_prompts.spinner();
|
|
158
|
+
spinner.start(`Initializing package.json with ${packageManager.name}`);
|
|
159
|
+
await initPackageJson(cwd, packageManager);
|
|
160
|
+
spinner.stop(`Created package.json with ${packageManager.name}`);
|
|
161
|
+
}
|
|
162
|
+
const packageManager = detectPackageManager(cwd);
|
|
163
|
+
if (hasPackageJson(cwd)) _clack_prompts.log.info(`Detected package manager: ${(0, node_util.styleText)("cyan", packageManager.name)}`);
|
|
164
|
+
const inputPath = await resolveOrPrompt(inputFlag, require_constants.initDefaults.inputPath, "Using input path", () => _clack_prompts.text({
|
|
165
|
+
message: "Where is your OpenAPI specification located?",
|
|
166
|
+
placeholder: require_constants.initDefaults.inputPath,
|
|
167
|
+
defaultValue: require_constants.initDefaults.inputPath,
|
|
168
|
+
validate: (value) => {
|
|
169
|
+
if (!value) return "Input path is required";
|
|
170
|
+
}
|
|
171
|
+
}));
|
|
172
|
+
const outputPath = await resolveOrPrompt(outputFlag, require_constants.initDefaults.outputPath, "Using output path", () => _clack_prompts.text({
|
|
173
|
+
message: "Where should the generated files be output?",
|
|
174
|
+
placeholder: require_constants.initDefaults.outputPath,
|
|
175
|
+
defaultValue: require_constants.initDefaults.outputPath,
|
|
176
|
+
validate: (value) => {
|
|
177
|
+
if (!value) return "Output path is required";
|
|
178
|
+
}
|
|
179
|
+
}));
|
|
180
|
+
const defaultPlugins = require_constants.availablePlugins.filter((p) => require_constants.initDefaults.plugins.includes(p.value));
|
|
181
|
+
const pluginLabel = (plugins) => (0, node_util.styleText)("cyan", plugins.map((p) => p.label).join(", "));
|
|
182
|
+
let selectedPlugins;
|
|
183
|
+
if (pluginsFlag) {
|
|
184
|
+
const requested = pluginsFlag.split(",").map((v) => v.trim()).filter(Boolean);
|
|
185
|
+
selectedPlugins = require_constants.availablePlugins.filter((p) => requested.includes(p.value));
|
|
186
|
+
if (selectedPlugins.length === 0) {
|
|
187
|
+
selectedPlugins = defaultPlugins;
|
|
188
|
+
_clack_prompts.log.warn(`No valid plugins found in --plugins value; falling back to default: ${pluginLabel(defaultPlugins)}`);
|
|
189
|
+
} else _clack_prompts.log.info(`Using plugins: ${pluginLabel(selectedPlugins)}`);
|
|
190
|
+
} else if (yes) {
|
|
191
|
+
selectedPlugins = defaultPlugins;
|
|
192
|
+
_clack_prompts.log.info(`Using plugins: ${pluginLabel(defaultPlugins)}`);
|
|
193
|
+
} else {
|
|
194
|
+
const values = await _clack_prompts.multiselect({
|
|
195
|
+
message: "Select plugins to use:",
|
|
196
|
+
options: require_constants.availablePlugins.map(({ value, label, hint }) => ({
|
|
197
|
+
value,
|
|
198
|
+
label,
|
|
199
|
+
hint
|
|
200
|
+
})),
|
|
201
|
+
initialValues: [...require_constants.initDefaults.plugins],
|
|
202
|
+
required: true
|
|
203
|
+
});
|
|
204
|
+
if (_clack_prompts.isCancel(values)) cancelAndExit();
|
|
205
|
+
selectedPlugins = require_constants.availablePlugins.filter((p) => values.includes(p.value));
|
|
206
|
+
}
|
|
207
|
+
const packagesToInstall = ["kubb", ...selectedPlugins.map((p) => p.packageName)];
|
|
208
|
+
const spinner = _clack_prompts.spinner();
|
|
209
|
+
spinner.start(`Installing ${packagesToInstall.length} packages with ${packageManager.name}`);
|
|
210
|
+
try {
|
|
211
|
+
await installPackages(packagesToInstall, packageManager, cwd);
|
|
212
|
+
spinner.stop(`Installed ${packagesToInstall.length} packages`);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
spinner.stop("Installation failed");
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
const configSpinner = _clack_prompts.spinner();
|
|
218
|
+
configSpinner.start(`Creating ${require_constants.KUBB_CONFIG_FILENAME}`);
|
|
219
|
+
const configContent = generateConfigFile({
|
|
220
|
+
selectedPlugins,
|
|
221
|
+
inputPath,
|
|
222
|
+
outputPath
|
|
223
|
+
});
|
|
224
|
+
const configPath = node_path.default.join(cwd, require_constants.KUBB_CONFIG_FILENAME);
|
|
225
|
+
if (node_fs.default.existsSync(configPath)) {
|
|
226
|
+
configSpinner.stop(`${require_constants.KUBB_CONFIG_FILENAME} already exists`);
|
|
227
|
+
if (!yes) {
|
|
228
|
+
const shouldOverwrite = await _clack_prompts.confirm({
|
|
229
|
+
message: `${require_constants.KUBB_CONFIG_FILENAME} already exists. Overwrite?`,
|
|
230
|
+
initialValue: false
|
|
231
|
+
});
|
|
232
|
+
if (_clack_prompts.isCancel(shouldOverwrite) || !shouldOverwrite) cancelAndExit("Keeping existing configuration. Packages have been installed.");
|
|
233
|
+
}
|
|
234
|
+
configSpinner.start(`Overwriting ${require_constants.KUBB_CONFIG_FILENAME}`);
|
|
235
|
+
}
|
|
236
|
+
await node_fs.default.promises.writeFile(configPath, configContent, "utf-8");
|
|
237
|
+
configSpinner.stop(`Created ${require_constants.KUBB_CONFIG_FILENAME}`);
|
|
238
|
+
_clack_prompts.outro((0, node_util.styleText)("green", "✓ All set!") + "\n\n" + (0, node_util.styleText)("dim", "Next steps:") + "\n" + (0, node_util.styleText)("cyan", ` 1. Make sure your OpenAPI spec is at: ${inputPath}`) + "\n" + (0, node_util.styleText)("cyan", " 2. Generate code with: npx kubb generate") + "\n" + (0, node_util.styleText)("cyan", " Or start a stream server with: npx kubb agent start") + "\n" + (0, node_util.styleText)("cyan", ` 3. Find generated files in: ${outputPath}`) + "\n\n" + (0, node_util.styleText)("dim", `Using ${packageManager.name} • Kubb v${version}`));
|
|
239
|
+
} catch (error) {
|
|
240
|
+
_clack_prompts.log.error((0, node_util.styleText)("red", "An error occurred during initialization"));
|
|
241
|
+
if (error instanceof Error) _clack_prompts.log.error(error.message);
|
|
242
|
+
node_process.default.exit(1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
exports.run = run;
|
|
247
|
+
|
|
248
|
+
//# sourceMappingURL=run-YsoCk5we.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-YsoCk5we.cjs","names":["pluginDefaultConfigs","process","fs","path","spawnAsync","process","clack","initDefaults","availablePlugins","KUBB_CONFIG_FILENAME","path","fs"],"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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AK,WAAWF,kBAAAA,uBAAuB;EAErD,eAAM,OAAA,GAAA,UAAA,WACM,SAAS,aAAa,GAC9B,UAAA,GAAA,UAAA,WACU,OAAO,cAAc,GAC/B,QAAA,GAAA,UAAA,WACU,QAAQ,2CAA2C,YAAY,GACzE,QAAA,GAAA,UAAA,WACU,QAAQ,6CAA6C,GAC/D,QAAA,GAAA,UAAA,WACU,QAAQ,2DAA2D,GAC7E,QAAA,GAAA,UAAA,WACU,QAAQ,iCAAiC,aAAa,GAChE,UAAA,GAAA,UAAA,WACU,OAAO,SAAS,eAAe,KAAK,WAAW,UAAU,CACtE;UACM,OAAO;EACd,eAAM,IAAI,OAAA,GAAA,UAAA,WAAgB,OAAO,0CAA0C,CAAC;EAC5E,IAAI,iBAAiB,OACnB,eAAM,IAAI,MAAM,MAAM,QAAQ;EAEhC,aAAA,QAAQ,KAAK,EAAE"}
|
|
@@ -15,8 +15,13 @@ function tokenize(command) {
|
|
|
15
15
|
* Spawns `cmd` with `args` and returns a promise that settles when the child process finishes.
|
|
16
16
|
*
|
|
17
17
|
* Foreground mode (default) inherits the parent's stdio and rejects on non-zero exit or signal.
|
|
18
|
-
* Detached mode spawns the child in its own process group, unref's it, and resolves immediately
|
|
19
|
-
*
|
|
18
|
+
* Detached mode spawns the child in its own process group, unref's it, and resolves immediately.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* await spawnAsync('pnpm', ['install'])
|
|
23
|
+
* await spawnAsync('node', ['server.js'], { detached: true }) // fire-and-forget
|
|
24
|
+
* ```
|
|
20
25
|
*/
|
|
21
26
|
function spawnAsync(cmd, args, options = {}) {
|
|
22
27
|
const { cwd = process.cwd(), env, detached = false } = options;
|
|
@@ -54,4 +59,4 @@ Object.defineProperty(exports, "tokenize", {
|
|
|
54
59
|
}
|
|
55
60
|
});
|
|
56
61
|
|
|
57
|
-
//# sourceMappingURL=shell-
|
|
62
|
+
//# sourceMappingURL=shell-475fQKaX.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-475fQKaX.cjs","names":[],"sources":["../../../internals/utils/src/shell.ts"],"sourcesContent":["import { spawn } from 'node:child_process'\n\n/**\n * Tokenizes a shell command string, respecting single and double quotes.\n *\n * @example\n * tokenize('git commit -m \"initial commit\"')\n * // → ['git', 'commit', '-m', 'initial commit']\n */\nexport function tokenize(command: string): string[] {\n return (command.match(/[^\\s\"']+|\"([^\"]*)\"|'([^']*)'/g) ?? []).map((token) => token.replace(/^[\"']|[\"']$/g, ''))\n}\n\ntype SpawnOptions = {\n /**\n * Working directory for the child process.\n * @default process.cwd()\n */\n cwd?: string\n /**\n * Environment variables passed to the child process.\n * @default process.env\n */\n env?: NodeJS.ProcessEnv\n /**\n * When `true`, spawns a detached background process and resolves immediately.\n * The child is unref'd so the parent process can exit independently.\n * @default false\n */\n detached?: boolean\n}\n\n/**\n * Spawns `cmd` with `args` and returns a promise that settles when the child process finishes.\n *\n * Foreground mode (default) inherits the parent's stdio and rejects on non-zero exit or signal.\n * Detached mode spawns the child in its own process group, unref's it, and resolves immediately.\n *\n * @example\n * ```ts\n * await spawnAsync('pnpm', ['install'])\n * await spawnAsync('node', ['server.js'], { detached: true }) // fire-and-forget\n * ```\n */\nexport function spawnAsync(cmd: string, args: string[], options: SpawnOptions = {}): Promise<void> {\n const { cwd = process.cwd(), env, detached = false } = options\n\n return new Promise((resolve, reject) => {\n const child = spawn(cmd, args, {\n stdio: detached ? 'ignore' : 'inherit',\n cwd,\n env,\n detached,\n })\n\n if (detached) {\n child.unref()\n resolve()\n return\n }\n\n child.on('close', (code, signal) => {\n if (code === 0) {\n resolve()\n } else if (signal !== null) {\n reject(new Error(`\"${cmd} ${args.join(' ')}\" was terminated by signal ${signal}`))\n } else {\n reject(new Error(`\"${cmd} ${args.join(' ')}\" exited with code ${code}`))\n }\n })\n child.on('error', reject)\n })\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,SAAS,SAA2B;CAClD,QAAQ,QAAQ,MAAM,gCAAgC,IAAI,EAAE,EAAE,KAAK,UAAU,MAAM,QAAQ,gBAAgB,GAAG,CAAC;;;;;;;;;;;;;;AAkCjH,SAAgB,WAAW,KAAa,MAAgB,UAAwB,EAAE,EAAiB;CACjG,MAAM,EAAE,MAAM,QAAQ,KAAK,EAAE,KAAK,WAAW,UAAU;CAEvD,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,SAAA,GAAA,mBAAA,OAAc,KAAK,MAAM;GAC7B,OAAO,WAAW,WAAW;GAC7B;GACA;GACA;GACD,CAAC;EAEF,IAAI,UAAU;GACZ,MAAM,OAAO;GACb,SAAS;GACT;;EAGF,MAAM,GAAG,UAAU,MAAM,WAAW;GAClC,IAAI,SAAS,GACX,SAAS;QACJ,IAAI,WAAW,MACpB,uBAAO,IAAI,MAAM,IAAI,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,6BAA6B,SAAS,CAAC;QAElF,uBAAO,IAAI,MAAM,IAAI,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,qBAAqB,OAAO,CAAC;IAE1E;EACF,MAAM,GAAG,SAAS,OAAO;GACzB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./chunk
|
|
1
|
+
import "./chunk-BvFE5Tac.js";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
//#region ../../internals/utils/src/shell.ts
|
|
4
4
|
/**
|
|
@@ -15,8 +15,13 @@ function tokenize(command) {
|
|
|
15
15
|
* Spawns `cmd` with `args` and returns a promise that settles when the child process finishes.
|
|
16
16
|
*
|
|
17
17
|
* Foreground mode (default) inherits the parent's stdio and rejects on non-zero exit or signal.
|
|
18
|
-
* Detached mode spawns the child in its own process group, unref's it, and resolves immediately
|
|
19
|
-
*
|
|
18
|
+
* Detached mode spawns the child in its own process group, unref's it, and resolves immediately.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* await spawnAsync('pnpm', ['install'])
|
|
23
|
+
* await spawnAsync('node', ['server.js'], { detached: true }) // fire-and-forget
|
|
24
|
+
* ```
|
|
20
25
|
*/
|
|
21
26
|
function spawnAsync(cmd, args, options = {}) {
|
|
22
27
|
const { cwd = process.cwd(), env, detached = false } = options;
|
|
@@ -43,4 +48,4 @@ function spawnAsync(cmd, args, options = {}) {
|
|
|
43
48
|
//#endregion
|
|
44
49
|
export { tokenize as n, spawnAsync as t };
|
|
45
50
|
|
|
46
|
-
//# sourceMappingURL=shell-
|
|
51
|
+
//# sourceMappingURL=shell-CN6DNqeC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-CN6DNqeC.js","names":[],"sources":["../../../internals/utils/src/shell.ts"],"sourcesContent":["import { spawn } from 'node:child_process'\n\n/**\n * Tokenizes a shell command string, respecting single and double quotes.\n *\n * @example\n * tokenize('git commit -m \"initial commit\"')\n * // → ['git', 'commit', '-m', 'initial commit']\n */\nexport function tokenize(command: string): string[] {\n return (command.match(/[^\\s\"']+|\"([^\"]*)\"|'([^']*)'/g) ?? []).map((token) => token.replace(/^[\"']|[\"']$/g, ''))\n}\n\ntype SpawnOptions = {\n /**\n * Working directory for the child process.\n * @default process.cwd()\n */\n cwd?: string\n /**\n * Environment variables passed to the child process.\n * @default process.env\n */\n env?: NodeJS.ProcessEnv\n /**\n * When `true`, spawns a detached background process and resolves immediately.\n * The child is unref'd so the parent process can exit independently.\n * @default false\n */\n detached?: boolean\n}\n\n/**\n * Spawns `cmd` with `args` and returns a promise that settles when the child process finishes.\n *\n * Foreground mode (default) inherits the parent's stdio and rejects on non-zero exit or signal.\n * Detached mode spawns the child in its own process group, unref's it, and resolves immediately.\n *\n * @example\n * ```ts\n * await spawnAsync('pnpm', ['install'])\n * await spawnAsync('node', ['server.js'], { detached: true }) // fire-and-forget\n * ```\n */\nexport function spawnAsync(cmd: string, args: string[], options: SpawnOptions = {}): Promise<void> {\n const { cwd = process.cwd(), env, detached = false } = options\n\n return new Promise((resolve, reject) => {\n const child = spawn(cmd, args, {\n stdio: detached ? 'ignore' : 'inherit',\n cwd,\n env,\n detached,\n })\n\n if (detached) {\n child.unref()\n resolve()\n return\n }\n\n child.on('close', (code, signal) => {\n if (code === 0) {\n resolve()\n } else if (signal !== null) {\n reject(new Error(`\"${cmd} ${args.join(' ')}\" was terminated by signal ${signal}`))\n } else {\n reject(new Error(`\"${cmd} ${args.join(' ')}\" exited with code ${code}`))\n }\n })\n child.on('error', reject)\n })\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,SAAS,SAA2B;CAClD,QAAQ,QAAQ,MAAM,gCAAgC,IAAI,EAAE,EAAE,KAAK,UAAU,MAAM,QAAQ,gBAAgB,GAAG,CAAC;;;;;;;;;;;;;;AAkCjH,SAAgB,WAAW,KAAa,MAAgB,UAAwB,EAAE,EAAiB;CACjG,MAAM,EAAE,MAAM,QAAQ,KAAK,EAAE,KAAK,WAAW,UAAU;CAEvD,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,QAAQ,MAAM,KAAK,MAAM;GAC7B,OAAO,WAAW,WAAW;GAC7B;GACA;GACA;GACD,CAAC;EAEF,IAAI,UAAU;GACZ,MAAM,OAAO;GACb,SAAS;GACT;;EAGF,MAAM,GAAG,UAAU,MAAM,WAAW;GAClC,IAAI,SAAS,GACX,SAAS;QACJ,IAAI,WAAW,MACpB,uBAAO,IAAI,MAAM,IAAI,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,6BAA6B,SAAS,CAAC;QAElF,uBAAO,IAAI,MAAM,IAAI,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,qBAAqB,OAAO,CAAC;IAE1E;EACF,MAAM,GAAG,SAAS,OAAO;GACzB"}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
const require_constants = require("./constants-
|
|
2
|
+
const require_constants = require("./constants-BINTA5VZ.cjs");
|
|
3
3
|
let node_crypto = require("node:crypto");
|
|
4
4
|
let node_dns = require("node:dns");
|
|
5
5
|
let node_os = require("node:os");
|
|
6
|
-
node_os = require_chunk.__toESM(node_os);
|
|
6
|
+
node_os = require_chunk.__toESM(node_os, 1);
|
|
7
7
|
let node_process = require("node:process");
|
|
8
|
-
node_process = require_chunk.__toESM(node_process);
|
|
8
|
+
node_process = require_chunk.__toESM(node_process, 1);
|
|
9
9
|
//#region ../../internals/utils/src/env.ts
|
|
10
10
|
/**
|
|
11
11
|
* Returns `true` when running inside a GitHub Actions workflow.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* if (isGitHubActions()) {
|
|
16
|
+
* core.setOutput('result', 'ok')
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
12
19
|
*/
|
|
13
20
|
function isGitHubActions() {
|
|
14
21
|
return !!process.env.GITHUB_ACTIONS;
|
|
@@ -17,19 +24,41 @@ function isGitHubActions() {
|
|
|
17
24
|
* Returns `true` when the process is running in a CI environment.
|
|
18
25
|
* Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,
|
|
19
26
|
* TeamCity, Buildkite, and Azure Pipelines.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* if (isCIEnvironment()) {
|
|
31
|
+
* logger.level = 'error'
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
20
34
|
*/
|
|
21
35
|
function isCIEnvironment() {
|
|
22
36
|
return !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.BITBUCKET_BUILD_NUMBER || process.env.JENKINS_URL || process.env.CIRCLECI || process.env.TRAVIS || process.env.TEAMCITY_VERSION || process.env.BUILDKITE || process.env.TF_BUILD);
|
|
23
37
|
}
|
|
24
38
|
/**
|
|
25
|
-
* Returns `true` when the process has an interactive TTY
|
|
39
|
+
* Returns `true` when the process has an interactive TTY with a valid terminal
|
|
40
|
+
* width and is not running in CI.
|
|
41
|
+
*
|
|
42
|
+
* Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,
|
|
43
|
+
* which breaks clack's box-drawing helpers (they call `String.prototype.repeat`
|
|
44
|
+
* with a negative count and throw a `RangeError`). We therefore require a
|
|
45
|
+
* positive column count before declaring the TTY usable.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* if (canUseTTY()) {
|
|
50
|
+
* renderProgressBar()
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
26
53
|
*/
|
|
27
54
|
function canUseTTY() {
|
|
28
|
-
return !!process.stdout.isTTY && !isCIEnvironment();
|
|
55
|
+
return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment();
|
|
29
56
|
}
|
|
30
57
|
//#endregion
|
|
31
58
|
//#region ../../internals/utils/src/network.ts
|
|
32
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Well-known stable domains used as DNS probes to check internet connectivity.
|
|
61
|
+
*/
|
|
33
62
|
const TEST_DOMAINS = [
|
|
34
63
|
"dns.google.com",
|
|
35
64
|
"cloudflare.com",
|
|
@@ -37,7 +66,14 @@ const TEST_DOMAINS = [
|
|
|
37
66
|
];
|
|
38
67
|
/**
|
|
39
68
|
* Returns `true` when the system has internet connectivity.
|
|
40
|
-
*
|
|
69
|
+
* Probes DNS resolution against well-known stable domains.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* if (await isOnline()) {
|
|
74
|
+
* await fetchLatestVersion()
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
41
77
|
*/
|
|
42
78
|
async function isOnline() {
|
|
43
79
|
for (const domain of TEST_DOMAINS) try {
|
|
@@ -48,6 +84,12 @@ async function isOnline() {
|
|
|
48
84
|
}
|
|
49
85
|
/**
|
|
50
86
|
* Executes `fn` only when the system is online. Returns `null` when offline or on error.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const version = await executeIfOnline(() => fetchLatestVersion('kubb'))
|
|
91
|
+
* // null when offline
|
|
92
|
+
* ```
|
|
51
93
|
*/
|
|
52
94
|
async function executeIfOnline(fn) {
|
|
53
95
|
if (!await isOnline()) return null;
|
|
@@ -58,17 +100,15 @@ async function executeIfOnline(fn) {
|
|
|
58
100
|
}
|
|
59
101
|
}
|
|
60
102
|
//#endregion
|
|
61
|
-
//#region src/
|
|
103
|
+
//#region src/telemetry.ts
|
|
62
104
|
/**
|
|
63
|
-
*
|
|
64
|
-
* Delegates to the canonical isCIEnvironment() from envDetection.
|
|
105
|
+
* Returns `true` when the current process runs inside a CI environment.
|
|
65
106
|
*/
|
|
66
107
|
function isCi() {
|
|
67
108
|
return isCIEnvironment();
|
|
68
109
|
}
|
|
69
110
|
/**
|
|
70
|
-
*
|
|
71
|
-
* Respects the standard DO_NOT_TRACK convention used across development tools.
|
|
111
|
+
* Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
|
|
72
112
|
*/
|
|
73
113
|
function isTelemetryDisabled() {
|
|
74
114
|
return node_process.default.env["DO_NOT_TRACK"] === "1" || node_process.default.env["DO_NOT_TRACK"] === "true" || node_process.default.env["KUBB_DISABLE_TELEMETRY"] === "1" || node_process.default.env["KUBB_DISABLE_TELEMETRY"] === "true";
|
|
@@ -237,4 +277,4 @@ Object.defineProperty(exports, "sendTelemetry", {
|
|
|
237
277
|
}
|
|
238
278
|
});
|
|
239
279
|
|
|
240
|
-
//# sourceMappingURL=telemetry-
|
|
280
|
+
//# sourceMappingURL=telemetry-B2iWkY5e.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-B2iWkY5e.cjs","names":["dnsPromises","process","OTLP_ENDPOINT","os"],"sources":["../../../internals/utils/src/env.ts","../../../internals/utils/src/network.ts","../src/telemetry.ts"],"sourcesContent":["/**\n * Returns `true` when running inside a GitHub Actions workflow.\n *\n * @example\n * ```ts\n * if (isGitHubActions()) {\n * core.setOutput('result', 'ok')\n * }\n * ```\n */\nexport function isGitHubActions(): boolean {\n return !!process.env.GITHUB_ACTIONS\n}\n\n/**\n * Returns `true` when the process is running in a CI environment.\n * Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,\n * TeamCity, Buildkite, and Azure Pipelines.\n *\n * @example\n * ```ts\n * if (isCIEnvironment()) {\n * logger.level = 'error'\n * }\n * ```\n */\nexport function isCIEnvironment(): boolean {\n return !!(\n process.env.CI ||\n process.env.GITHUB_ACTIONS ||\n process.env.GITLAB_CI ||\n process.env.BITBUCKET_BUILD_NUMBER ||\n process.env.JENKINS_URL ||\n process.env.CIRCLECI ||\n process.env.TRAVIS ||\n process.env.TEAMCITY_VERSION ||\n process.env.BUILDKITE ||\n process.env.TF_BUILD\n )\n}\n\n/**\n * Returns `true` when the process has an interactive TTY with a valid terminal\n * width and is not running in CI.\n *\n * Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,\n * which breaks clack's box-drawing helpers (they call `String.prototype.repeat`\n * with a negative count and throw a `RangeError`). We therefore require a\n * positive column count before declaring the TTY usable.\n *\n * @example\n * ```ts\n * if (canUseTTY()) {\n * renderProgressBar()\n * }\n * ```\n */\nexport function canUseTTY(): boolean {\n return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment()\n}\n","import { promises as dnsPromises } from 'node:dns'\n\n/**\n * Well-known stable domains used as DNS probes to check internet connectivity.\n */\nconst TEST_DOMAINS = ['dns.google.com', 'cloudflare.com', 'one.one.one.one'] as const\n\n/**\n * Returns `true` when the system has internet connectivity.\n * Probes DNS resolution against well-known stable domains.\n *\n * @example\n * ```ts\n * if (await isOnline()) {\n * await fetchLatestVersion()\n * }\n * ```\n */\nexport async function isOnline(): Promise<boolean> {\n for (const domain of TEST_DOMAINS) {\n try {\n await dnsPromises.resolve(domain)\n return true\n } catch {\n // Try next domain\n }\n }\n\n return false\n}\n\n/**\n * Executes `fn` only when the system is online. Returns `null` when offline or on error.\n *\n * @example\n * ```ts\n * const version = await executeIfOnline(() => fetchLatestVersion('kubb'))\n * // null when offline\n * ```\n */\nexport async function executeIfOnline<T>(fn: () => Promise<T>): Promise<T | null> {\n if (!(await isOnline())) return null\n\n try {\n return await fn()\n } catch {\n return null\n }\n}\n","import { randomBytes } from 'node:crypto'\nimport os from 'node:os'\nimport process from 'node:process'\nimport { executeIfOnline, isCIEnvironment } from '@internals/utils'\nimport { OTLP_ENDPOINT } from './constants.ts'\n\n// OpenTelemetry OTLP JSON types\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto\n// https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto\n\ntype OtlpStringValue = { stringValue: string }\ntype OtlpBoolValue = { boolValue: boolean }\ntype OtlpIntValue = { intValue: number }\ntype OtlpDoubleValue = { doubleValue: number }\ntype OtlpBytesValue = { bytesValue: string }\ntype OtlpArrayValue = { arrayValue: { values: OtlpAnyValue[] } }\ntype OtlpKvListValue = { kvlistValue: { values: OtlpKeyValue[] } }\n\ntype OtlpAnyValue = OtlpStringValue | OtlpBoolValue | OtlpIntValue | OtlpDoubleValue | OtlpBytesValue | OtlpArrayValue | OtlpKvListValue\n\ntype OtlpKeyValue = {\n key: string\n value: OtlpAnyValue\n}\n\ntype OtlpResource = {\n attributes: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpInstrumentationScope = {\n name: string\n version?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\n/** https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto#L103 */\ntype OtlpSpanKind = 0 | 1 | 2 | 3 | 4 | 5\n\n/** 0 = STATUS_CODE_UNSET, 1 = STATUS_CODE_OK, 2 = STATUS_CODE_ERROR */\ntype OtlpStatusCode = 0 | 1 | 2\n\ntype OtlpStatus = {\n code: OtlpStatusCode\n message?: string\n}\n\ntype OtlpSpan = {\n traceId: string\n spanId: string\n traceState?: string\n parentSpanId?: string\n name: string\n kind: OtlpSpanKind\n startTimeUnixNano: string\n endTimeUnixNano: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n events?: OtlpSpanEvent[]\n droppedEventsCount?: number\n links?: OtlpSpanLink[]\n droppedLinksCount?: number\n status?: OtlpStatus\n}\n\ntype OtlpSpanEvent = {\n timeUnixNano: string\n name: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpSpanLink = {\n traceId: string\n spanId: string\n traceState?: string\n attributes?: OtlpKeyValue[]\n droppedAttributesCount?: number\n}\n\ntype OtlpScopeSpans = {\n scope: OtlpInstrumentationScope\n spans: OtlpSpan[]\n schemaUrl?: string\n}\n\ntype OtlpResourceSpans = {\n resource: OtlpResource\n scopeSpans: OtlpScopeSpans[]\n schemaUrl?: string\n}\n\n/** Root payload sent to POST /v1/traces */\ntype OtlpExportTraceServiceRequest = {\n resourceSpans: OtlpResourceSpans[]\n}\n\n/**\n * Anonymous plugin name and options snapshot sent with each telemetry event.\n */\nexport type TelemetryPlugin = {\n /**\n * Plugin name as registered in the Kubb config, e.g. `'@kubb/plugin-ts'`.\n */\n name: string\n /**\n * anonymized plugin options snapshot — values are included but cannot be traced back to the user.\n */\n options: Record<string, unknown>\n}\n\ntype TelemetryEvent = {\n command: string\n kubbVersion: string\n nodeVersion: string\n platform: string\n ci: boolean\n plugins: TelemetryPlugin[]\n duration: number\n filesCreated: number\n status: 'success' | 'failed'\n}\n\n/**\n * Returns `true` when the current process runs inside a CI environment.\n */\nexport function isCi(): boolean {\n return isCIEnvironment()\n}\n\n/**\n * Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.\n */\nexport function isTelemetryDisabled(): boolean {\n return (\n process.env['DO_NOT_TRACK'] === '1' ||\n process.env['DO_NOT_TRACK'] === 'true' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === '1' ||\n process.env['KUBB_DISABLE_TELEMETRY'] === 'true'\n )\n}\n\n/**\n * Convert a TelemetryEvent into an OTLP-compatible JSON trace payload.\n * See https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/\n */\nexport function buildOtlpPayload(event: TelemetryEvent): OtlpExportTraceServiceRequest {\n const traceId = randomBytes(16).toString('hex')\n const spanId = randomBytes(8).toString('hex')\n const endTimeNs = BigInt(Date.now()) * 1_000_000n\n const startTimeNs = endTimeNs - BigInt(event.duration) * 1_000_000n\n\n const attributes: OtlpKeyValue[] = [\n { key: 'kubb.command', value: { stringValue: event.command } },\n { key: 'kubb.version', value: { stringValue: event.kubbVersion } },\n { key: 'kubb.node_version', value: { stringValue: event.nodeVersion } },\n { key: 'kubb.platform', value: { stringValue: event.platform } },\n { key: 'kubb.ci', value: { boolValue: event.ci } },\n { key: 'kubb.files_created', value: { intValue: event.filesCreated } },\n { key: 'kubb.status', value: { stringValue: event.status } },\n {\n key: 'kubb.plugins',\n value: {\n arrayValue: {\n values: event.plugins.map(\n (p): OtlpKvListValue => ({\n kvlistValue: {\n values: [\n { key: 'name', value: { stringValue: p.name } },\n {\n key: 'options',\n value: {\n stringValue: JSON.stringify({\n ...p.options,\n usedEnumNames: undefined,\n }),\n },\n },\n ],\n },\n }),\n ),\n },\n },\n },\n ]\n\n return {\n resourceSpans: [\n {\n resource: {\n attributes: [\n { key: 'service.name', value: { stringValue: 'kubb-cli' } },\n {\n key: 'service.version',\n value: { stringValue: event.kubbVersion },\n },\n { key: 'telemetry.sdk.language', value: { stringValue: 'nodejs' } },\n ],\n },\n scopeSpans: [\n {\n scope: { name: 'kubb-cli', version: event.kubbVersion },\n spans: [\n {\n traceId,\n spanId,\n name: event.command,\n kind: 1 satisfies OtlpSpanKind,\n startTimeUnixNano: String(startTimeNs),\n endTimeUnixNano: String(endTimeNs),\n attributes,\n status: {\n code: (event.status === 'success' ? 1 : 2) satisfies OtlpStatusCode,\n },\n },\n ],\n },\n ],\n },\n ],\n }\n}\n\n/**\n * Send an anonymous telemetry event to the Kubb OTLP endpoint.\n * Respects DO_NOT_TRACK and KUBB_DISABLE_TELEMETRY environment variables.\n * Fails silently to never interrupt the generation process.\n */\nexport async function sendTelemetry(event: TelemetryEvent): Promise<void> {\n if (isTelemetryDisabled()) {\n return\n }\n\n await executeIfOnline(async () => {\n try {\n await fetch(`${OTLP_ENDPOINT}/v1/traces`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Kubb-Telemetry-Version': '1',\n 'Kubb-Telemetry-Source': 'kubb-cli',\n },\n body: JSON.stringify(buildOtlpPayload(event)),\n signal: AbortSignal.timeout(5_000),\n })\n } catch (_e) {\n // Fail silently – telemetry must never break the CLI\n }\n })\n}\n\n/**\n * Build an anonymous telemetry payload from a completed generation run.\n * No file paths, OpenAPI specs, or secrets are included.\n */\nexport function buildTelemetryEvent(options: {\n command: 'generate' | 'mcp' | 'validate' | 'agent'\n kubbVersion: string\n plugins?: TelemetryPlugin[]\n hrStart: [number, number]\n filesCreated?: number\n status: 'success' | 'failed'\n}): TelemetryEvent {\n const [seconds, nanoseconds] = process.hrtime(options.hrStart)\n const duration = Math.round(seconds * 1000 + nanoseconds / 1e6)\n\n return {\n command: options.command,\n kubbVersion: options.kubbVersion,\n nodeVersion: process.versions.node.split('.')[0] as string,\n platform: os.platform(),\n ci: isCi(),\n plugins: options.plugins ?? [],\n duration,\n filesCreated: options.filesCreated ?? 0,\n status: options.status,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAUA,SAAgB,kBAA2B;CACzC,OAAO,CAAC,CAAC,QAAQ,IAAI;;;;;;;;;;;;;;AAevB,SAAgB,kBAA2B;CACzC,OAAO,CAAC,EACN,QAAQ,IAAI,MACZ,QAAQ,IAAI,kBACZ,QAAQ,IAAI,aACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,eACZ,QAAQ,IAAI,YACZ,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0B;KAC1B,yBAAyB;KAC1B;IACD,MAAM,KAAK,UAAU,iBAAiB,MAAM,CAAC;IAC7C,QAAQ,YAAY,QAAQ,IAAM;IACnC,CAAC;WACK,IAAI;GAGb;;;;;;AAOJ,SAAgB,oBAAoB,SAOjB;CACjB,MAAM,CAAC,SAAS,eAAeD,aAAAA,QAAQ,OAAO,QAAQ,QAAQ;CAC9D,MAAM,WAAW,KAAK,MAAM,UAAU,MAAO,cAAc,IAAI;CAE/D,OAAO;EACL,SAAS,QAAQ;EACjB,aAAa,QAAQ;EACrB,aAAaA,aAAAA,QAAQ,SAAS,KAAK,MAAM,IAAI,CAAC;EAC9C,UAAUE,QAAAA,QAAG,UAAU;EACvB,IAAI,MAAM;EACV,SAAS,QAAQ,WAAW,EAAE;EAC9B;EACA,cAAc,QAAQ,gBAAgB;EACtC,QAAQ,QAAQ;EACjB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./chunk
|
|
2
|
-
import { n as OTLP_ENDPOINT } from "./constants-
|
|
1
|
+
import "./chunk-BvFE5Tac.js";
|
|
2
|
+
import { n as OTLP_ENDPOINT } from "./constants-B2JTeRBb.js";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
4
|
import { promises } from "node:dns";
|
|
5
5
|
import os from "node:os";
|
|
@@ -7,6 +7,13 @@ import process$1 from "node:process";
|
|
|
7
7
|
//#region ../../internals/utils/src/env.ts
|
|
8
8
|
/**
|
|
9
9
|
* Returns `true` when running inside a GitHub Actions workflow.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* if (isGitHubActions()) {
|
|
14
|
+
* core.setOutput('result', 'ok')
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
10
17
|
*/
|
|
11
18
|
function isGitHubActions() {
|
|
12
19
|
return !!process.env.GITHUB_ACTIONS;
|
|
@@ -15,19 +22,41 @@ function isGitHubActions() {
|
|
|
15
22
|
* Returns `true` when the process is running in a CI environment.
|
|
16
23
|
* Covers GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, Bitbucket,
|
|
17
24
|
* TeamCity, Buildkite, and Azure Pipelines.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* if (isCIEnvironment()) {
|
|
29
|
+
* logger.level = 'error'
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
18
32
|
*/
|
|
19
33
|
function isCIEnvironment() {
|
|
20
34
|
return !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.BITBUCKET_BUILD_NUMBER || process.env.JENKINS_URL || process.env.CIRCLECI || process.env.TRAVIS || process.env.TEAMCITY_VERSION || process.env.BUILDKITE || process.env.TF_BUILD);
|
|
21
35
|
}
|
|
22
36
|
/**
|
|
23
|
-
* Returns `true` when the process has an interactive TTY
|
|
37
|
+
* Returns `true` when the process has an interactive TTY with a valid terminal
|
|
38
|
+
* width and is not running in CI.
|
|
39
|
+
*
|
|
40
|
+
* Some IDE-embedded terminals report `isTTY = true` but set `columns` to `0`,
|
|
41
|
+
* which breaks clack's box-drawing helpers (they call `String.prototype.repeat`
|
|
42
|
+
* with a negative count and throw a `RangeError`). We therefore require a
|
|
43
|
+
* positive column count before declaring the TTY usable.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* if (canUseTTY()) {
|
|
48
|
+
* renderProgressBar()
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
24
51
|
*/
|
|
25
52
|
function canUseTTY() {
|
|
26
|
-
return !!process.stdout.isTTY && !isCIEnvironment();
|
|
53
|
+
return !!process.stdout.isTTY && (process.stdout.columns ?? 0) > 0 && !isCIEnvironment();
|
|
27
54
|
}
|
|
28
55
|
//#endregion
|
|
29
56
|
//#region ../../internals/utils/src/network.ts
|
|
30
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Well-known stable domains used as DNS probes to check internet connectivity.
|
|
59
|
+
*/
|
|
31
60
|
const TEST_DOMAINS = [
|
|
32
61
|
"dns.google.com",
|
|
33
62
|
"cloudflare.com",
|
|
@@ -35,7 +64,14 @@ const TEST_DOMAINS = [
|
|
|
35
64
|
];
|
|
36
65
|
/**
|
|
37
66
|
* Returns `true` when the system has internet connectivity.
|
|
38
|
-
*
|
|
67
|
+
* Probes DNS resolution against well-known stable domains.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* if (await isOnline()) {
|
|
72
|
+
* await fetchLatestVersion()
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
39
75
|
*/
|
|
40
76
|
async function isOnline() {
|
|
41
77
|
for (const domain of TEST_DOMAINS) try {
|
|
@@ -46,6 +82,12 @@ async function isOnline() {
|
|
|
46
82
|
}
|
|
47
83
|
/**
|
|
48
84
|
* Executes `fn` only when the system is online. Returns `null` when offline or on error.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const version = await executeIfOnline(() => fetchLatestVersion('kubb'))
|
|
89
|
+
* // null when offline
|
|
90
|
+
* ```
|
|
49
91
|
*/
|
|
50
92
|
async function executeIfOnline(fn) {
|
|
51
93
|
if (!await isOnline()) return null;
|
|
@@ -56,17 +98,15 @@ async function executeIfOnline(fn) {
|
|
|
56
98
|
}
|
|
57
99
|
}
|
|
58
100
|
//#endregion
|
|
59
|
-
//#region src/
|
|
101
|
+
//#region src/telemetry.ts
|
|
60
102
|
/**
|
|
61
|
-
*
|
|
62
|
-
* Delegates to the canonical isCIEnvironment() from envDetection.
|
|
103
|
+
* Returns `true` when the current process runs inside a CI environment.
|
|
63
104
|
*/
|
|
64
105
|
function isCi() {
|
|
65
106
|
return isCIEnvironment();
|
|
66
107
|
}
|
|
67
108
|
/**
|
|
68
|
-
*
|
|
69
|
-
* Respects the standard DO_NOT_TRACK convention used across development tools.
|
|
109
|
+
* Returns `true` when telemetry is disabled via `DO_NOT_TRACK` or `KUBB_DISABLE_TELEMETRY`.
|
|
70
110
|
*/
|
|
71
111
|
function isTelemetryDisabled() {
|
|
72
112
|
return process$1.env["DO_NOT_TRACK"] === "1" || process$1.env["DO_NOT_TRACK"] === "true" || process$1.env["KUBB_DISABLE_TELEMETRY"] === "1" || process$1.env["KUBB_DISABLE_TELEMETRY"] === "true";
|
|
@@ -200,4 +240,4 @@ function buildTelemetryEvent(options) {
|
|
|
200
240
|
//#endregion
|
|
201
241
|
export { canUseTTY as a, executeIfOnline as i, isTelemetryDisabled as n, isGitHubActions as o, sendTelemetry as r, buildTelemetryEvent as t };
|
|
202
242
|
|
|
203
|
-
//# sourceMappingURL=telemetry-
|
|
243
|
+
//# sourceMappingURL=telemetry-BkektVz6.js.map
|