@kubb/cli 5.14.5 → 5.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/kubb.js +2 -1
- package/dist/{Telemetry-Dc79_cIA.js → Telemetry-B3edcFoB.js} +12 -86
- package/dist/Telemetry-B3edcFoB.js.map +1 -0
- package/dist/{Telemetry-Dc9DVxKQ.cjs → Telemetry-COWGqYmh.cjs} +14 -118
- package/dist/Telemetry-COWGqYmh.cjs.map +1 -0
- package/dist/{background-v5pDy3IJ.cjs → background-B24lIehn.cjs} +5 -6
- package/dist/{background-v5pDy3IJ.cjs.map → background-B24lIehn.cjs.map} +1 -1
- package/dist/{background-C877JFxE.js → background-D-7OGjvg.js} +1 -1
- package/dist/{background-3_KudPH-.js → background-_dKcGjM7.js} +5 -6
- package/dist/{background-3_KudPH-.js.map → background-_dKcGjM7.js.map} +1 -1
- package/dist/banner-BdTTDFkG.js +140 -0
- package/dist/banner-BdTTDFkG.js.map +1 -0
- package/dist/banner-wJFk-L-c.cjs +163 -0
- package/dist/banner-wJFk-L-c.cjs.map +1 -0
- package/dist/config-BL3HnFhb.js +1 -0
- package/dist/config-BWj9jBVj.cjs +62 -0
- package/dist/config-BWj9jBVj.cjs.map +1 -0
- package/dist/{config-CNqgDSu3.js → config-CQTxXvIG.js} +6 -52
- package/dist/config-CQTxXvIG.js.map +1 -0
- package/dist/{config-BG_Nr2CZ.cjs → config-CRrmj88c.cjs} +15 -62
- package/dist/config-CRrmj88c.cjs.map +1 -0
- package/dist/config-Uk3rbZfb.js +49 -0
- package/dist/config-Uk3rbZfb.js.map +1 -0
- package/dist/configFile-C0DIXNMD.js +993 -0
- package/dist/configFile-C0DIXNMD.js.map +1 -0
- package/dist/configFile-CoEpHdXG.cjs +1028 -0
- package/dist/configFile-CoEpHdXG.cjs.map +1 -0
- package/dist/{credentials-C8tjAhTo.js → credentials-B77iJx9H.js} +1 -1
- package/dist/{credentials-DDaKqtJn.cjs → credentials-DEsGwcGD.cjs} +3 -4
- package/dist/{credentials-DDaKqtJn.cjs.map → credentials-DEsGwcGD.cjs.map} +1 -1
- package/dist/{credentials-CZK6zPLv.js → credentials-osgjujE_.js} +3 -4
- package/dist/{credentials-CZK6zPLv.js.map → credentials-osgjujE_.js.map} +1 -1
- package/dist/env-C3xHRMez.js +1 -0
- package/dist/env-eu3XyKqJ.cjs +55 -0
- package/dist/env-eu3XyKqJ.cjs.map +1 -0
- package/dist/env-rv-VgSGN.js +34 -0
- package/dist/env-rv-VgSGN.js.map +1 -0
- package/dist/{errors-Cl69p_vI.cjs → errors-BponpdjN.cjs} +3 -4
- package/dist/{errors-Cl69p_vI.cjs.map → errors-BponpdjN.cjs.map} +1 -1
- package/dist/{errors-DmC83ALX.js → errors-wzqmMpMo.js} +3 -4
- package/dist/{errors-DmC83ALX.js.map → errors-wzqmMpMo.js.map} +1 -1
- package/dist/index.cjs +37 -2719
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +35 -2713
- package/dist/index.js.map +1 -1
- package/dist/installWithSpinner-DpnpxHq5.js +49 -0
- package/dist/installWithSpinner-DpnpxHq5.js.map +1 -0
- package/dist/installWithSpinner-ONGfIVUJ.cjs +56 -0
- package/dist/installWithSpinner-ONGfIVUJ.cjs.map +1 -0
- package/dist/{text-CEyJhBnh.js → intro-9PB8sE8z.js} +8 -52
- package/dist/intro-9PB8sE8z.js.map +1 -0
- package/dist/{text-CC2xdpGL.cjs → intro-YPaf1Imr.cjs} +12 -80
- package/dist/intro-YPaf1Imr.cjs.map +1 -0
- package/dist/isCIEnvironment-D6xtAAZ2.js +14 -0
- package/dist/isCIEnvironment-D6xtAAZ2.js.map +1 -0
- package/dist/isCIEnvironment-DiVOMI5Q.cjs +20 -0
- package/dist/isCIEnvironment-DiVOMI5Q.cjs.map +1 -0
- package/dist/mascot--q1xjKw1.js +63 -0
- package/dist/mascot--q1xjKw1.js.map +1 -0
- package/dist/mascot-JSA0j3Q_.cjs +80 -0
- package/dist/mascot-JSA0j3Q_.cjs.map +1 -0
- package/dist/mcp-CYPOFKnP.cjs +20 -0
- package/dist/mcp-CYPOFKnP.cjs.map +1 -0
- package/dist/mcp-CxeZR5vb.js +21 -0
- package/dist/mcp-CxeZR5vb.js.map +1 -0
- package/dist/package-D3Yss9Bb.js +5 -0
- package/dist/package-D3Yss9Bb.js.map +1 -0
- package/dist/package-aX0q9SZr.cjs +10 -0
- package/dist/package-aX0q9SZr.cjs.map +1 -0
- package/dist/{registry-ov1RYcD4.js → registry-B3eYk4LN.js} +7 -67
- package/dist/registry-B3eYk4LN.js.map +1 -0
- package/dist/{registry-BInbtBm7.cjs → registry-YE1pFWL-.cjs} +4 -82
- package/dist/registry-YE1pFWL-.cjs.map +1 -0
- package/dist/{reporters-DQz--AdE.cjs → reporters-2cgjvXwR.cjs} +32 -40
- package/dist/{reporters-DQz--AdE.cjs.map → reporters-2cgjvXwR.cjs.map} +1 -1
- package/dist/{reporters-BtD41K-C.js → reporters-BM430HdQ.js} +19 -27
- package/dist/{reporters-BtD41K-C.js.map → reporters-BM430HdQ.js.map} +1 -1
- package/dist/{rolldown-runtime-CPE0t6oh.cjs → rolldown-runtime-C3-Zg-KD.cjs} +1 -2
- package/dist/{rolldown-runtime-CRm0XQPb.js → rolldown-runtime-xo6NMXYd.js} +1 -2
- package/dist/run-1H9TGT8v.js +77 -0
- package/dist/run-1H9TGT8v.js.map +1 -0
- package/dist/run-B4zvF9WY.cjs +233 -0
- package/dist/run-B4zvF9WY.cjs.map +1 -0
- package/dist/run-BYP_t9dR.cjs +324 -0
- package/dist/run-BYP_t9dR.cjs.map +1 -0
- package/dist/{run-1oXPIkli.cjs → run-Bb19PlwV.cjs} +44 -37
- package/dist/run-Bb19PlwV.cjs.map +1 -0
- package/dist/{run-B03V0Poj.cjs → run-BoO7H8RA.cjs} +49 -41
- package/dist/run-BoO7H8RA.cjs.map +1 -0
- package/dist/run-BrM7-NSV.js +181 -0
- package/dist/run-BrM7-NSV.js.map +1 -0
- package/dist/{run-UsAMlUyy.js → run-C0KI-NE3.js} +9 -9
- package/dist/{run-UsAMlUyy.js.map → run-C0KI-NE3.js.map} +1 -1
- package/dist/run-CCLPt4hr.js +1 -0
- package/dist/run-CCsdLz3X.js +385 -0
- package/dist/run-CCsdLz3X.js.map +1 -0
- package/dist/{run-YMSJnvYl.js → run-CbX6tpqB.js} +31 -23
- package/dist/run-CbX6tpqB.js.map +1 -0
- package/dist/run-CrM4jsix.cjs +80 -0
- package/dist/run-CrM4jsix.cjs.map +1 -0
- package/dist/run-CvFakE3B.cjs +185 -0
- package/dist/run-CvFakE3B.cjs.map +1 -0
- package/dist/run-D-nn9-Wq.js +319 -0
- package/dist/run-D-nn9-Wq.js.map +1 -0
- package/dist/{run-cBSr2F1q.cjs → run-D5Z6nfzK.cjs} +5 -6
- package/dist/{run-cBSr2F1q.cjs.map → run-D5Z6nfzK.cjs.map} +1 -1
- package/dist/{run-BUzdEUaE.cjs → run-DCqmf5W1.cjs} +10 -10
- package/dist/{run-BUzdEUaE.cjs.map → run-DCqmf5W1.cjs.map} +1 -1
- package/dist/{run-BK-A9JDf.js → run-DFXhBS64.js} +5 -6
- package/dist/{run-BK-A9JDf.js.map → run-DFXhBS64.js.map} +1 -1
- package/dist/run-DgGZOC_x.cjs +389 -0
- package/dist/run-DgGZOC_x.cjs.map +1 -0
- package/dist/{run-DDwdeHgU.js → run-KqdudiWQ.js} +26 -20
- package/dist/run-KqdudiWQ.js.map +1 -0
- package/dist/run-RN_31Q4u.js +228 -0
- package/dist/run-RN_31Q4u.js.map +1 -0
- package/dist/shared-C0EtrdUm.cjs +123 -0
- package/dist/shared-C0EtrdUm.cjs.map +1 -0
- package/dist/shared-Ct9stKpp.js +94 -0
- package/dist/shared-Ct9stKpp.js.map +1 -0
- package/dist/{snapshot-BrwynBfC.cjs → snapshot-D7Ytw8S0.cjs} +13 -14
- package/dist/{snapshot-BrwynBfC.cjs.map → snapshot-D7Ytw8S0.cjs.map} +1 -1
- package/dist/{snapshot-D2E7nhEf.js → snapshot-n7dJGCWv.js} +10 -11
- package/dist/{snapshot-D2E7nhEf.js.map → snapshot-n7dJGCWv.js.map} +1 -1
- package/dist/spinner-BZaln7O8.js +160 -0
- package/dist/spinner-BZaln7O8.js.map +1 -0
- package/dist/spinner-CfB0sIPy.cjs +208 -0
- package/dist/spinner-CfB0sIPy.cjs.map +1 -0
- package/dist/{status-CxzhvjKs.cjs → status-Bc0_4T41.cjs} +7 -8
- package/dist/{status-CxzhvjKs.cjs.map → status-Bc0_4T41.cjs.map} +1 -1
- package/dist/{status-BHIOMCM0.js → status-DxSkp1cH.js} +6 -7
- package/dist/{status-BHIOMCM0.js.map → status-DxSkp1cH.js.map} +1 -1
- package/dist/studio-BpYwgFb0.cjs +218 -0
- package/dist/studio-BpYwgFb0.cjs.map +1 -0
- package/dist/studio-mw6HaPkr.js +215 -0
- package/dist/studio-mw6HaPkr.js.map +1 -0
- package/dist/studioWorker.js +4 -5
- package/dist/{summary-B219y888.js → summary-CbmQKA8l.js} +5 -6
- package/dist/{summary-B219y888.js.map → summary-CbmQKA8l.js.map} +1 -1
- package/dist/{summary-BOYsqub3.cjs → summary-Clvl5Hxs.cjs} +7 -8
- package/dist/{summary-BOYsqub3.cjs.map → summary-Clvl5Hxs.cjs.map} +1 -1
- package/dist/table-BlRe9YTZ.cjs +15 -0
- package/dist/table-BlRe9YTZ.cjs.map +1 -0
- package/dist/table-CR7iZJGo.js +10 -0
- package/dist/table-CR7iZJGo.js.map +1 -0
- package/dist/text-BmiI4s6N.js +13 -0
- package/dist/text-BmiI4s6N.js.map +1 -0
- package/dist/text-Ep3AulAS.cjs +24 -0
- package/dist/text-Ep3AulAS.cjs.map +1 -0
- package/dist/time-3BKoci3G.cjs +82 -0
- package/dist/time-3BKoci3G.cjs.map +1 -0
- package/dist/time-C-wU7VhC.js +65 -0
- package/dist/time-C-wU7VhC.js.map +1 -0
- package/dist/utils-BdibacYq.js +244 -0
- package/dist/utils-BdibacYq.js.map +1 -0
- package/dist/utils-CO89mxRU.cjs +290 -0
- package/dist/utils-CO89mxRU.cjs.map +1 -0
- package/dist/utils-CbJ6hS_t.js +222 -0
- package/dist/utils-CbJ6hS_t.js.map +1 -0
- package/dist/utils-CcARPB45.cjs +286 -0
- package/dist/utils-CcARPB45.cjs.map +1 -0
- package/dist/validate-8ZcWXfMt.js +28 -0
- package/dist/validate-8ZcWXfMt.js.map +1 -0
- package/dist/validate-CMSeDpGT.cjs +27 -0
- package/dist/validate-CMSeDpGT.cjs.map +1 -0
- package/package.json +7 -7
- package/dist/Telemetry-Dc79_cIA.js.map +0 -1
- package/dist/Telemetry-Dc9DVxKQ.cjs.map +0 -1
- package/dist/config-BG_Nr2CZ.cjs.map +0 -1
- package/dist/config-CNqgDSu3.js.map +0 -1
- package/dist/config-DWDpFSn1.js +0 -1
- package/dist/registry-BInbtBm7.cjs.map +0 -1
- package/dist/registry-ov1RYcD4.js.map +0 -1
- package/dist/run-1oXPIkli.cjs.map +0 -1
- package/dist/run-B03V0Poj.cjs.map +0 -1
- package/dist/run-DDwdeHgU.js.map +0 -1
- package/dist/run-YMSJnvYl.js.map +0 -1
- package/dist/run-v5aW1jjQ.js +0 -1
- package/dist/text-CC2xdpGL.cjs.map +0 -1
- package/dist/text-CEyJhBnh.js.map +0 -1
- package/dist/utils-8E1nF4C1.cjs +0 -645
- package/dist/utils-8E1nF4C1.cjs.map +0 -1
- package/dist/utils-D8VN40bN.js +0 -536
- package/dist/utils-D8VN40bN.js.map +0 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import "./rolldown-runtime-xo6NMXYd.js";
|
|
2
|
+
import { a as ConfigEditOperation, i as readImports, n as editConfigFile, o as extensionKinds, r as readConfig, t as editConfig } from "./configFile-C0DIXNMD.js";
|
|
3
|
+
import { t as getErrorMessage } from "./errors-wzqmMpMo.js";
|
|
4
|
+
import { n as withSpinner, o as read } from "./spinner-BZaln7O8.js";
|
|
5
|
+
import { l as logStep, n as logIntro, o as logBlock, s as logError, t as isInteractiveRun } from "./intro-9PB8sE8z.js";
|
|
6
|
+
import { o as yesArg, t as configArg } from "./shared-Ct9stKpp.js";
|
|
7
|
+
import { r as BUNDLED_PACKAGES, t as findConfigFile } from "./config-CQTxXvIG.js";
|
|
8
|
+
import { t as logCommandSummary } from "./summary-CbmQKA8l.js";
|
|
9
|
+
import { c as toRegistryId, l as toShortId, n as closestIds, r as fetchRegistryIndex, s as registryUrl } from "./registry-B3eYk4LN.js";
|
|
10
|
+
import { d as uninstallPackages, n as detectPackageManager } from "./utils-CbJ6hS_t.js";
|
|
11
|
+
import { styleText } from "node:util";
|
|
12
|
+
import { define } from "gunshi";
|
|
13
|
+
import process from "node:process";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import * as clack from "@clack/prompts";
|
|
16
|
+
import { Diagnostics, readInstalledPackages } from "@kubb/core";
|
|
17
|
+
// src/runners/remove/run.ts
|
|
18
|
+
/** The lines of `before` that `after` no longer has, trimmed. */
|
|
19
|
+
function removedLines({ before, after }) {
|
|
20
|
+
const remaining = after.split("\n");
|
|
21
|
+
return before.split("\n").filter((line) => {
|
|
22
|
+
const index = remaining.indexOf(line);
|
|
23
|
+
if (index !== -1) remaining.splice(index, 1);
|
|
24
|
+
return index === -1 && line.trim() !== "";
|
|
25
|
+
}).map((line) => line.trim());
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Removes a plugin or parser from `kubb.config.ts` and uninstalls its package. Refuses the adapter,
|
|
29
|
+
* which the config needs, and an extension another one in the config depends on. Previews the
|
|
30
|
+
* change before asking.
|
|
31
|
+
*/
|
|
32
|
+
async function run({ id: input, configPath, yes, uninstall }) {
|
|
33
|
+
const cwd = process.cwd();
|
|
34
|
+
const hrStart = process.hrtime();
|
|
35
|
+
const summary = (title, status, lines) => logCommandSummary({
|
|
36
|
+
title,
|
|
37
|
+
status,
|
|
38
|
+
hrStart,
|
|
39
|
+
block: true,
|
|
40
|
+
lines
|
|
41
|
+
});
|
|
42
|
+
const fail = (title, lines) => {
|
|
43
|
+
summary(title, "failed", lines);
|
|
44
|
+
process.exitCode = 1;
|
|
45
|
+
};
|
|
46
|
+
logIntro({ title: isInteractiveRun({ yes }) ? void 0 : styleText("bgCyan", styleText("black", " Kubb Remove ")) });
|
|
47
|
+
try {
|
|
48
|
+
const id = toRegistryId(input);
|
|
49
|
+
const configFile = configPath ? path.resolve(configPath) : findConfigFile(cwd);
|
|
50
|
+
if (!configFile) throw new Diagnostics.Error({
|
|
51
|
+
code: Diagnostics.code.unknown,
|
|
52
|
+
severity: "error",
|
|
53
|
+
message: "No kubb.config.ts found. Pass its path with --config.",
|
|
54
|
+
help: "Run `kubb remove <id> --config <path>`."
|
|
55
|
+
});
|
|
56
|
+
const configName = path.relative(cwd, configFile) || configFile;
|
|
57
|
+
const [entries, installed, source] = await withSpinner({
|
|
58
|
+
message: "Reading the registry",
|
|
59
|
+
promise: Promise.all([
|
|
60
|
+
fetchRegistryIndex({ registry: registryUrl() }),
|
|
61
|
+
readInstalledPackages({ root: cwd }),
|
|
62
|
+
read(configFile)
|
|
63
|
+
])
|
|
64
|
+
});
|
|
65
|
+
const versions = new Map(installed.map((item) => [item.package, item.version]));
|
|
66
|
+
const entry = entries.find((candidate) => candidate.id === id);
|
|
67
|
+
if (!entry) {
|
|
68
|
+
const suggestions = closestIds({
|
|
69
|
+
input: id,
|
|
70
|
+
ids: entries.map((candidate) => candidate.id)
|
|
71
|
+
}).map(toShortId);
|
|
72
|
+
return fail(`No extension named ${input}`, suggestions.map((suggestion) => ` kubb remove ${suggestion}`));
|
|
73
|
+
}
|
|
74
|
+
const { artifact, manifest } = entry;
|
|
75
|
+
const kind = manifest.kind.charAt(0).toUpperCase() + manifest.kind.slice(1);
|
|
76
|
+
if (manifest.kind === extensionKinds.adapter) return fail("The adapter cannot be removed", [` A config needs one adapter. Change it in ${configName} by hand.`]);
|
|
77
|
+
const view = readConfig(source);
|
|
78
|
+
const running = new Set(view.managed ? view.configs.flatMap((config) => [...config.plugins, ...config.parsers ?? []].filter((call) => !call.disabled).map((call) => call.packageName)) : []);
|
|
79
|
+
const dependents = entries.filter((other) => other.id !== entry.id && other.manifest.dependencies?.includes(manifest.name) && running.has(other.artifact.package));
|
|
80
|
+
if (dependents.length) {
|
|
81
|
+
const names = dependents.map((other) => other.manifest.name).join(", ");
|
|
82
|
+
return fail(`${names} ${dependents.length === 1 ? "needs" : "need"} ${manifest.name}`, [` Remove ${names} first.`]);
|
|
83
|
+
}
|
|
84
|
+
const edits = [{
|
|
85
|
+
operation: ConfigEditOperation.REMOVE_EXTENSION,
|
|
86
|
+
...manifest.kind === extensionKinds.parser ? { kind: extensionKinds.parser } : {},
|
|
87
|
+
plugin: artifact.package
|
|
88
|
+
}];
|
|
89
|
+
const preview = editConfig({
|
|
90
|
+
source,
|
|
91
|
+
edits
|
|
92
|
+
});
|
|
93
|
+
const outcome = preview.outcomes[0];
|
|
94
|
+
if (!outcome?.applied) return fail(`Could not edit ${configName}`, [` ${outcome?.reason ?? "the config file was not changed"}`]);
|
|
95
|
+
const bundled = BUNDLED_PACKAGES.includes(artifact.package);
|
|
96
|
+
const stillImported = readImports(preview.source).includes(artifact.package);
|
|
97
|
+
const uninstalls = uninstall && !bundled && !stillImported && versions.has(artifact.package);
|
|
98
|
+
if (!preview.changed && !uninstalls) {
|
|
99
|
+
summary(`${manifest.name} is not in the project`, "success", [" No changes made"]);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const packageLine = (() => {
|
|
103
|
+
if (uninstalls) return `Uninstalls ${artifact.package}`;
|
|
104
|
+
if (bundled) return `Keeps ${artifact.package}, which ships with kubb`;
|
|
105
|
+
if (stillImported) return `Keeps ${artifact.package}, which another config entry still imports`;
|
|
106
|
+
return "Uninstalls nothing";
|
|
107
|
+
})();
|
|
108
|
+
logStep(`${kind} ${styleText("cyan", manifest.name)} v${versions.get(artifact.package) ?? artifact.version}`);
|
|
109
|
+
logBlock([
|
|
110
|
+
`Config ${configName}`,
|
|
111
|
+
...removedLines({
|
|
112
|
+
before: source,
|
|
113
|
+
after: preview.source
|
|
114
|
+
}).map((line) => styleText("red", ` - ${line}`)),
|
|
115
|
+
packageLine
|
|
116
|
+
]);
|
|
117
|
+
const confirmed = yes || await clack.confirm({
|
|
118
|
+
message: "Remove it?",
|
|
119
|
+
initialValue: true
|
|
120
|
+
});
|
|
121
|
+
if (clack.isCancel(confirmed) || !confirmed) {
|
|
122
|
+
summary("Remove canceled", "canceled", [` ${kind} ${manifest.name}`, " No changes made"]);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (preview.changed) {
|
|
126
|
+
const written = await editConfigFile({
|
|
127
|
+
filePath: configFile,
|
|
128
|
+
edits
|
|
129
|
+
});
|
|
130
|
+
if (!written.outcomes[0]?.applied) return fail(`Could not edit ${configName}`, [` ${written.outcomes[0]?.reason ?? "the config file was not changed"}`]);
|
|
131
|
+
logStep(`${manifest.export}() removed from ${configName}`);
|
|
132
|
+
}
|
|
133
|
+
const packageManager = detectPackageManager(cwd);
|
|
134
|
+
if (uninstalls) await withSpinner({
|
|
135
|
+
message: `Uninstalling ${artifact.package} with ${packageManager.name}`,
|
|
136
|
+
promise: uninstallPackages([artifact.package], packageManager, cwd)
|
|
137
|
+
});
|
|
138
|
+
summary(`${kind} removed`, "success", [
|
|
139
|
+
` Packages ${uninstalls ? `${artifact.package} uninstalled with ${packageManager.name}` : "none uninstalled"}`,
|
|
140
|
+
"",
|
|
141
|
+
"Next kubb generate"
|
|
142
|
+
]);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
logError(getErrorMessage(error));
|
|
145
|
+
fail("Remove failed", [" See the error above"]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const command = define({
|
|
149
|
+
name: "remove",
|
|
150
|
+
description: "Remove a plugin or parser from kubb.config.ts and uninstall its package.",
|
|
151
|
+
examples: [
|
|
152
|
+
"kubb remove plugin-zod",
|
|
153
|
+
"kubb remove acme/plugin-x --yes",
|
|
154
|
+
"kubb remove plugin-zod --no-uninstall"
|
|
155
|
+
].join("\n"),
|
|
156
|
+
toKebab: true,
|
|
157
|
+
args: {
|
|
158
|
+
id: {
|
|
159
|
+
type: "positional",
|
|
160
|
+
description: "Registry id: owner/slug, or a slug for an official extension",
|
|
161
|
+
required: true
|
|
162
|
+
},
|
|
163
|
+
...configArg,
|
|
164
|
+
...yesArg,
|
|
165
|
+
uninstall: {
|
|
166
|
+
type: "boolean",
|
|
167
|
+
description: "Uninstall the package. Pass --no-uninstall to only edit the config",
|
|
168
|
+
negatable: true,
|
|
169
|
+
default: true
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
run: ({ values }) => run({
|
|
173
|
+
id: values.id,
|
|
174
|
+
configPath: values.config,
|
|
175
|
+
yes: values.yes,
|
|
176
|
+
uninstall: values.uninstall
|
|
177
|
+
})
|
|
178
|
+
});
|
|
179
|
+
export { command, run };
|
|
180
|
+
|
|
181
|
+
//# sourceMappingURL=run-BrM7-NSV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-BrM7-NSV.js","names":[],"sources":["../src/runners/remove/run.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { define } from 'gunshi'\nimport { BUNDLED_PACKAGES, ConfigEditOperation, extensionKinds, editConfig, editConfigFile, findConfigFile, readConfig, readImports } from '@internals/shared'\nimport { getErrorMessage, read } from '@internals/utils'\nimport { Diagnostics, readInstalledPackages } from '@kubb/core'\nimport { configArg, yesArg } from '../../commands/shared.ts'\nimport { isInteractiveRun, logIntro } from '../../ui/intro.ts'\nimport { logBlock, logError, logStep } from '../../ui/log.ts'\nimport { withSpinner } from '../../ui/spinner.ts'\nimport { logCommandSummary } from '../../ui/summary.ts'\nimport { closestIds, fetchRegistryIndex, registryUrl, toRegistryId, toShortId } from '../../utils/registry.ts'\nimport { detectPackageManager, uninstallPackages } from '../init/utils.ts'\n\nexport type RemoveOptions = {\n /**\n * `owner/slug`, or a bare `slug` for an official extension.\n */\n id: string\n configPath?: string\n yes: boolean\n uninstall: boolean\n}\n\n/** The lines of `before` that `after` no longer has, trimmed. */\nfunction removedLines({ before, after }: { before: string; after: string }): Array<string> {\n const remaining = after.split('\\n')\n return before\n .split('\\n')\n .filter((line) => {\n const index = remaining.indexOf(line)\n if (index !== -1) remaining.splice(index, 1)\n return index === -1 && line.trim() !== ''\n })\n .map((line) => line.trim())\n}\n\n/**\n * Removes a plugin or parser from `kubb.config.ts` and uninstalls its package. Refuses the adapter,\n * which the config needs, and an extension another one in the config depends on. Previews the\n * change before asking.\n */\nexport async function run({ id: input, configPath, yes, uninstall }: RemoveOptions): Promise<void> {\n const cwd = process.cwd()\n const hrStart = process.hrtime()\n const summary = (title: string, status: Parameters<typeof logCommandSummary>[0]['status'], lines: ReadonlyArray<string>) =>\n logCommandSummary({ title, status, hrStart, block: true, lines })\n const fail = (title: string, lines: ReadonlyArray<string>) => {\n summary(title, 'failed', lines)\n process.exitCode = 1\n }\n logIntro({ title: isInteractiveRun({ yes }) ? undefined : styleText('bgCyan', styleText('black', ' Kubb Remove ')) })\n\n try {\n const id = toRegistryId(input)\n const configFile = configPath ? path.resolve(configPath) : findConfigFile(cwd)\n if (!configFile)\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'No kubb.config.ts found. Pass its path with --config.',\n help: 'Run `kubb remove <id> --config <path>`.',\n })\n const configName = path.relative(cwd, configFile) || configFile\n const [entries, installed, source] = await withSpinner({\n message: 'Reading the registry',\n promise: Promise.all([fetchRegistryIndex({ registry: registryUrl() }), readInstalledPackages({ root: cwd }), read(configFile)]),\n })\n const versions = new Map(installed.map((item) => [item.package, item.version]))\n\n const entry = entries.find((candidate) => candidate.id === id)\n if (!entry) {\n const suggestions = closestIds({ input: id, ids: entries.map((candidate) => candidate.id) }).map(toShortId)\n return fail(\n `No extension named ${input}`,\n suggestions.map((suggestion) => ` kubb remove ${suggestion}`),\n )\n }\n const { artifact, manifest } = entry\n const kind = manifest.kind.charAt(0).toUpperCase() + manifest.kind.slice(1)\n if (manifest.kind === extensionKinds.adapter)\n return fail('The adapter cannot be removed', [` A config needs one adapter. Change it in ${configName} by hand.`])\n\n // Only calls that run count: a plugin Studio switched off is a comment, as in Studio's own check.\n const view = readConfig(source)\n const running = new Set(\n view.managed\n ? view.configs.flatMap((config) => [...config.plugins, ...(config.parsers ?? [])].filter((call) => !call.disabled).map((call) => call.packageName))\n : [],\n )\n const dependents = entries.filter(\n (other) => other.id !== entry.id && other.manifest.dependencies?.includes(manifest.name) && running.has(other.artifact.package),\n )\n if (dependents.length) {\n const names = dependents.map((other) => other.manifest.name).join(', ')\n return fail(`${names} ${dependents.length === 1 ? 'needs' : 'need'} ${manifest.name}`, [` Remove ${names} first.`])\n }\n\n const edits = [\n {\n operation: ConfigEditOperation.REMOVE_EXTENSION,\n ...(manifest.kind === extensionKinds.parser ? { kind: extensionKinds.parser } : {}),\n plugin: artifact.package,\n },\n ]\n const preview = editConfig({ source, edits })\n const outcome = preview.outcomes[0]\n if (!outcome?.applied) return fail(`Could not edit ${configName}`, [` ${outcome?.reason ?? 'the config file was not changed'}`])\n\n // Bundled extensions leave the config but stay installed.\n const bundled = BUNDLED_PACKAGES.includes(artifact.package)\n // Another `defineConfig` entry can still import it, and uninstalling it then breaks the config.\n const stillImported = readImports(preview.source).includes(artifact.package)\n const uninstalls = uninstall && !bundled && !stillImported && versions.has(artifact.package)\n if (!preview.changed && !uninstalls) {\n summary(`${manifest.name} is not in the project`, 'success', [' No changes made'])\n return\n }\n\n const packageLine = (() => {\n if (uninstalls) return `Uninstalls ${artifact.package}`\n if (bundled) return `Keeps ${artifact.package}, which ships with kubb`\n if (stillImported) return `Keeps ${artifact.package}, which another config entry still imports`\n return 'Uninstalls nothing'\n })()\n logStep(`${kind} ${styleText('cyan', manifest.name)} v${versions.get(artifact.package) ?? artifact.version}`)\n logBlock([\n `Config ${configName}`,\n ...removedLines({ before: source, after: preview.source }).map((line) => styleText('red', ` - ${line}`)),\n packageLine,\n ])\n\n const confirmed = yes || (await clack.confirm({ message: 'Remove it?', initialValue: true }))\n if (clack.isCancel(confirmed) || !confirmed) {\n summary('Remove canceled', 'canceled', [` ${kind} ${manifest.name}`, ' No changes made'])\n return\n }\n\n if (preview.changed) {\n const written = await editConfigFile({ filePath: configFile, edits })\n if (!written.outcomes[0]?.applied) return fail(`Could not edit ${configName}`, [` ${written.outcomes[0]?.reason ?? 'the config file was not changed'}`])\n logStep(`${manifest.export}() removed from ${configName}`)\n }\n const packageManager = detectPackageManager(cwd)\n if (uninstalls)\n await withSpinner({\n message: `Uninstalling ${artifact.package} with ${packageManager.name}`,\n promise: uninstallPackages([artifact.package], packageManager, cwd),\n })\n\n summary(`${kind} removed`, 'success', [\n ` Packages ${uninstalls ? `${artifact.package} uninstalled with ${packageManager.name}` : 'none uninstalled'}`,\n '',\n 'Next kubb generate',\n ])\n } catch (error) {\n logError(getErrorMessage(error))\n fail('Remove failed', [' See the error above'])\n }\n}\n\nexport const command = define({\n name: 'remove',\n description: 'Remove a plugin or parser from kubb.config.ts and uninstall its package.',\n examples: ['kubb remove plugin-zod', 'kubb remove acme/plugin-x --yes', 'kubb remove plugin-zod --no-uninstall'].join('\\n'),\n toKebab: true,\n args: {\n id: {\n type: 'positional',\n description: 'Registry id: owner/slug, or a slug for an official extension',\n required: true,\n },\n ...configArg,\n ...yesArg,\n uninstall: {\n type: 'boolean',\n description: 'Uninstall the package. Pass --no-uninstall to only edit the config',\n negatable: true,\n default: true,\n },\n },\n run: ({ values }) => run({ id: values.id, configPath: values.config, yes: values.yes, uninstall: values.uninstall }),\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2BA,SAAS,aAAa,EAAE,QAAQ,SAA2D;CACzF,MAAM,YAAY,MAAM,MAAM,IAAI;CAClC,OAAO,OACJ,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;IAAY;GAAM,CAAC;GACpE,IAAI,CAAC,QAAQ,SAAS,EAAE,EAAE,SAAS,OAAO,KAAK,kBAAkB,cAAc,CAAC,KAAK,QAAQ,SAAS,EAAE,EAAE,UAAU,mCAAmC,CAAC;GACxJ,QAAQ,GAAG,SAAS,OAAO,kBAAkB,YAAY;EAC3D;EACA,MAAM,iBAAiB,qBAAqB,GAAG;EAC/C,IAAI,YACF,MAAM,YAAY;GAChB,SAAS,gBAAgB,SAAS,QAAQ,QAAQ,eAAe;GACjE,SAAS,kBAAkB,CAAC,SAAS,OAAO,GAAG,gBAAgB,GAAG;EACpE,CAAC;EAEH,QAAQ,GAAG,KAAK,WAAW,WAAW;GACpC,eAAe,aAAa,GAAG,SAAS,QAAQ,oBAAoB,eAAe,SAAS;GAC5F;GACA;EACF,CAAC;CACH,SAAS,OAAO;EACd,SAAS,gBAAgB,KAAK,CAAC;EAC/B,KAAK,iBAAiB,CAAC,uBAAuB,CAAC;CACjD;AACF;AAEA,MAAa,UAAU,OAAO;CAC5B,MAAM;CACN,aAAa;CACb,UAAU;EAAC;EAA0B;EAAmC;CAAuC,CAAC,CAAC,KAAK,IAAI;CAC1H,SAAS;CACT,MAAM;EACJ,IAAI;GACF,MAAM;GACN,aAAa;GACb,UAAU;EACZ;EACA,GAAG;EACH,GAAG;EACH,WAAW;GACT,MAAM;GACN,aAAa;GACb,WAAW;GACX,SAAS;EACX;CACF;CACA,MAAM,EAAE,aAAa,IAAI;EAAE,IAAI,OAAO;EAAI,YAAY,OAAO;EAAQ,KAAK,OAAO;EAAK,WAAW,OAAO;CAAU,CAAC;AACrH,CAAC"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import "./rolldown-runtime-
|
|
2
|
-
import { n as toError } from "./errors-
|
|
3
|
-
import { n as trackRun } from "./Telemetry-
|
|
4
|
-
import { t as pluralize } from "./text-
|
|
5
|
-
import {
|
|
6
|
-
import { t as
|
|
1
|
+
import "./rolldown-runtime-xo6NMXYd.js";
|
|
2
|
+
import { n as toError } from "./errors-wzqmMpMo.js";
|
|
3
|
+
import { n as trackRun } from "./Telemetry-B3edcFoB.js";
|
|
4
|
+
import { t as pluralize } from "./text-BmiI4s6N.js";
|
|
5
|
+
import { t as findConfigFile } from "./config-CQTxXvIG.js";
|
|
6
|
+
import { t as getConfigs } from "./config-Uk3rbZfb.js";
|
|
7
|
+
import { t as logCommandSummary } from "./summary-CbmQKA8l.js";
|
|
7
8
|
import { styleText } from "node:util";
|
|
8
9
|
import process from "node:process";
|
|
9
10
|
import { resolve } from "node:path";
|
|
10
11
|
import { checkoutGitInput, getInputKind } from "@kubb/core";
|
|
11
|
-
|
|
12
|
+
// src/runners/validate/run.ts
|
|
12
13
|
/**
|
|
13
14
|
* Validates `input` with the configured adapters, falling back to OpenAPI when no config exists.
|
|
14
15
|
* Exits the process with code 1 on validation failure or missing dependency.
|
|
@@ -93,7 +94,6 @@ async function run({ input, configPath }) {
|
|
|
93
94
|
process.exit(1);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
|
-
//#endregion
|
|
97
97
|
export { run };
|
|
98
98
|
|
|
99
|
-
//# sourceMappingURL=run-
|
|
99
|
+
//# sourceMappingURL=run-C0KI-NE3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-
|
|
1
|
+
{"version":3,"file":"run-C0KI-NE3.js","names":[],"sources":["../src/runners/validate/run.ts"],"sourcesContent":["import process from 'node:process'\nimport { resolve } from 'node:path'\nimport { styleText } from 'node:util'\nimport { findConfigFile } from '@internals/shared'\nimport { toError } from '@internals/utils'\nimport { type Config, checkoutGitInput, getInputKind } from '@kubb/core'\nimport { trackRun } from '../../Telemetry.ts'\nimport { getConfigs } from '../../config.ts'\nimport { pluralize } from '../../ui/text.ts'\nimport { logCommandSummary } from '../../ui/summary.ts'\n\ntype ValidateOptions = {\n /**\n * Path, URL, or git input (`git+<repo>#<ref>:<path>`) of the specification to validate.\n */\n input: string\n configPath?: string\n}\n\n/**\n * Validates `input` with the configured adapters, falling back to OpenAPI when no config exists.\n * Exits the process with code 1 on validation failure or missing dependency.\n */\nexport async function run({ input, configPath }: ValidateOptions): Promise<void> {\n const hrStart = process.hrtime()\n const report = trackRun({ command: 'validate', hrStart })\n let adapterName: string | undefined\n\n try {\n const configFile = configPath ?? findConfigFile()\n // A config found by search that does not load must not block validating a file; an explicit `--config` still fails.\n const loaded = configFile\n ? await getConfigs({ configPath: configFile, input }).catch((error) => {\n if (configPath) throw error\n })\n : undefined\n const fallback = async () => {\n adapterName = '@kubb/adapter-oas'\n const { adapterOas } = await import('@kubb/adapter-oas')\n return [{ adapter: adapterOas(), input }]\n }\n // An array config often repeats one adapter, so each adapter and input pair is validated once.\n const unique = new Map(\n (loaded?.configs ?? []).map((config) => {\n const resolved = getInputKind(input) === 'file' ? resolve(config.root || process.cwd(), input) : input\n return [`${config.adapter?.name}\\0${resolved}`, { adapter: config.adapter, input: resolved }] as const\n }),\n )\n const targets: Array<{ adapter: Config['adapter']; input: string }> = loaded ? [...unique.values()] : await fallback()\n if (!targets.length) throw new Error('The Kubb config contains no configurations to validate.')\n for (const target of targets) {\n adapterName = target.adapter?.name\n if (!target.adapter) throw new Error('No adapter is configured. Set adapter in your Kubb config to validate this specification.')\n const checkout = getInputKind(target.input) === 'git' ? await checkoutGitInput(target.input) : undefined\n try {\n await target.adapter.validate(checkout?.path ?? target.input, { throwOnError: true })\n } finally {\n await checkout?.dispose()\n }\n }\n const specifications = new Set(targets.map((target) => target.input)).size\n const adapterNames = [...new Set(targets.flatMap((target) => target.adapter?.name ?? []))]\n await report({ status: 'success' })\n\n logCommandSummary({\n title: 'Validation passed',\n status: 'success',\n hrStart,\n lines: [\n ` ${styleText('bold', `${pluralize(specifications, 'specification')} validated`)}`,\n ` ${styleText('dim', 'Input')} ${styleText('cyan', input)}`,\n ` ${styleText('dim', adapterNames.length === 1 ? 'Adapter' : 'Adapters')} ${adapterNames.join(', ')}`,\n ],\n })\n } catch (error) {\n await report({ status: 'failed' })\n const message = toError(error).message\n const missingAdapter = adapterName === '@kubb/adapter-oas' && /(?:Cannot find|Cannot resolve|not found)[\\s\\S]*@kubb\\/adapter-oas/.test(message)\n logCommandSummary({\n title: missingAdapter ? 'Could not validate' : 'Validation failed',\n status: 'failed',\n hrStart,\n lines: [\n ` ${styleText('dim', 'Input')} ${styleText('cyan', input)}`,\n ` ${styleText('dim', 'Adapter')} ${adapterName ?? 'not configured'}${missingAdapter ? ' · not installed' : ''}`,\n '',\n styleText('bold', missingAdapter ? 'Required package' : 'Validation error'),\n ` ${styleText('red', message)}`,\n ...(missingAdapter\n ? ['', 'Install it with:', styleText('cyan', ' npm install @kubb/adapter-oas'), styleText('cyan', ' pnpm add @kubb/adapter-oas')]\n : []),\n ],\n })\n\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuBA,eAAsB,IAAI,EAAE,OAAO,cAA8C;CAC/E,MAAM,UAAU,QAAQ,OAAO;CAC/B,MAAM,SAAS,SAAS;EAAE,SAAS;EAAY;CAAQ,CAAC;CACxD,IAAI;CAEJ,IAAI;EACF,MAAM,aAAa,cAAc,eAAe;EAEhD,MAAM,SAAS,aACX,MAAM,WAAW;GAAE,YAAY;GAAY;EAAM,CAAC,CAAC,CAAC,OAAO,UAAU;GACnE,IAAI,YAAY,MAAM;EACxB,CAAC,IACD,KAAA;EACJ,MAAM,WAAW,YAAY;GAC3B,cAAc;GACd,MAAM,EAAE,eAAe,MAAM,OAAO;GACpC,OAAO,CAAC;IAAE,SAAS,WAAW;IAAG;GAAM,CAAC;EAC1C;EAEA,MAAM,SAAS,IAAI,KAChB,QAAQ,WAAW,CAAC,EAAA,CAAG,KAAK,WAAW;GACtC,MAAM,WAAW,aAAa,KAAK,MAAM,SAAS,QAAQ,OAAO,QAAQ,QAAQ,IAAI,GAAG,KAAK,IAAI;GACjG,OAAO,CAAC,GAAG,OAAO,SAAS,KAAK,IAAI,YAAY;IAAE,SAAS,OAAO;IAAS,OAAO;GAA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R;GACA,OAAO;IACL,KAAK,UAAU,OAAO,OAAO,EAAE,MAAM,UAAU,QAAQ,KAAK;IAC5D,KAAK,UAAU,OAAO,SAAS,EAAE,IAAI,eAAe,mBAAmB,iBAAiB,qBAAqB;IAC7G;IACA,UAAU,QAAQ,iBAAiB,qBAAqB,kBAAkB;IAC1E,KAAK,UAAU,OAAO,OAAO;IAC7B,GAAI,iBACA;KAAC;KAAI;KAAoB,UAAU,QAAQ,iCAAiC;KAAG,UAAU,QAAQ,8BAA8B;IAAC,IAChI,CAAC;GACP;EACF,CAAC;EAED,QAAQ,KAAK,CAAC;CAChB;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as connect, a as login, s as resolvePermissions, c as runStudio } from "./run-KqdudiWQ.js";
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import "./rolldown-runtime-xo6NMXYd.js";
|
|
2
|
+
import { a as ConfigEditOperation, t as editConfig } from "./configFile-C0DIXNMD.js";
|
|
3
|
+
import { n as getElapsedMs, t as formatMs } from "./time-C-wU7VhC.js";
|
|
4
|
+
import { r as exists, s as write, t as createSpinner } from "./spinner-BZaln7O8.js";
|
|
5
|
+
import { t as version } from "./package-D3Yss9Bb.js";
|
|
6
|
+
import { l as logStep, n as logIntro, o as logBlock, r as logOutro, s as logError, t as isInteractiveRun, u as logWarn } from "./intro-9PB8sE8z.js";
|
|
7
|
+
import { n as dryRunId } from "./shared-Ct9stKpp.js";
|
|
8
|
+
import { t as pluralize } from "./text-BmiI4s6N.js";
|
|
9
|
+
import { a as KUBB_CONFIG_FILENAME, o as KUBB_PACKAGE_NAME, s as initDefaults } from "./config-CQTxXvIG.js";
|
|
10
|
+
import { t as getConfigs } from "./config-Uk3rbZfb.js";
|
|
11
|
+
import { a as installSpec, i as incompatibility, r as fetchRegistryIndex, s as registryUrl } from "./registry-B3eYk4LN.js";
|
|
12
|
+
import { a as generateScript, c as missingPluginDependencies, i as findSpecFiles, l as parsePluginsFlag, n as detectPackageManager, o as initPackageJson, r as findPlugin, s as installPackages, t as addGenerateScript, u as readSpecInfo } from "./utils-CbJ6hS_t.js";
|
|
13
|
+
import { t as installWithSpinner } from "./installWithSpinner-DpnpxHq5.js";
|
|
14
|
+
import { styleText } from "node:util";
|
|
15
|
+
import { defineWithTypes } from "gunshi";
|
|
16
|
+
import process from "node:process";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import * as clack from "@clack/prompts";
|
|
19
|
+
import { Diagnostics, createKubb } from "@kubb/core";
|
|
20
|
+
// ../../internals/shared/src/init.ts
|
|
21
|
+
/** The `kubb.config.ts` `kubb init` writes before `kubb add` puts each plugin in. */
|
|
22
|
+
function generateConfigFile({ inputPath, outputPath }) {
|
|
23
|
+
return `import { defineConfig } from 'kubb/config'
|
|
24
|
+
|
|
25
|
+
export default defineConfig({
|
|
26
|
+
input: '${inputPath}',
|
|
27
|
+
output: {
|
|
28
|
+
path: '${outputPath}',
|
|
29
|
+
clean: true,
|
|
30
|
+
},
|
|
31
|
+
plugins: [],
|
|
32
|
+
})
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
// src/runners/init/run.ts
|
|
36
|
+
function cancelAndExit(message = "Operation canceled.") {
|
|
37
|
+
clack.cancel(message);
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
function unwrap(value) {
|
|
41
|
+
if (clack.isCancel(value)) cancelAndExit();
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
/** The full `kubb.config.ts` for `choices`, with each plugin added the way `kubb add` adds it. */
|
|
45
|
+
function buildConfig({ inputPath, outputPath, plugins }) {
|
|
46
|
+
const { source, outcomes } = editConfig({
|
|
47
|
+
source: generateConfigFile({
|
|
48
|
+
inputPath,
|
|
49
|
+
outputPath
|
|
50
|
+
}),
|
|
51
|
+
edits: plugins.map((entry) => ({
|
|
52
|
+
operation: ConfigEditOperation.ADD_PLUGIN,
|
|
53
|
+
plugin: entry.artifact.package
|
|
54
|
+
})),
|
|
55
|
+
extensions: new Map(plugins.map(({ artifact, manifest }) => [artifact.package, {
|
|
56
|
+
package: artifact.package,
|
|
57
|
+
version: artifact.version,
|
|
58
|
+
manifest
|
|
59
|
+
}]))
|
|
60
|
+
});
|
|
61
|
+
const failed = outcomes.find((outcome) => !outcome.applied);
|
|
62
|
+
if (failed && failed.edit.operation === ConfigEditOperation.ADD_PLUGIN) throw new Diagnostics.Error({
|
|
63
|
+
code: Diagnostics.code.unknown,
|
|
64
|
+
severity: "error",
|
|
65
|
+
message: `Could not add ${failed.edit.plugin} to ${KUBB_CONFIG_FILENAME}: ${failed.reason}`,
|
|
66
|
+
help: `Run kubb init without that plugin, then add it with kubb add.`
|
|
67
|
+
});
|
|
68
|
+
return source;
|
|
69
|
+
}
|
|
70
|
+
/** Generates from the config at `configPath` without reporters, and returns how many files it wrote. */
|
|
71
|
+
async function firstRun(configPath) {
|
|
72
|
+
const { configs } = await getConfigs({ configPath });
|
|
73
|
+
let files = 0;
|
|
74
|
+
for (const config of configs) {
|
|
75
|
+
const result = await createKubb(config).generate();
|
|
76
|
+
if (!result.success) throw new Error(result.diagnostics.flatMap((diagnostic) => diagnostic.severity === "error" ? [diagnostic.message] : []).join("\n"));
|
|
77
|
+
files += result.files.length;
|
|
78
|
+
}
|
|
79
|
+
return files;
|
|
80
|
+
}
|
|
81
|
+
/** The command that runs `kubb generate`: the `generate` script when it runs Kubb, otherwise `npx kubb generate`. */
|
|
82
|
+
function generateCommand({ packageManager, script, watch }) {
|
|
83
|
+
if (script !== "kubb generate") return `npx kubb generate${watch ? " --watch" : ""}`;
|
|
84
|
+
const run = [
|
|
85
|
+
packageManager.name,
|
|
86
|
+
...packageManager.runCommand,
|
|
87
|
+
"generate"
|
|
88
|
+
].join(" ");
|
|
89
|
+
if (!watch) return run;
|
|
90
|
+
return packageManager.name === "npm" ? `${run} -- --watch` : `${run} --watch`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Runs the Kubb setup wizard: detects the package manager and specs, asks for the spec, plugins, and
|
|
94
|
+
* output folder, shows the config for review, then installs, writes `kubb.config.ts`, adds a
|
|
95
|
+
* `generate` script, and runs the first generation.
|
|
96
|
+
* Pass `yes: true` to skip all prompts and print one line per step.
|
|
97
|
+
*/
|
|
98
|
+
async function run({ yes, input: inputFlag, output: outputFlag, plugins: pluginsFlag, dryRun }) {
|
|
99
|
+
const cwd = process.cwd();
|
|
100
|
+
/** Runs `task` behind a spinner, or prints one line when it is done in `--yes` mode. */
|
|
101
|
+
async function step({ start, task, done, failed }) {
|
|
102
|
+
const spinner = createSpinner();
|
|
103
|
+
if (!yes) spinner.start(start);
|
|
104
|
+
try {
|
|
105
|
+
const result = await task();
|
|
106
|
+
if (yes) console.log(`${styleText("green", "✓")} ${done(result)}`);
|
|
107
|
+
else spinner.stop(done(result));
|
|
108
|
+
return result;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (!yes) spinner.error(failed);
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!yes) logIntro({ title: isInteractiveRun({
|
|
115
|
+
yes,
|
|
116
|
+
dryRun: dryRun.enabled
|
|
117
|
+
}) ? void 0 : "Set up Kubb" });
|
|
118
|
+
try {
|
|
119
|
+
const registry = fetchRegistryIndex({ registry: registryUrl() }).then((entries) => entries.filter((entry) => entry.kind === "plugin" && !incompatibility(entry.manifest)));
|
|
120
|
+
registry.catch(() => {});
|
|
121
|
+
if (!await exists(path.join(cwd, "package.json"))) {
|
|
122
|
+
if (!yes) {
|
|
123
|
+
if (!unwrap(await clack.confirm({
|
|
124
|
+
message: "No package.json found. Would you like to create one?",
|
|
125
|
+
initialValue: true
|
|
126
|
+
}))) cancelAndExit();
|
|
127
|
+
}
|
|
128
|
+
const packageManager = detectPackageManager(cwd);
|
|
129
|
+
await step({
|
|
130
|
+
start: `Initializing package.json with ${packageManager.name}`,
|
|
131
|
+
task: () => initPackageJson(cwd, packageManager),
|
|
132
|
+
done: () => `Created package.json with ${packageManager.name}`,
|
|
133
|
+
failed: "Could not create package.json"
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const packageManager = detectPackageManager(cwd);
|
|
137
|
+
const specs = await findSpecFiles(cwd);
|
|
138
|
+
if (!yes) {
|
|
139
|
+
logStep(`Package manager ${packageManager.name}`);
|
|
140
|
+
if (specs[0]) {
|
|
141
|
+
const { version: specVersion, operations } = await readSpecInfo(path.join(cwd, specs[0]));
|
|
142
|
+
const details = [
|
|
143
|
+
specs[0].slice(2),
|
|
144
|
+
specVersion ? `${specVersion.startsWith("2") ? "Swagger" : "OpenAPI"} ${specVersion}` : void 0,
|
|
145
|
+
operations === void 0 ? void 0 : pluralize(operations, "operation"),
|
|
146
|
+
specs.length > 1 ? `+${specs.length - 1} more` : void 0
|
|
147
|
+
];
|
|
148
|
+
logStep(`Found ${details.filter(Boolean).join(" · ")}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const plugins = pluginsFlag || yes ? await registry : void 0;
|
|
152
|
+
const defaultPlugins = (entries) => initDefaults.plugins.flatMap((id) => findPlugin({
|
|
153
|
+
plugins: entries,
|
|
154
|
+
id
|
|
155
|
+
}) ?? []);
|
|
156
|
+
const flagPlugins = pluginsFlag && plugins ? parsePluginsFlag({
|
|
157
|
+
plugins,
|
|
158
|
+
value: pluginsFlag
|
|
159
|
+
}) : void 0;
|
|
160
|
+
let choices = {
|
|
161
|
+
inputPath: inputFlag ?? specs[0] ?? initDefaults.inputPath,
|
|
162
|
+
outputPath: outputFlag ?? initDefaults.outputPath,
|
|
163
|
+
plugins: flagPlugins ?? (plugins ? defaultPlugins(plugins) : [])
|
|
164
|
+
};
|
|
165
|
+
if (yes && !choices.plugins.length) throw new Error("The registry has no default plugin. Pass --plugins to choose one.");
|
|
166
|
+
async function askInput(current) {
|
|
167
|
+
const choice = specs.length ? unwrap(await clack.select({
|
|
168
|
+
message: "Which spec should Kubb read?",
|
|
169
|
+
options: [
|
|
170
|
+
...specs.map((spec) => ({
|
|
171
|
+
value: spec,
|
|
172
|
+
label: spec,
|
|
173
|
+
hint: "found in this repo"
|
|
174
|
+
})),
|
|
175
|
+
{
|
|
176
|
+
value: "url",
|
|
177
|
+
label: "A URL"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
value: "file",
|
|
181
|
+
label: "Another file"
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
initialValue: specs.includes(current) ? current : /^https?:\/\//.test(current) ? "url" : "file"
|
|
185
|
+
})) : /^https?:\/\//.test(current) ? "url" : "file";
|
|
186
|
+
if (specs.includes(choice)) return choice;
|
|
187
|
+
const isUrl = choice === "url";
|
|
188
|
+
const initial = isUrl === /^https?:\/\//.test(current) && !specs.includes(current) ? current : void 0;
|
|
189
|
+
return unwrap(await clack.text({
|
|
190
|
+
message: isUrl ? "Spec URL" : "Spec path",
|
|
191
|
+
placeholder: isUrl ? "https://example.com/openapi.yaml" : initDefaults.inputPath,
|
|
192
|
+
initialValue: initial,
|
|
193
|
+
defaultValue: isUrl ? void 0 : initDefaults.inputPath,
|
|
194
|
+
validate: (value) => {
|
|
195
|
+
if (isUrl && !/^https?:\/\//.test(value ?? "")) return "Enter an http(s) URL";
|
|
196
|
+
}
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
async function askPlugins(previous) {
|
|
200
|
+
const plugins = await registry;
|
|
201
|
+
const current = previous.length ? previous : defaultPlugins(plugins);
|
|
202
|
+
const width = Math.max(...plugins.map((entry) => entry.manifest.displayName.length));
|
|
203
|
+
const nameWidth = Math.max(...plugins.map((entry) => entry.manifest.name.length));
|
|
204
|
+
const values = unwrap(await clack.multiselect({
|
|
205
|
+
message: "What should Kubb generate?",
|
|
206
|
+
options: plugins.map(({ id, manifest }) => ({
|
|
207
|
+
value: id,
|
|
208
|
+
label: `${manifest.displayName.padEnd(width)} ${styleText("dim", manifest.name.padEnd(nameWidth))}`.trimEnd()
|
|
209
|
+
})),
|
|
210
|
+
initialValues: current.map((entry) => entry.id),
|
|
211
|
+
required: true
|
|
212
|
+
}));
|
|
213
|
+
return plugins.filter((entry) => values.includes(entry.id));
|
|
214
|
+
}
|
|
215
|
+
const answered = yes || Boolean(inputFlag && outputFlag && pluginsFlag);
|
|
216
|
+
if (!answered) {
|
|
217
|
+
let firstPass = true;
|
|
218
|
+
while (true) {
|
|
219
|
+
choices = {
|
|
220
|
+
inputPath: firstPass && inputFlag ? inputFlag : await askInput(choices.inputPath),
|
|
221
|
+
plugins: firstPass && flagPlugins ? flagPlugins : await askPlugins(choices.plugins),
|
|
222
|
+
outputPath: firstPass && outputFlag ? outputFlag : unwrap(await clack.text({
|
|
223
|
+
message: "Output folder",
|
|
224
|
+
placeholder: choices.outputPath,
|
|
225
|
+
defaultValue: choices.outputPath
|
|
226
|
+
}))
|
|
227
|
+
};
|
|
228
|
+
firstPass = false;
|
|
229
|
+
const missing = missingPluginDependencies(choices.plugins.map((entry) => entry.manifest));
|
|
230
|
+
if (missing.length) {
|
|
231
|
+
logWarn(`${missing.join("\n")}\nAdd the missing plugins.`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const config = buildConfig(choices);
|
|
235
|
+
const packages = [KUBB_PACKAGE_NAME, ...choices.plugins.map((entry) => entry.artifact.package)];
|
|
236
|
+
logStep(`Review ${KUBB_CONFIG_FILENAME}`);
|
|
237
|
+
logBlock([
|
|
238
|
+
...config.trimEnd().split("\n"),
|
|
239
|
+
"",
|
|
240
|
+
`${styleText("dim", "Installs")} ${packages.join(" ")} with ${packageManager.name}`
|
|
241
|
+
]);
|
|
242
|
+
const configExists = await exists(path.join(cwd, KUBB_CONFIG_FILENAME));
|
|
243
|
+
if (unwrap(await clack.select({
|
|
244
|
+
message: configExists ? `kubb.config.ts exists. Overwrite it?` : "Create it?",
|
|
245
|
+
options: [{
|
|
246
|
+
value: true,
|
|
247
|
+
label: "Yes"
|
|
248
|
+
}, {
|
|
249
|
+
value: false,
|
|
250
|
+
label: "Change a choice"
|
|
251
|
+
}]
|
|
252
|
+
}))) break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const missing = missingPluginDependencies(choices.plugins.map((entry) => entry.manifest));
|
|
256
|
+
if (missing.length) throw new Diagnostics.Error({
|
|
257
|
+
code: Diagnostics.code.missingDependency,
|
|
258
|
+
severity: "error",
|
|
259
|
+
message: `${missing.join("\n")}\nAdd the missing plugins and run kubb init again.`
|
|
260
|
+
});
|
|
261
|
+
const configPath = path.join(cwd, KUBB_CONFIG_FILENAME);
|
|
262
|
+
if (answered && !yes && await exists(configPath)) {
|
|
263
|
+
if (!unwrap(await clack.confirm({
|
|
264
|
+
message: `kubb.config.ts exists. Overwrite it?`,
|
|
265
|
+
initialValue: false
|
|
266
|
+
}))) cancelAndExit("Keeping existing configuration.");
|
|
267
|
+
}
|
|
268
|
+
const packagesToInstall = [`${KUBB_PACKAGE_NAME}@${version}`, ...choices.plugins.map((entry) => installSpec(entry.artifact))];
|
|
269
|
+
const packageNames = [KUBB_PACKAGE_NAME, ...choices.plugins.map((entry) => entry.artifact.package)];
|
|
270
|
+
const dry = { message: `install ${packagesToInstall.length} packages with ${packageManager.name}` };
|
|
271
|
+
if (yes) await step({
|
|
272
|
+
start: "",
|
|
273
|
+
task: async () => void await dryRun.run(() => installPackages(packagesToInstall, packageManager, cwd), dry),
|
|
274
|
+
done: () => `Installed ${packageNames.join(" ")} with ${packageManager.name}`,
|
|
275
|
+
failed: "Installation failed"
|
|
276
|
+
});
|
|
277
|
+
else await installWithSpinner({
|
|
278
|
+
packages: packagesToInstall,
|
|
279
|
+
names: `${packagesToInstall.length} packages`,
|
|
280
|
+
packageManager,
|
|
281
|
+
cwd,
|
|
282
|
+
install: async (packages, packageManager, cwd, onLine) => void await dryRun.run(() => installPackages(packages, packageManager, cwd, onLine), dry)
|
|
283
|
+
});
|
|
284
|
+
await step({
|
|
285
|
+
start: `Writing ${KUBB_CONFIG_FILENAME}`,
|
|
286
|
+
task: async () => dryRun.run(async () => void await write(configPath, buildConfig(choices)), { message: `write ${KUBB_CONFIG_FILENAME}` }),
|
|
287
|
+
done: () => `Wrote ${KUBB_CONFIG_FILENAME}`,
|
|
288
|
+
failed: `Could not write ${KUBB_CONFIG_FILENAME}`
|
|
289
|
+
});
|
|
290
|
+
const scriptAdded = await dryRun.run(() => addGenerateScript(cwd), {
|
|
291
|
+
message: "add a generate script to package.json",
|
|
292
|
+
resolve: async () => await generateScript(cwd) === void 0
|
|
293
|
+
});
|
|
294
|
+
if (scriptAdded && !yes) logStep("Added \"generate\": \"kubb generate\" to package.json");
|
|
295
|
+
const script = scriptAdded ? "kubb generate" : await generateScript(cwd);
|
|
296
|
+
const runStart = process.hrtime();
|
|
297
|
+
try {
|
|
298
|
+
await dryRun.run(() => step({
|
|
299
|
+
start: "Running the first generation",
|
|
300
|
+
task: () => firstRun(configPath),
|
|
301
|
+
done: (files) => yes ? `Generated ${pluralize(files, "file")} in ${choices.outputPath}` : `First run ${pluralize(files, "file")} in ${choices.outputPath} · ${formatMs(getElapsedMs(runStart))}`,
|
|
302
|
+
failed: "First run failed"
|
|
303
|
+
}), {
|
|
304
|
+
message: "run the first generation",
|
|
305
|
+
resolve: () => 0
|
|
306
|
+
});
|
|
307
|
+
} catch (error) {
|
|
308
|
+
logError(error instanceof Error ? error.message : String(error));
|
|
309
|
+
const message = `Kubb is set up, but the first run failed. Fix the error, then run ${generateCommand({
|
|
310
|
+
packageManager,
|
|
311
|
+
script,
|
|
312
|
+
watch: false
|
|
313
|
+
})}.`;
|
|
314
|
+
if (yes) console.log(message);
|
|
315
|
+
else logOutro(styleText("yellow", message));
|
|
316
|
+
process.exitCode = 1;
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (yes) {
|
|
320
|
+
console.log(`Kubb is set up. Run ${generateCommand({
|
|
321
|
+
packageManager,
|
|
322
|
+
script,
|
|
323
|
+
watch: false
|
|
324
|
+
})} after changing the spec.`);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
logOutro(`${styleText("green", "✓ Kubb is set up")}\n ${styleText("dim", "Next")} ${generateCommand({
|
|
328
|
+
packageManager,
|
|
329
|
+
script,
|
|
330
|
+
watch: true
|
|
331
|
+
})}`);
|
|
332
|
+
} catch (error) {
|
|
333
|
+
logError(styleText("red", "An error occurred during initialization"));
|
|
334
|
+
if (error instanceof Error) logError(error.message);
|
|
335
|
+
process.exit(1);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const command = defineWithTypes()({
|
|
339
|
+
name: "init",
|
|
340
|
+
description: "Set up a config, install plugins, and run the first generation.",
|
|
341
|
+
examples: [
|
|
342
|
+
"kubb init",
|
|
343
|
+
"kubb init --yes",
|
|
344
|
+
"kubb init --input ./openapi.yaml --output ./src/gen --plugins plugin-ts,plugin-zod",
|
|
345
|
+
"kubb init --yes --input ./openapi.yaml --plugins ts,zod --output src/api",
|
|
346
|
+
"kubb init --plugins plugin-ts,plugin-axios,plugin-react-query",
|
|
347
|
+
"kubb init --yes --dry-run"
|
|
348
|
+
].join("\n"),
|
|
349
|
+
toKebab: true,
|
|
350
|
+
args: {
|
|
351
|
+
yes: {
|
|
352
|
+
type: "boolean",
|
|
353
|
+
description: "Skip prompts and use the detected spec, the default plugin, and the default output folder",
|
|
354
|
+
short: "y",
|
|
355
|
+
default: false
|
|
356
|
+
},
|
|
357
|
+
input: {
|
|
358
|
+
type: "string",
|
|
359
|
+
description: "Path to the OpenAPI specification",
|
|
360
|
+
short: "i",
|
|
361
|
+
metavar: "path"
|
|
362
|
+
},
|
|
363
|
+
output: {
|
|
364
|
+
type: "string",
|
|
365
|
+
description: "Output directory for generated files",
|
|
366
|
+
short: "o",
|
|
367
|
+
metavar: "path"
|
|
368
|
+
},
|
|
369
|
+
plugins: {
|
|
370
|
+
type: "string",
|
|
371
|
+
description: "Comma-separated Kubb registry ids of the plugins to add, the same ids `kubb add` takes (plugin-ts, plugin-zod, acme/plugin-x), or short names (ts, zod)",
|
|
372
|
+
metavar: "plugin-ts,plugin-zod,..."
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
run: ({ values, extensions }) => run({
|
|
376
|
+
yes: values.yes,
|
|
377
|
+
input: values.input,
|
|
378
|
+
output: values.output,
|
|
379
|
+
plugins: values.plugins,
|
|
380
|
+
dryRun: extensions[dryRunId]
|
|
381
|
+
})
|
|
382
|
+
});
|
|
383
|
+
export { command, run };
|
|
384
|
+
|
|
385
|
+
//# sourceMappingURL=run-CCsdLz3X.js.map
|