@kode-ai-tools/cli 0.1.5 → 0.1.7
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.js +8953 -0
- package/package.json +6 -26
- package/prompt-C1_FgRkG.js +672 -0
- package/dist/bin.js +0 -260
package/dist/bin.js
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Command as u } from "commander";
|
|
3
|
-
import * as c from "node:fs";
|
|
4
|
-
import * as l from "node:path";
|
|
5
|
-
import r from "consola";
|
|
6
|
-
import y, { YAMLMap as h, isMap as d } from "yaml";
|
|
7
|
-
function w(t, e) {
|
|
8
|
-
return { name: t, status: e ? "pass" : "fail" };
|
|
9
|
-
}
|
|
10
|
-
const F = new u("doctor").description("Validate project structure for OpenAPI tooling").action(() => {
|
|
11
|
-
const t = process.cwd(), e = l.join(t, "openapi"), i = c.existsSync(e) && c.statSync(e).isDirectory(), n = [
|
|
12
|
-
w("openapi/ directory", i),
|
|
13
|
-
w("openapi/AGENT.md", i && c.existsSync(l.join(e, "AGENT.md")))
|
|
14
|
-
], o = Math.max(...n.map((p) => p.name.length));
|
|
15
|
-
r.log("");
|
|
16
|
-
for (const p of n) {
|
|
17
|
-
const s = p.status === "pass" ? "✔" : "✘", f = p.status === "pass" ? "pass" : "FAIL";
|
|
18
|
-
r.log(` ${s} ${p.name.padEnd(o)} ${f}`);
|
|
19
|
-
}
|
|
20
|
-
r.log("");
|
|
21
|
-
const a = n.filter((p) => p.status === "fail");
|
|
22
|
-
a.length > 0 && (r.error(`${a.length} check(s) failed`), process.exit(1)), r.success("All checks passed");
|
|
23
|
-
});
|
|
24
|
-
function S(t) {
|
|
25
|
-
c.existsSync(t) || c.mkdirSync(t, { recursive: !0 });
|
|
26
|
-
}
|
|
27
|
-
function g(t, e) {
|
|
28
|
-
const i = [];
|
|
29
|
-
if (!c.existsSync(t))
|
|
30
|
-
return i;
|
|
31
|
-
for (const n of c.readdirSync(t, { withFileTypes: !0 })) {
|
|
32
|
-
const o = l.join(t, n.name);
|
|
33
|
-
n.isDirectory() ? i.push(...g(o, e)) : n.isFile() && e(n.name) && i.push(o);
|
|
34
|
-
}
|
|
35
|
-
return i;
|
|
36
|
-
}
|
|
37
|
-
function $(t, e, i) {
|
|
38
|
-
const n = new Map(t.map((s) => [s.urlPath, s])), o = [
|
|
39
|
-
...i.paths.map((s) => n.get(s)).filter((s) => s !== void 0),
|
|
40
|
-
...t.filter((s) => !i.paths.includes(s.urlPath))
|
|
41
|
-
], a = new Map(e.map((s) => [`${s.section}/${s.name}`, s])), p = [
|
|
42
|
-
...i.components.map((s) => a.get(s)).filter((s) => s !== void 0),
|
|
43
|
-
...e.filter((s) => !i.components.includes(`${s.section}/${s.name}`))
|
|
44
|
-
];
|
|
45
|
-
return { paths: o, components: p };
|
|
46
|
-
}
|
|
47
|
-
function j({ core: t, files: e }) {
|
|
48
|
-
const i = new h(), n = /* @__PURE__ */ new Map();
|
|
49
|
-
for (const o of e)
|
|
50
|
-
o.kind === "path" ? i.add(t.createPair(o.pair.key, o.pair.value)) : o.kind === "component" && (n.has(o.section) || n.set(o.section, new h()), n.get(o.section)?.add(t.createPair(o.pair.key, o.pair.value)));
|
|
51
|
-
if (i.items.length > 0 && t.set("paths", i), n.size > 0) {
|
|
52
|
-
const o = new h();
|
|
53
|
-
for (const [a, p] of n)
|
|
54
|
-
o.add(t.createPair(a, p));
|
|
55
|
-
t.set("components", o);
|
|
56
|
-
}
|
|
57
|
-
return t;
|
|
58
|
-
}
|
|
59
|
-
function m(t) {
|
|
60
|
-
return t != null && typeof t == "object" && "value" in t ? String(t.value) : String(t);
|
|
61
|
-
}
|
|
62
|
-
function x(t) {
|
|
63
|
-
return t.replace(/[:*?"<>|]/g, "_");
|
|
64
|
-
}
|
|
65
|
-
function P(t) {
|
|
66
|
-
const e = t.split("/").filter(Boolean);
|
|
67
|
-
if (e.length === 0)
|
|
68
|
-
return "root.yaml";
|
|
69
|
-
const i = e.pop();
|
|
70
|
-
if (!i)
|
|
71
|
-
return "root.yaml";
|
|
72
|
-
const n = e.map(x).join("/"), o = `${x(i)}.yaml`;
|
|
73
|
-
return n ? `${n}/${o}` : o;
|
|
74
|
-
}
|
|
75
|
-
function b(t, e, i) {
|
|
76
|
-
const n = i ? `${e}/${i}.yaml` : e, o = A(t), a = j(o);
|
|
77
|
-
c.writeFileSync(n, a.toString(), "utf-8");
|
|
78
|
-
}
|
|
79
|
-
function A(t) {
|
|
80
|
-
const e = l.join(t, "openapi.yaml"), i = l.join(t, "manifest.json");
|
|
81
|
-
if (!c.existsSync(e))
|
|
82
|
-
throw new Error(`Not found: ${e}`);
|
|
83
|
-
const n = y.parseDocument(c.readFileSync(e, "utf-8")), o = c.existsSync(i) ? JSON.parse(c.readFileSync(i, "utf-8")) : null;
|
|
84
|
-
let a = M(t), p = O(t);
|
|
85
|
-
if (o) {
|
|
86
|
-
const f = $(a, p, o);
|
|
87
|
-
a = f.paths, p = f.components;
|
|
88
|
-
}
|
|
89
|
-
const s = [...a, ...p];
|
|
90
|
-
return o ? { core: n, files: s, manifest: { kind: "manifest", manifest: o } } : { core: n, files: s };
|
|
91
|
-
}
|
|
92
|
-
function M(t) {
|
|
93
|
-
const e = l.join(t, "paths");
|
|
94
|
-
if (!c.existsSync(e))
|
|
95
|
-
return [];
|
|
96
|
-
const i = [];
|
|
97
|
-
for (const n of g(e, (o) => o.endsWith(".yaml"))) {
|
|
98
|
-
const o = c.readFileSync(n, "utf-8"), p = y.parseDocument(o).contents;
|
|
99
|
-
if (!p?.items?.length)
|
|
100
|
-
continue;
|
|
101
|
-
const s = p.items[0];
|
|
102
|
-
if (!s)
|
|
103
|
-
continue;
|
|
104
|
-
const f = m(s.key), k = l.relative(e, n);
|
|
105
|
-
i.push({ kind: "path", urlPath: f, relativePath: k, pair: s });
|
|
106
|
-
}
|
|
107
|
-
return i;
|
|
108
|
-
}
|
|
109
|
-
function O(t) {
|
|
110
|
-
const e = l.join(t, "components");
|
|
111
|
-
if (!c.existsSync(e))
|
|
112
|
-
return [];
|
|
113
|
-
const i = [];
|
|
114
|
-
for (const n of g(e, (o) => o.endsWith(".yaml")).sort()) {
|
|
115
|
-
const o = c.readFileSync(n, "utf-8"), p = y.parseDocument(o).contents;
|
|
116
|
-
if (!p?.items?.length)
|
|
117
|
-
continue;
|
|
118
|
-
const s = p.items[0];
|
|
119
|
-
if (!s)
|
|
120
|
-
continue;
|
|
121
|
-
const f = l.relative(e, n).split(l.sep)[0];
|
|
122
|
-
f && i.push({ kind: "component", section: f, name: m(s.key), pair: s });
|
|
123
|
-
}
|
|
124
|
-
return i;
|
|
125
|
-
}
|
|
126
|
-
function I(t) {
|
|
127
|
-
return c.existsSync(t) ? c.readdirSync(t, { withFileTypes: !0 }).filter((e) => e.isDirectory()).map((e) => e.name) : [];
|
|
128
|
-
}
|
|
129
|
-
const C = new u("merge").description("Merge split OpenAPI spec files back into one").argument("[input]", "path to the split spec directory").argument("[output]", "output path").option("-f, --file-name <name>", "output file name (without .yaml extension)").option("--non-interactive", "disable interactive prompts").action(async (t, e, i) => {
|
|
130
|
-
if (!t || !e) {
|
|
131
|
-
if (i.nonInteractive && (r.error("<input> and <output> are required in non-interactive mode"), process.exit(1)), !t) {
|
|
132
|
-
const n = l.join(process.cwd(), "openapi"), o = I(n);
|
|
133
|
-
o.length === 0 && (r.warn("No directories found in openapi/"), r.info("Use --non-interactive mode with explicit paths: merge <input> <output>"), process.exit(1));
|
|
134
|
-
const a = await r.prompt("Select split spec directory to merge:", {
|
|
135
|
-
type: "select",
|
|
136
|
-
options: o
|
|
137
|
-
});
|
|
138
|
-
typeof a == "symbol" && process.exit(0), t = l.join(n, a), e = l.join(n, `${a}.yaml`);
|
|
139
|
-
}
|
|
140
|
-
if (e || (e = await r.prompt("Output path:", { type: "text" })), c.existsSync(e)) {
|
|
141
|
-
const n = await r.prompt(`File ${e} already exists. Overwrite?`, {
|
|
142
|
-
type: "confirm",
|
|
143
|
-
initial: !1
|
|
144
|
-
});
|
|
145
|
-
(typeof n == "symbol" || !n) && (r.info("Aborted"), process.exit(0));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
c.existsSync(t) || (r.error(`Directory not found: ${t}`), process.exit(1)), r.start("Merging OpenAPI spec…");
|
|
149
|
-
try {
|
|
150
|
-
b(t, e, i.fileName), r.success(`Merge complete! Output: ${e}`);
|
|
151
|
-
} catch (n) {
|
|
152
|
-
r.error("Merge failed", n), process.exit(1);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
function T(t, e) {
|
|
156
|
-
const i = t ? t.items.map((o) => m(o.key)) : [], n = [];
|
|
157
|
-
if (e)
|
|
158
|
-
for (const o of e.items) {
|
|
159
|
-
const a = m(o.key);
|
|
160
|
-
if (d(o.value))
|
|
161
|
-
for (const p of o.value.items)
|
|
162
|
-
n.push(`${a}/${m(p.key)}`);
|
|
163
|
-
}
|
|
164
|
-
return { version: 1, paths: i, components: n };
|
|
165
|
-
}
|
|
166
|
-
function N(t) {
|
|
167
|
-
return t.items.map((e) => {
|
|
168
|
-
const i = m(e.key);
|
|
169
|
-
return {
|
|
170
|
-
kind: "path",
|
|
171
|
-
urlPath: i,
|
|
172
|
-
relativePath: P(i),
|
|
173
|
-
pair: e
|
|
174
|
-
};
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
function E(t) {
|
|
178
|
-
const e = [];
|
|
179
|
-
for (const i of t.items) {
|
|
180
|
-
const n = m(i.key);
|
|
181
|
-
if (d(i.value))
|
|
182
|
-
for (const o of i.value.items)
|
|
183
|
-
e.push({
|
|
184
|
-
kind: "component",
|
|
185
|
-
section: n,
|
|
186
|
-
name: m(o.key),
|
|
187
|
-
pair: o
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
return e;
|
|
191
|
-
}
|
|
192
|
-
function L(t) {
|
|
193
|
-
const e = y.parseDocument(t), i = e.get("paths", !0), n = e.get("components", !0), o = [{ kind: "core", doc: e }];
|
|
194
|
-
d(i) && o.push(...N(i)), d(n) && o.push(...E(n));
|
|
195
|
-
const a = T(d(i) ? i : null, d(n) ? n : null);
|
|
196
|
-
return { files: o, manifest: { kind: "manifest", manifest: a } };
|
|
197
|
-
}
|
|
198
|
-
function Y(t) {
|
|
199
|
-
const e = t.clone();
|
|
200
|
-
return e.delete("paths"), e.delete("components"), e.toString();
|
|
201
|
-
}
|
|
202
|
-
function v(t) {
|
|
203
|
-
const e = new y.Document({});
|
|
204
|
-
return e.add(e.createPair(t.key, t.value)), e.toString();
|
|
205
|
-
}
|
|
206
|
-
function B(t, e) {
|
|
207
|
-
const i = c.readFileSync(t, "utf-8");
|
|
208
|
-
W(L(i), e);
|
|
209
|
-
}
|
|
210
|
-
function W({ files: t, manifest: e }, i) {
|
|
211
|
-
S(i);
|
|
212
|
-
for (const n of t)
|
|
213
|
-
switch (n.kind) {
|
|
214
|
-
case "core": {
|
|
215
|
-
c.writeFileSync(l.join(i, "openapi.yaml"), Y(n.doc));
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
case "path": {
|
|
219
|
-
const o = l.join(i, "paths", n.relativePath);
|
|
220
|
-
S(l.dirname(o)), c.writeFileSync(o, v(n.pair));
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
case "component": {
|
|
224
|
-
const o = l.join(i, "components", n.section, `${n.name}.yaml`);
|
|
225
|
-
S(l.dirname(o)), c.writeFileSync(o, v(n.pair));
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
c.writeFileSync(l.join(i, "manifest.json"), JSON.stringify(e.manifest, null, 2), "utf-8");
|
|
230
|
-
}
|
|
231
|
-
function U(t) {
|
|
232
|
-
return c.existsSync(t) ? c.readdirSync(t, { withFileTypes: !0 }).filter((e) => e.isFile() && e.name.endsWith(".yaml")).map((e) => e.name) : [];
|
|
233
|
-
}
|
|
234
|
-
const q = new u("split").description("Split an OpenAPI spec into separate files").argument("[input]", "path to the OpenAPI YAML file").argument("[output]", "output directory").option("--non-interactive", "disable interactive prompts").action(async (t, e, i) => {
|
|
235
|
-
if (!t || !e) {
|
|
236
|
-
if (i.nonInteractive && (r.error("<input> and <output> are required in non-interactive mode"), process.exit(1)), !t) {
|
|
237
|
-
const n = l.join(process.cwd(), "openapi"), o = U(n);
|
|
238
|
-
o.length === 0 && (r.warn("No .yaml files found in openapi/ directory"), r.info("Use --non-interactive mode with explicit paths: split <input> <output>"), process.exit(1));
|
|
239
|
-
const a = await r.prompt("Select OpenAPI spec to split:", {
|
|
240
|
-
type: "select",
|
|
241
|
-
options: o
|
|
242
|
-
});
|
|
243
|
-
typeof a == "symbol" && process.exit(0), t = l.join(n, a), e = l.join(n, l.basename(a, ".yaml"));
|
|
244
|
-
}
|
|
245
|
-
if (e || (e = await r.prompt("Output directory:", { type: "text" })), c.existsSync(e)) {
|
|
246
|
-
const n = await r.prompt(`Directory ${e} already exists. Overwrite?`, {
|
|
247
|
-
type: "confirm",
|
|
248
|
-
initial: !1
|
|
249
|
-
});
|
|
250
|
-
(typeof n == "symbol" || !n) && (r.info("Aborted"), process.exit(0));
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
c.existsSync(t) || (r.error(`File not found: ${t}`), process.exit(1)), r.start("Splitting OpenAPI spec…");
|
|
254
|
-
try {
|
|
255
|
-
B(t, e), r.success(`Split complete! Output: ${e}`);
|
|
256
|
-
} catch (n) {
|
|
257
|
-
r.error("Split failed", n), process.exit(1);
|
|
258
|
-
}
|
|
259
|
-
}), z = new u("openapi").description("OpenAPI spec tools").addCommand(q).addCommand(C).addCommand(F);
|
|
260
|
-
new u().name("ai-tools").description("Kode AI Tools CLI").version("0.0.0").addCommand(z).parse();
|