@luna-park/plugin 1.0.1 → 1.0.3
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 +139 -0
- package/dist/extractor.cjs +16 -0
- package/dist/extractor.d.ts +245 -0
- package/dist/extractor.js +577 -0
- package/dist/index-CxGB_fZK.js +394 -0
- package/dist/index-DmZsz62R.cjs +5 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +483 -19
- package/dist/index.js +18 -70
- package/package.json +21 -16
- package/dist/index.umd.cjs +0 -1
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
import M from "node:fs";
|
|
2
|
+
import { i as m, o as F, F as d, u as x, a as I, d as U } from "./index-CxGB_fZK.js";
|
|
3
|
+
import * as y from "typescript";
|
|
4
|
+
import p from "typescript";
|
|
5
|
+
import * as j from "path";
|
|
6
|
+
import * as J from "fs";
|
|
7
|
+
function S(t, e = {}) {
|
|
8
|
+
if (typeof t != "object" || t === null)
|
|
9
|
+
return JSON.stringify(t);
|
|
10
|
+
const o = {};
|
|
11
|
+
for (const n of ["default", "description", "name", "target", "promise", "optional", "example", "enum"])
|
|
12
|
+
t[n] && (o[n] = t[n]);
|
|
13
|
+
if (t.type === m.array)
|
|
14
|
+
return b(`LogicType.${t.type}`, [
|
|
15
|
+
S(t.items, e),
|
|
16
|
+
h(o)
|
|
17
|
+
]);
|
|
18
|
+
if (t.type === m.interface)
|
|
19
|
+
return b(`LogicType.${t.type}`, [
|
|
20
|
+
JSON.stringify(t.className),
|
|
21
|
+
h(o)
|
|
22
|
+
]);
|
|
23
|
+
if (t.type === m.union)
|
|
24
|
+
return b(`LogicType.${t.type}`, [
|
|
25
|
+
`[${t.elements.map((n) => S(n, e)).join(", ")}]`,
|
|
26
|
+
h(o)
|
|
27
|
+
]);
|
|
28
|
+
if (t.type === m.function)
|
|
29
|
+
return b(`LogicType.${t.type}`, [
|
|
30
|
+
S(t.inputs, e),
|
|
31
|
+
S(t.output, e),
|
|
32
|
+
h(o)
|
|
33
|
+
]);
|
|
34
|
+
if (t.type === m.object)
|
|
35
|
+
return b(`LogicType.${t.type}`, [
|
|
36
|
+
h(
|
|
37
|
+
F(
|
|
38
|
+
t.properties,
|
|
39
|
+
({ value: n }) => S(n, e)
|
|
40
|
+
),
|
|
41
|
+
!0
|
|
42
|
+
),
|
|
43
|
+
h(o)
|
|
44
|
+
]);
|
|
45
|
+
if (t.type === m.type) {
|
|
46
|
+
const n = t.target.at(-1), i = h(o);
|
|
47
|
+
return i !== "{}" ? n : `{ ...${n}, ${i.slice(1, -1)} }`;
|
|
48
|
+
}
|
|
49
|
+
return b(`LogicType.${t.type}`, [h(o)]);
|
|
50
|
+
}
|
|
51
|
+
function b(t, e) {
|
|
52
|
+
const o = e.findLastIndex((n) => n !== "{}");
|
|
53
|
+
return `${t}(${e.slice(0, o + 1).join(", ")})`;
|
|
54
|
+
}
|
|
55
|
+
function h(t, e) {
|
|
56
|
+
return `{${Object.entries(t).map(([o, n]) => `${_(o)}: ${e ? n : JSON.stringify(n)}`).join(", ")}}`;
|
|
57
|
+
}
|
|
58
|
+
function _(t) {
|
|
59
|
+
return /^[a-zA-Z]+$/.test(t) ? t : JSON.stringify(t);
|
|
60
|
+
}
|
|
61
|
+
function V(t, e) {
|
|
62
|
+
const o = [], n = t.components.default;
|
|
63
|
+
Object.keys(t.types);
|
|
64
|
+
for (const r of ["properties", "slots", "models", "emits"])
|
|
65
|
+
n[r] && Object.keys(n[r]).length && o.push({
|
|
66
|
+
key: r,
|
|
67
|
+
value: Object.entries(n[r]).map(([l, s]) => `${_(l)}: ${S(s, {})}`).join(`,
|
|
68
|
+
`)
|
|
69
|
+
});
|
|
70
|
+
const i = Object.entries(t.types).map(([r, l]) => `const ${r} = ${S(l, {})};`).join(`
|
|
71
|
+
|
|
72
|
+
`);
|
|
73
|
+
return `import { LogicType, type TComponent } from "@luna-park/plugin";
|
|
74
|
+
import ${e.name} from "${e.path}";
|
|
75
|
+
|
|
76
|
+
${i}
|
|
77
|
+
|
|
78
|
+
export const ${e.name.toLocaleLowerCase()}: TComponent = {
|
|
79
|
+
name: "${e.name}",
|
|
80
|
+
component: ${e.name},
|
|
81
|
+
${o.map(({ key: r, value: l }) => `${r}: {
|
|
82
|
+
${l}
|
|
83
|
+
}`).join(`,
|
|
84
|
+
`)}
|
|
85
|
+
}`;
|
|
86
|
+
}
|
|
87
|
+
function T(t, e) {
|
|
88
|
+
const o = {
|
|
89
|
+
description: C(t.getDocumentationComment(e)) || void 0
|
|
90
|
+
};
|
|
91
|
+
for (const n of t.getJsDocTags()) {
|
|
92
|
+
if (n.name === "param") {
|
|
93
|
+
o.params || (o.params = {});
|
|
94
|
+
let i = C(n.text?.slice(1)).trim();
|
|
95
|
+
i.startsWith("- ") && (i = i.slice(2));
|
|
96
|
+
const r = n.text[0]?.text;
|
|
97
|
+
o.params[r] = i;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
o[n.name] = C(n.text);
|
|
101
|
+
}
|
|
102
|
+
return d(o);
|
|
103
|
+
}
|
|
104
|
+
function C(t = []) {
|
|
105
|
+
return t.map((e) => e.text).join("");
|
|
106
|
+
}
|
|
107
|
+
function v(t, e) {
|
|
108
|
+
const o = e.checker.getPropertiesOfType(t), n = {};
|
|
109
|
+
return o.forEach((i) => {
|
|
110
|
+
const r = z(e.checker.getTypeOfSymbol(i)).type, s = e.checker.getSignaturesOfType(r, y.SignatureKind.Call)[0]?.parameters?.[0];
|
|
111
|
+
if (s) {
|
|
112
|
+
const c = e.checker.getTypeOfSymbol(s);
|
|
113
|
+
n[i.name] = {
|
|
114
|
+
type: e.typeToString(c)
|
|
115
|
+
}, e.extractType(c);
|
|
116
|
+
} else
|
|
117
|
+
n[i.name] = {
|
|
118
|
+
type: "{}"
|
|
119
|
+
};
|
|
120
|
+
}), n;
|
|
121
|
+
}
|
|
122
|
+
function L(t, e) {
|
|
123
|
+
const o = e.checker.getPropertiesOfType(t), n = {}, i = {};
|
|
124
|
+
return o.forEach((r) => {
|
|
125
|
+
if (["onVnode", "ref_"].some((s) => r.name.startsWith(s)) || ["ref", "class", "style", "key"].includes(r.name))
|
|
126
|
+
return;
|
|
127
|
+
const l = e.checker.getTypeOfSymbol(r);
|
|
128
|
+
if (e.extractType(l), W(r.name)) {
|
|
129
|
+
i[H(r.name)] = A(l, r, e);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
n[r.name] = A(l, r, e);
|
|
133
|
+
}), { emits: i, props: n };
|
|
134
|
+
}
|
|
135
|
+
function E(t) {
|
|
136
|
+
return t.models = Object.keys(t.properties ?? {}).reduce((e, o) => (t.emits?.[`update:${o}`] && (e[o] = t.properties[o], delete t.properties[o], delete t.emits[`update:${o}`]), e), {}), t;
|
|
137
|
+
}
|
|
138
|
+
function z(t) {
|
|
139
|
+
if (t.isUnion()) {
|
|
140
|
+
const e = t.types.filter((o) => o.flags !== y.TypeFlags.Undefined);
|
|
141
|
+
if (e.length === 1)
|
|
142
|
+
return { optional: !0, type: e[0] };
|
|
143
|
+
}
|
|
144
|
+
return { type: t };
|
|
145
|
+
}
|
|
146
|
+
function A(t, e, o) {
|
|
147
|
+
const n = z(t);
|
|
148
|
+
return d({
|
|
149
|
+
description: T(e, o.checker).description,
|
|
150
|
+
optional: n.optional,
|
|
151
|
+
type: o.typeToString(n.type)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function W(t) {
|
|
155
|
+
return /^on[A-Z]/.test(t);
|
|
156
|
+
}
|
|
157
|
+
function H(t) {
|
|
158
|
+
return t = t.slice(2), t.charAt(0).toLowerCase() + t.slice(1);
|
|
159
|
+
}
|
|
160
|
+
function K(t, e) {
|
|
161
|
+
return Object.fromEntries((t.getTypeParameters() ?? []).map((o) => {
|
|
162
|
+
let n = "unknown";
|
|
163
|
+
const i = o.getDefault();
|
|
164
|
+
i && (n = e.typeToString(i));
|
|
165
|
+
const r = o.getConstraint();
|
|
166
|
+
return r && (n = e.typeToString(r)), [o.symbol.name, n];
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
function Q(t, e) {
|
|
170
|
+
const o = /* @__PURE__ */ new Map(), n = t.getExportsOfModule(e);
|
|
171
|
+
for (const i of n) {
|
|
172
|
+
let r = i;
|
|
173
|
+
for (; r.flags & y.SymbolFlags.Alias; )
|
|
174
|
+
r = t.getAliasedSymbol(r);
|
|
175
|
+
o.set(i.name, r);
|
|
176
|
+
}
|
|
177
|
+
return o;
|
|
178
|
+
}
|
|
179
|
+
function $(t, e) {
|
|
180
|
+
let o = t.getFullyQualifiedName(e);
|
|
181
|
+
return o.includes('".') && (o = o.split('".').pop()), o.includes(").") && (o = o.split(").").pop()), o;
|
|
182
|
+
}
|
|
183
|
+
function O(t, e) {
|
|
184
|
+
for (const [o, n] of Object.entries(e))
|
|
185
|
+
t = t.replace(new RegExp(`\\b${o}\\b`, "g"), n);
|
|
186
|
+
return t;
|
|
187
|
+
}
|
|
188
|
+
function R(t) {
|
|
189
|
+
const e = [];
|
|
190
|
+
return t.members.forEach((n) => {
|
|
191
|
+
const i = n.name.getText();
|
|
192
|
+
if (n.initializer) {
|
|
193
|
+
let r;
|
|
194
|
+
y.isStringLiteral(n.initializer) ? r = `"${n.initializer.text}"` : y.isNumericLiteral(n.initializer) ? r = n.initializer.text : r = n.initializer.getText(), e.push(`${i} = ${r}`);
|
|
195
|
+
} else
|
|
196
|
+
e.push(i);
|
|
197
|
+
}), `{ ${e.join(", ")} }`;
|
|
198
|
+
}
|
|
199
|
+
function w(t) {
|
|
200
|
+
if (t.getFlags() & (p.TypeFlags.StringLike | p.TypeFlags.NumberLike | p.TypeFlags.BooleanLike | p.TypeFlags.ESSymbolLike | p.TypeFlags.Void | p.TypeFlags.Undefined | p.TypeFlags.Null | p.TypeFlags.Any | p.TypeFlags.Unknown | p.TypeFlags.Never))
|
|
201
|
+
return !1;
|
|
202
|
+
const o = t.getSymbol();
|
|
203
|
+
if (!o)
|
|
204
|
+
return !0;
|
|
205
|
+
const n = o.declarations?.[0];
|
|
206
|
+
if (!n)
|
|
207
|
+
return !0;
|
|
208
|
+
const i = n.getSourceFile();
|
|
209
|
+
return !(/lib\..*\.d\.ts$/.test(i.fileName) || i.fileName.startsWith("/@vue/"));
|
|
210
|
+
}
|
|
211
|
+
const D = p.TypeFormatFlags.WriteArrowStyleSignature | p.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | p.TypeFormatFlags.NoTruncation | p.TypeFormatFlags.UseFullyQualifiedType;
|
|
212
|
+
class q {
|
|
213
|
+
constructor(e) {
|
|
214
|
+
this.program = e, this.checker = e.getTypeChecker();
|
|
215
|
+
}
|
|
216
|
+
checker;
|
|
217
|
+
index;
|
|
218
|
+
cache = /* @__PURE__ */ new Set();
|
|
219
|
+
result;
|
|
220
|
+
get(e) {
|
|
221
|
+
if (this.index = this.program.getSourceFile(e), !this.index)
|
|
222
|
+
throw new Error(`Cannot find file ${e}`);
|
|
223
|
+
const o = this.checker.getSymbolAtLocation(this.index);
|
|
224
|
+
if (!o)
|
|
225
|
+
throw new Error(`Cannot find module ${e}`);
|
|
226
|
+
this.result = {
|
|
227
|
+
components: {},
|
|
228
|
+
functions: {},
|
|
229
|
+
types: {}
|
|
230
|
+
};
|
|
231
|
+
const n = this.index.statements.find((i) => p.isExportAssignment(i));
|
|
232
|
+
if (n) {
|
|
233
|
+
const r = this.checker.getTypeAtLocation(n.expression).getCallSignatures()[0];
|
|
234
|
+
r && this.exportFunction("default", r);
|
|
235
|
+
}
|
|
236
|
+
return this.exportModule(o), this.result;
|
|
237
|
+
}
|
|
238
|
+
exportModule(e) {
|
|
239
|
+
const o = Q(this.checker, e);
|
|
240
|
+
for (const [n, i] of o.entries()) {
|
|
241
|
+
let r = this.checker.getTypeOfSymbol(i);
|
|
242
|
+
if (r.symbol && r.symbol.flags & p.SymbolFlags.Module) {
|
|
243
|
+
const s = r.symbol.exports?.get("default");
|
|
244
|
+
s && (r = this.checker.getTypeOfSymbol(s));
|
|
245
|
+
}
|
|
246
|
+
const l = r.symbol || r.aliasSymbol;
|
|
247
|
+
if (l?.flags & p.SymbolFlags.Function) {
|
|
248
|
+
const s = this.checker.getTypeOfSymbol(l), c = this.checker.getSignaturesOfType(s, p.SignatureKind.Call)[0];
|
|
249
|
+
if (c) {
|
|
250
|
+
const a = $(this.checker, l);
|
|
251
|
+
this.exportFunction(a, c);
|
|
252
|
+
}
|
|
253
|
+
} else if (this.typeToString(r).includes("DefineComponent<"))
|
|
254
|
+
try {
|
|
255
|
+
this.exportComponent(n, r);
|
|
256
|
+
} catch (c) {
|
|
257
|
+
console.error(`Fail to export component ${n}`), console.error(c);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exportComponent(e, o) {
|
|
262
|
+
const n = o.getConstructSignatures()[0];
|
|
263
|
+
if (!n)
|
|
264
|
+
return;
|
|
265
|
+
const i = this.checker.getReturnTypeOfSignature(n), r = {}, l = this.checker.getPropertyOfType(i, "$props");
|
|
266
|
+
if (l) {
|
|
267
|
+
const c = this.checker.getTypeOfSymbol(l), a = L(c, this);
|
|
268
|
+
r.properties = a.props, r.emits = a.emits;
|
|
269
|
+
}
|
|
270
|
+
const s = this.checker.getPropertyOfType(i, "$slots");
|
|
271
|
+
if (s) {
|
|
272
|
+
const c = this.checker.getTypeOfSymbol(s);
|
|
273
|
+
r.slots = v(c, this);
|
|
274
|
+
}
|
|
275
|
+
this.result.components[e] = E(r);
|
|
276
|
+
}
|
|
277
|
+
exportFunction(e, o) {
|
|
278
|
+
const n = T(o, this.checker), i = K(o, this), r = o.getParameters().map((s) => {
|
|
279
|
+
const c = s.valueDeclaration ?? this.index, a = this.checker.getTypeOfSymbol(s);
|
|
280
|
+
this.extractType(a, c);
|
|
281
|
+
const f = s.valueDeclaration?.initializer?.getText();
|
|
282
|
+
return d({
|
|
283
|
+
default: f,
|
|
284
|
+
description: n.params?.[s.name],
|
|
285
|
+
name: s.name,
|
|
286
|
+
optional: !!c.questionToken || f !== void 0 || void 0,
|
|
287
|
+
type: O(this.typeToString(a), i)
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
if (r.some((s) => s.name?.startsWith("__VLS_"))) {
|
|
291
|
+
const s = {}, c = r.findIndex((u) => u.name === "__VLS_props"), a = o.getParameters()[c];
|
|
292
|
+
if (a) {
|
|
293
|
+
const u = this.checker.getTypeOfSymbol(a), k = L(u, this);
|
|
294
|
+
s.properties = k.props, s.emits = k.emits, Object.values(s.properties).forEach((N) => {
|
|
295
|
+
N.type = O(N.type, i);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
const f = r.findIndex((u) => u.name === "__VLS_slots"), g = o.getParameters()[f];
|
|
299
|
+
if (g) {
|
|
300
|
+
const u = this.checker.getTypeOfSymbol(g);
|
|
301
|
+
s.slots = v(u, this), Object.values(s.slots).forEach((k) => {
|
|
302
|
+
k.type = O(k.type, i);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
this.result.components[e] = E(s);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const l = this.checker.getReturnTypeOfSignature(o);
|
|
309
|
+
this.extractType(l), this.result.functions[e] = d({
|
|
310
|
+
description: n.description,
|
|
311
|
+
parameters: r,
|
|
312
|
+
return: {
|
|
313
|
+
description: n.returns,
|
|
314
|
+
type: O(this.typeToString(l), i)
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
extractType(e, o = this.index) {
|
|
319
|
+
if (this.cache.has(e))
|
|
320
|
+
return;
|
|
321
|
+
this.cache.add(e);
|
|
322
|
+
const n = e.symbol || e.aliasSymbol;
|
|
323
|
+
if ((e.isUnion() || e.isIntersection()) && !(n?.flags & p.SymbolFlags.Enum) && e.types.forEach((i) => {
|
|
324
|
+
this.extractType(i, o);
|
|
325
|
+
}), n) {
|
|
326
|
+
if (this.checker.getFullyQualifiedName(n).includes("/@vue/"))
|
|
327
|
+
return;
|
|
328
|
+
const i = $(this.checker, n);
|
|
329
|
+
if (n.flags & p.SymbolFlags.Enum) {
|
|
330
|
+
const r = n.valueDeclaration || n.declarations?.[0];
|
|
331
|
+
if (r && p.isEnumDeclaration(r)) {
|
|
332
|
+
const l = $(this.checker, n);
|
|
333
|
+
this.result.types[l] = d({
|
|
334
|
+
...T(n, this.checker),
|
|
335
|
+
type: R(r)
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (n.flags & p.SymbolFlags.Namespace) {
|
|
341
|
+
const r = n;
|
|
342
|
+
this.exportModule(r);
|
|
343
|
+
}
|
|
344
|
+
if (n.flags & p.SymbolFlags.TypeAlias) {
|
|
345
|
+
const r = n.valueDeclaration || n.declarations?.[0];
|
|
346
|
+
if (!r)
|
|
347
|
+
return;
|
|
348
|
+
const l = Object.fromEntries((r?.typeParameters ?? []).map((s) => {
|
|
349
|
+
let c = "unknown";
|
|
350
|
+
const a = s.default;
|
|
351
|
+
if (a) {
|
|
352
|
+
const g = this.checker.getTypeFromTypeNode(a);
|
|
353
|
+
c = this.typeToString(g);
|
|
354
|
+
}
|
|
355
|
+
const f = s.constraint;
|
|
356
|
+
if (f) {
|
|
357
|
+
const g = this.checker.getTypeFromTypeNode(f);
|
|
358
|
+
c = this.typeToString(g);
|
|
359
|
+
}
|
|
360
|
+
return [s.symbol.name, c];
|
|
361
|
+
}));
|
|
362
|
+
this.result.types[i] = {
|
|
363
|
+
...T(n, this.checker),
|
|
364
|
+
type: O(this.typeToString(e, D | p.TypeFormatFlags.InTypeAlias), l)
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
if (n.flags & p.SymbolFlags.Interface && w(e)) {
|
|
368
|
+
const r = n.getDeclarations()[0];
|
|
369
|
+
if (r) {
|
|
370
|
+
const l = this.checker.getPropertiesOfType(e), s = {};
|
|
371
|
+
l.forEach((c) => {
|
|
372
|
+
const a = this.checker.getTypeOfSymbol(c);
|
|
373
|
+
this.extractType(a, r), s[c.name] = {
|
|
374
|
+
...T(c, this.checker),
|
|
375
|
+
optional: !!(c.flags & p.SymbolFlags.Optional) || void 0,
|
|
376
|
+
type: this.typeToString(a)
|
|
377
|
+
};
|
|
378
|
+
}), this.result.types[i] = {
|
|
379
|
+
...T(n, this.checker),
|
|
380
|
+
type: s
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (n.flags & p.SymbolFlags.TypeLiteral) {
|
|
385
|
+
const r = $(this.checker, e.aliasSymbol || e.symbol), l = this.checker.getPropertiesOfType(e), s = {};
|
|
386
|
+
if (["Promise", "Partial", "Pick", "Omit", "Required"].includes(r)) {
|
|
387
|
+
this.cache.delete(e), this.extractType(e.aliasTypeArguments[0]);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (e.aliasTypeArguments?.some((c) => !w(c)))
|
|
391
|
+
return;
|
|
392
|
+
l.forEach((c) => {
|
|
393
|
+
const a = this.checker.getTypeOfSymbol(c);
|
|
394
|
+
s[c.name] = {
|
|
395
|
+
...T(c, this.checker),
|
|
396
|
+
optional: !!(c.flags & p.SymbolFlags.Optional),
|
|
397
|
+
type: this.typeToString(a)
|
|
398
|
+
};
|
|
399
|
+
}), r !== "__type" && (this.result.types[r] = {
|
|
400
|
+
...T(n, this.checker),
|
|
401
|
+
type: s
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (e.flags & p.TypeFlags.Object) {
|
|
406
|
+
const i = e;
|
|
407
|
+
if (w(e) && this.checker.getPropertiesOfType(e).forEach((l) => {
|
|
408
|
+
const s = this.checker.getTypeOfSymbol(l);
|
|
409
|
+
this.extractType(s, o);
|
|
410
|
+
}), i.objectFlags & p.ObjectFlags.Reference) {
|
|
411
|
+
const r = i;
|
|
412
|
+
this.checker.getTypeArguments(r).forEach((s) => {
|
|
413
|
+
this.extractType(s, o);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
typeToString(e, o = D) {
|
|
419
|
+
return this.checker.typeToString(e, void 0, o);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function Z(t, e = "unknown") {
|
|
423
|
+
const o = {
|
|
424
|
+
components: {},
|
|
425
|
+
functions: {},
|
|
426
|
+
types: {}
|
|
427
|
+
};
|
|
428
|
+
for (const [s, c] of Object.entries(t.types))
|
|
429
|
+
o.types[s] = n(c, s);
|
|
430
|
+
for (const [s, c] of Object.entries(t.functions))
|
|
431
|
+
o.functions[s] = i(c, s);
|
|
432
|
+
for (const [s, c] of Object.entries(t.components))
|
|
433
|
+
o.components[s] = r(c, s);
|
|
434
|
+
return o;
|
|
435
|
+
function n(s, c = "") {
|
|
436
|
+
if (typeof s.type == "string") {
|
|
437
|
+
if (s.type === "{}")
|
|
438
|
+
return x.void();
|
|
439
|
+
const a = {
|
|
440
|
+
...l(I(s.type)),
|
|
441
|
+
...d({
|
|
442
|
+
description: s.description,
|
|
443
|
+
name: c?.split(".").pop() || void 0,
|
|
444
|
+
optional: s.optional
|
|
445
|
+
})
|
|
446
|
+
};
|
|
447
|
+
if (s.default)
|
|
448
|
+
switch (a.type) {
|
|
449
|
+
case m.boolean:
|
|
450
|
+
a.default = s.default === "true";
|
|
451
|
+
break;
|
|
452
|
+
case m.number:
|
|
453
|
+
a.default = Number(s.default);
|
|
454
|
+
break;
|
|
455
|
+
case m.string:
|
|
456
|
+
a.default = s.default;
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
return a.type === m.object && !Object.keys(a.properties).length && (a.customizable = !0), a;
|
|
460
|
+
} else {
|
|
461
|
+
const a = x.object(
|
|
462
|
+
F(
|
|
463
|
+
s.type,
|
|
464
|
+
({ key: f, value: g }) => n(g, f)
|
|
465
|
+
),
|
|
466
|
+
d({
|
|
467
|
+
description: s.description,
|
|
468
|
+
name: c?.split(".").pop(),
|
|
469
|
+
optional: s.optional
|
|
470
|
+
})
|
|
471
|
+
);
|
|
472
|
+
return Object.keys(a.properties).length || (a.customizable = !0), a;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function i(s, c = "") {
|
|
476
|
+
return {
|
|
477
|
+
...d({
|
|
478
|
+
description: s.description,
|
|
479
|
+
name: c?.split(".").pop()
|
|
480
|
+
}),
|
|
481
|
+
parameters: (s.parameters ?? []).map((a) => n(a, a.name)),
|
|
482
|
+
return: n(s.return, "result")
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function r(s, c = "") {
|
|
486
|
+
return {
|
|
487
|
+
...d({
|
|
488
|
+
name: c?.split(".").pop()
|
|
489
|
+
}),
|
|
490
|
+
emits: F(s.emits, ({ value: a }) => n(a)),
|
|
491
|
+
models: F(s.models, ({ value: a }) => n(a)),
|
|
492
|
+
properties: F(s.properties, ({ key: a, value: f }) => n(f, a)),
|
|
493
|
+
slots: F(s.slots, ({ value: a }) => n(a))
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function l(s, c = "") {
|
|
497
|
+
return U(s, (f) => {
|
|
498
|
+
if (f.type === m.interface)
|
|
499
|
+
return {
|
|
500
|
+
...a(f.className, c),
|
|
501
|
+
description: f.description,
|
|
502
|
+
name: f.name,
|
|
503
|
+
optional: f.optional
|
|
504
|
+
};
|
|
505
|
+
});
|
|
506
|
+
function a(f, g = "") {
|
|
507
|
+
let u = `${g}${f}`;
|
|
508
|
+
for (; !t.types[u] && u.indexOf(".") !== -1; )
|
|
509
|
+
u = u.substring(u.indexOf(".") + 1);
|
|
510
|
+
return t.types[u] ? x.type([
|
|
511
|
+
"packages",
|
|
512
|
+
e,
|
|
513
|
+
...u.split(".")
|
|
514
|
+
]) : x.interface(f);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function B(t) {
|
|
519
|
+
for (; ; ) {
|
|
520
|
+
const e = j.join(t, "tsconfig.json");
|
|
521
|
+
if (J.existsSync(e))
|
|
522
|
+
return e;
|
|
523
|
+
const o = j.dirname(t);
|
|
524
|
+
if (o === t)
|
|
525
|
+
return;
|
|
526
|
+
t = o;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
function G(t) {
|
|
530
|
+
const e = y.readConfigFile(t, y.sys.readFile);
|
|
531
|
+
if (e.error)
|
|
532
|
+
throw new Error(`Failed to read tsconfig.json: ${e.error.messageText}`);
|
|
533
|
+
return y.parseJsonConfigFileContent(e.config, y.sys, j.dirname(t));
|
|
534
|
+
}
|
|
535
|
+
function X(t, e) {
|
|
536
|
+
const o = j.join(process.cwd(), "__temp__.ts"), n = y.createCompilerHost(e), i = y.resolveModuleName(
|
|
537
|
+
t,
|
|
538
|
+
o,
|
|
539
|
+
e,
|
|
540
|
+
n
|
|
541
|
+
);
|
|
542
|
+
if (i.resolvedModule)
|
|
543
|
+
return i.resolvedModule.resolvedFileName;
|
|
544
|
+
}
|
|
545
|
+
function Y(t) {
|
|
546
|
+
const e = B(t);
|
|
547
|
+
if (!e)
|
|
548
|
+
throw new Error(`Could not find tsconfig.json for: ${t}`);
|
|
549
|
+
const n = G(e).options, i = X(t, n);
|
|
550
|
+
if (!i)
|
|
551
|
+
throw new Error(`Could not resolve module: ${t}`);
|
|
552
|
+
const r = y.createCompilerHost(n), l = y.createProgram({
|
|
553
|
+
host: r,
|
|
554
|
+
options: n,
|
|
555
|
+
rootNames: [i]
|
|
556
|
+
}), s = l.getSourceFile(i);
|
|
557
|
+
if (!s)
|
|
558
|
+
throw new Error(`Could not get source file for: ${i}`);
|
|
559
|
+
return {
|
|
560
|
+
program: l,
|
|
561
|
+
sourceFile: s
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
const P = M.promises;
|
|
565
|
+
async function oe(t, e) {
|
|
566
|
+
const o = t.split("/").pop().split(".")[0], { program: n, sourceFile: i } = Y(t), l = new q(n).get(i.fileName), s = Z(l, o);
|
|
567
|
+
if (s.components.default) {
|
|
568
|
+
const c = V(s, { name: o, path: t });
|
|
569
|
+
await P.mkdir(e.split("/").slice(0, -1).join("/"), { recursive: !0 }), await P.writeFile(e, c);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
export {
|
|
573
|
+
q as CTypeExport,
|
|
574
|
+
oe as extractFile,
|
|
575
|
+
Z as generateNodes,
|
|
576
|
+
Y as getSourceFile
|
|
577
|
+
};
|