@luna-park/plugin 1.1.0 → 1.2.1
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 +6 -6
- package/bin/preview.js +1 -1
- package/dist/chunk-rCEYsGS8.cjs +1 -0
- package/dist/dist-BUZt4gnZ.js +421 -0
- package/dist/dist-BkSFkjuo.cjs +5 -0
- package/dist/extractor.cjs +9 -11
- package/dist/extractor.d.ts +17 -17
- package/dist/extractor.js +483 -548
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +760 -262
- package/dist/index.js +2961 -23
- package/dist/plugin.css +2 -0
- package/dist/preview.cjs +1 -1
- package/dist/preview.js +27 -37
- package/package.json +19 -17
- package/dist/index-4fa4mAH8.cjs +0 -5
- package/dist/index-QMG2c0JW.js +0 -394
package/README.md
CHANGED
|
@@ -123,12 +123,12 @@ The main interface for defining a plugin.
|
|
|
123
123
|
|
|
124
124
|
The environment object passed to lifecycle hooks and dynamic options.
|
|
125
125
|
|
|
126
|
-
| Property
|
|
127
|
-
|
|
128
|
-
| `app`
|
|
129
|
-
| `config`
|
|
130
|
-
| `mode`
|
|
131
|
-
| `
|
|
126
|
+
| Property | Type | Description |
|
|
127
|
+
|:------------|:----------------------| :--- |
|
|
128
|
+
| `app` | `TApplication` | Access to the core application instance. |
|
|
129
|
+
| `config` | `Static<TConfig>` | The resolved configuration values based on the schema. |
|
|
130
|
+
| `mode` | `"build" \| "editor"` | The current running mode. |
|
|
131
|
+
| `internals` | `TInternals` | Internal state (if defined). |
|
|
132
132
|
|
|
133
133
|
### `TOption<TEnv, T>`
|
|
134
134
|
|
package/bin/preview.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n&&t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return o}});
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
function cloneDeep(e) {
|
|
2
|
+
if (typeof e != "object") return e;
|
|
3
|
+
let S = [
|
|
4
|
+
() => JSON.parse(JSON.stringify(e)),
|
|
5
|
+
() => structuredClone(e),
|
|
6
|
+
() => safeClone(e)
|
|
7
|
+
], C;
|
|
8
|
+
for (let e of S) try {
|
|
9
|
+
return e();
|
|
10
|
+
} catch (e) {
|
|
11
|
+
C = e;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
throw console.error("Failed to deep clone object:", e), Error(C);
|
|
15
|
+
}
|
|
16
|
+
function safeClone(e) {
|
|
17
|
+
let x = /* @__PURE__ */ new WeakSet();
|
|
18
|
+
return S(e);
|
|
19
|
+
function S(e) {
|
|
20
|
+
if (typeof e != "object") return e;
|
|
21
|
+
if (x.has(e)) return { recursive: !0 };
|
|
22
|
+
if (x.add(e), Array.isArray(e)) return e.map((e) => S(e));
|
|
23
|
+
let C = Object.getOwnPropertyDescriptors(e), w = {};
|
|
24
|
+
for (let [e, x] of Object.entries(C)) w[e] = S(x.value);
|
|
25
|
+
return w;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function cloneWithFunctions(e) {
|
|
29
|
+
if (Array.isArray(e)) return e.map(cloneWithFunctions);
|
|
30
|
+
if (typeof e != "object") return e;
|
|
31
|
+
let x = {};
|
|
32
|
+
for (let [C, w] of Object.entries(e)) {
|
|
33
|
+
if (typeof w == "function") {
|
|
34
|
+
x[C] = w;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
x[C] = cloneWithFunctions(w);
|
|
38
|
+
}
|
|
39
|
+
return x;
|
|
40
|
+
}
|
|
41
|
+
function objectMap(e, x) {
|
|
42
|
+
return e ? Object.fromEntries(Object.entries(e).map(([e, S]) => [e, x({
|
|
43
|
+
key: e,
|
|
44
|
+
value: S
|
|
45
|
+
})])) : {};
|
|
46
|
+
}
|
|
47
|
+
function objectFilter(e, x) {
|
|
48
|
+
return e ? Object.fromEntries(Object.entries(e).filter(([e, S]) => x({
|
|
49
|
+
key: e,
|
|
50
|
+
value: S
|
|
51
|
+
}))) : {};
|
|
52
|
+
}
|
|
53
|
+
function cleanObject(x) {
|
|
54
|
+
for (let C in x = cloneDeep(x), x) S(x, C);
|
|
55
|
+
function S(e, x) {
|
|
56
|
+
if (typeof e[x] == "object") {
|
|
57
|
+
for (let C in e[x]) S(e[x], C);
|
|
58
|
+
Object.keys(e[x]).length === 0 && delete e[x];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return x;
|
|
62
|
+
}
|
|
63
|
+
var EVarType = /* @__PURE__ */ function(e) {
|
|
64
|
+
return e.exec = "exec", e.number = "number", e.string = "string", e.boolean = "boolean", e.object = "object", e.record = "record", e.array = "array", e.interface = "interface", e.type = "type", e.function = "function", e.union = "union", e.unknown = "unknown", e.undefined = "undefined", e.void = "void", e;
|
|
65
|
+
}({}), LogicType = {
|
|
66
|
+
array: (e, x = {}) => ({
|
|
67
|
+
...x,
|
|
68
|
+
items: e,
|
|
69
|
+
type: EVarType.array
|
|
70
|
+
}),
|
|
71
|
+
boolean: (e = {}) => ({
|
|
72
|
+
...e,
|
|
73
|
+
type: EVarType.boolean
|
|
74
|
+
}),
|
|
75
|
+
exec: (e = {}) => ({
|
|
76
|
+
...e,
|
|
77
|
+
type: EVarType.exec
|
|
78
|
+
}),
|
|
79
|
+
function: (e = {
|
|
80
|
+
properties: {},
|
|
81
|
+
type: EVarType.object
|
|
82
|
+
}, x = { type: EVarType.void }, S = {}) => ({
|
|
83
|
+
...S,
|
|
84
|
+
inputs: e,
|
|
85
|
+
output: x,
|
|
86
|
+
type: EVarType.function
|
|
87
|
+
}),
|
|
88
|
+
interface: (e, x = {}) => ({
|
|
89
|
+
...x,
|
|
90
|
+
className: typeof e == "string" ? e : e.name,
|
|
91
|
+
type: EVarType.interface
|
|
92
|
+
}),
|
|
93
|
+
number: (e = {}) => ({
|
|
94
|
+
...e,
|
|
95
|
+
type: EVarType.number
|
|
96
|
+
}),
|
|
97
|
+
object: (e = {}, x = {}) => ({
|
|
98
|
+
...x,
|
|
99
|
+
properties: e,
|
|
100
|
+
type: EVarType.object
|
|
101
|
+
}),
|
|
102
|
+
record: (e, x, S = {}) => ({
|
|
103
|
+
...S,
|
|
104
|
+
key: e,
|
|
105
|
+
type: EVarType.record,
|
|
106
|
+
value: x
|
|
107
|
+
}),
|
|
108
|
+
string: (e = {}) => ({
|
|
109
|
+
...e,
|
|
110
|
+
type: EVarType.string
|
|
111
|
+
}),
|
|
112
|
+
type: (e, x = {}) => ({
|
|
113
|
+
...x,
|
|
114
|
+
target: e,
|
|
115
|
+
type: EVarType.type
|
|
116
|
+
}),
|
|
117
|
+
undefined: (e = {}) => ({
|
|
118
|
+
...e,
|
|
119
|
+
type: EVarType.undefined
|
|
120
|
+
}),
|
|
121
|
+
union: (e, x = {}) => ({
|
|
122
|
+
...x,
|
|
123
|
+
elements: e,
|
|
124
|
+
type: EVarType.union
|
|
125
|
+
}),
|
|
126
|
+
unknown: (e = {}) => ({
|
|
127
|
+
...e,
|
|
128
|
+
type: EVarType.unknown
|
|
129
|
+
}),
|
|
130
|
+
void: (e = {}) => ({
|
|
131
|
+
...e,
|
|
132
|
+
type: EVarType.void
|
|
133
|
+
})
|
|
134
|
+
}, LogicUtil = {
|
|
135
|
+
omit(e, x) {
|
|
136
|
+
return {
|
|
137
|
+
...e,
|
|
138
|
+
properties: objectFilter(e.properties, ({ key: e }) => !x.includes(e))
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
partial(e, x = !1) {
|
|
142
|
+
return {
|
|
143
|
+
...e,
|
|
144
|
+
properties: objectMap(e.properties, ({ value: e }) => ({
|
|
145
|
+
...e,
|
|
146
|
+
optional: !x || !e.required
|
|
147
|
+
}))
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
pick(e, x) {
|
|
151
|
+
return {
|
|
152
|
+
...e,
|
|
153
|
+
properties: objectFilter(e.properties, ({ key: e }) => x.includes(e))
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
promise(e) {
|
|
157
|
+
return {
|
|
158
|
+
...e,
|
|
159
|
+
promise: !0
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
required(e) {
|
|
163
|
+
return {
|
|
164
|
+
...e,
|
|
165
|
+
properties: objectMap(e.properties, ({ value: e }) => ({
|
|
166
|
+
...e,
|
|
167
|
+
optional: !1
|
|
168
|
+
}))
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}, ELogicType = /* @__PURE__ */ function(e) {
|
|
172
|
+
return e.function = "function", e.macro = "macro", e.operation = "operation", e;
|
|
173
|
+
}({}), ELogicScope = /* @__PURE__ */ function(e) {
|
|
174
|
+
return e.Frontend = "frontend", e.Backend = "backend", e.Desktop = "desktop", e.Shared = "shared", e;
|
|
175
|
+
}({});
|
|
176
|
+
function makeLogicNode(e) {
|
|
177
|
+
return e;
|
|
178
|
+
}
|
|
179
|
+
function scanner(e) {
|
|
180
|
+
let x = [];
|
|
181
|
+
for (e = e.replaceAll(/ +/g, " "), e = e.replaceAll(/\s*\n\s*/g, "\n"); e.length;) {
|
|
182
|
+
if ([" ", "\n"].includes(e[0])) {
|
|
183
|
+
e = e.slice(1);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (e.startsWith("/*")) {
|
|
187
|
+
let S = e.indexOf("*/");
|
|
188
|
+
x.push(e.slice(0, S + 2)), e = e.slice(S + 2);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
let S = e.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];
|
|
192
|
+
if (S) {
|
|
193
|
+
e = e.slice(S.length), x.push(S);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
let C = e.match(/^([0-9]+)/)?.[0];
|
|
197
|
+
if (C) {
|
|
198
|
+
e = e.slice(C.length), x.push(C);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (e[0] === ">" && x.at(-1) === "=") {
|
|
202
|
+
x.pop(), x.push("=>"), e = e.slice(1);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
x.push(e[0]), e = e.slice(1);
|
|
206
|
+
}
|
|
207
|
+
return x;
|
|
208
|
+
}
|
|
209
|
+
var wrappers = [
|
|
210
|
+
["(", ")"],
|
|
211
|
+
["[", "]"],
|
|
212
|
+
["{", "}"],
|
|
213
|
+
["<", ">"],
|
|
214
|
+
["'", "'"],
|
|
215
|
+
["\"", "\""]
|
|
216
|
+
];
|
|
217
|
+
function lexer(e) {
|
|
218
|
+
return cleanArray(splitUntil(e, ";"));
|
|
219
|
+
}
|
|
220
|
+
function getUntil(e, x, S = 1) {
|
|
221
|
+
let C = [];
|
|
222
|
+
for (wrappers.find((e) => e[1] === x)?.[0]; e.length && (e[0], !(e[0] === x && (S--, S <= 0)));) {
|
|
223
|
+
let w = getFirstElement(e);
|
|
224
|
+
if (C.push(w), S === 0 && typeof w == "object" && w.type === "wrap" && w.style.endsWith(x)) break;
|
|
225
|
+
}
|
|
226
|
+
return e.shift(), C;
|
|
227
|
+
}
|
|
228
|
+
function eraseUntil(e, x) {
|
|
229
|
+
for (; e.length;) {
|
|
230
|
+
if (e[0] === x) {
|
|
231
|
+
e.shift();
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
e.shift();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function splitUntil(e, x) {
|
|
238
|
+
let S = [[]];
|
|
239
|
+
for (; e.length;) {
|
|
240
|
+
if (e[0] === x) {
|
|
241
|
+
S.push([]), e.shift();
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
S.at(-1).push(getFirstElement(e));
|
|
245
|
+
}
|
|
246
|
+
return S.filter((e) => e.length);
|
|
247
|
+
}
|
|
248
|
+
function getFirstElement(e) {
|
|
249
|
+
let x = e.shift(), S = !1;
|
|
250
|
+
if (x === "export") {
|
|
251
|
+
if (S = !0, x = e.shift(), x === "=") return {
|
|
252
|
+
type: "export",
|
|
253
|
+
content: e.shift()
|
|
254
|
+
};
|
|
255
|
+
if (x === "as") return eraseUntil(e, ";"), getFirstElement(e);
|
|
256
|
+
}
|
|
257
|
+
if (x === "declare" && (x = e.shift()), x === "namespace") {
|
|
258
|
+
let C = e.shift();
|
|
259
|
+
e.shift();
|
|
260
|
+
let w = splitUntil(getUntil(e, "}", 0), ";");
|
|
261
|
+
return e.unshift(";"), {
|
|
262
|
+
name: C,
|
|
263
|
+
type: x,
|
|
264
|
+
content: w,
|
|
265
|
+
export: S
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (x === "function") {
|
|
269
|
+
let C = e.shift(), w = e.shift(), T = {
|
|
270
|
+
name: C,
|
|
271
|
+
type: x
|
|
272
|
+
};
|
|
273
|
+
w === "<" && (T.template = getUntil(e, ">"), e.shift());
|
|
274
|
+
let E = splitUntil(getUntil(e, ")", 0), ",");
|
|
275
|
+
return T.export = S, T.params = E, e[0] === ":" && (e.shift(), T.returns = getUntil(e, ";")), e.unshift(";"), T;
|
|
276
|
+
}
|
|
277
|
+
if (x === "interface") {
|
|
278
|
+
let x = e.shift();
|
|
279
|
+
e.shift();
|
|
280
|
+
let S = splitUntil(getUntil(e, "}", 0), ";");
|
|
281
|
+
return e.unshift(";"), {
|
|
282
|
+
name: x,
|
|
283
|
+
type: "interface",
|
|
284
|
+
content: S
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
if (x === "type" && /^[A-Za-z0-9]*$/.test(e[0])) {
|
|
288
|
+
let S = e.shift(), C = e.shift(), w = {
|
|
289
|
+
name: S,
|
|
290
|
+
type: x
|
|
291
|
+
};
|
|
292
|
+
return C === "<" && (w.template = getUntil(e, ">"), e.shift()), w.content = getUntil(e, ";"), e.unshift(";"), w;
|
|
293
|
+
}
|
|
294
|
+
if (x === "enum") {
|
|
295
|
+
let x = e.shift();
|
|
296
|
+
e.shift();
|
|
297
|
+
let S = getUntil(e, "}");
|
|
298
|
+
return e.unshift(";"), {
|
|
299
|
+
name: x,
|
|
300
|
+
type: "enum",
|
|
301
|
+
options: Object.fromEntries(S.join("").split(",").filter((e) => e.trim()).map((e) => {
|
|
302
|
+
if (e.includes("=")) {
|
|
303
|
+
let [x, S] = e.split("=");
|
|
304
|
+
return [JSON.parse(S), x];
|
|
305
|
+
}
|
|
306
|
+
return [x, x];
|
|
307
|
+
}))
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
if (typeof x == "string" && x.startsWith("/*")) return {
|
|
311
|
+
type: "comment",
|
|
312
|
+
content: cleanComment(x)
|
|
313
|
+
};
|
|
314
|
+
for (let S of wrappers) if (x === S[0]) return {
|
|
315
|
+
type: "wrap",
|
|
316
|
+
content: splitUntil(getUntil(e, S[1]), ";").map((e) => splitUntil(e, ",")).map((e) => splitUntil(e, "|")),
|
|
317
|
+
style: S.join("")
|
|
318
|
+
};
|
|
319
|
+
return x;
|
|
320
|
+
}
|
|
321
|
+
function cleanArray(e) {
|
|
322
|
+
return Array.isArray(e) ? e.length === 1 ? cleanArray(e[0]) : e.map((e) => cleanArray(e)) : typeof e == "object" && e ? objectMap(e, ({ value: e }) => cleanArray(e)) : e;
|
|
323
|
+
}
|
|
324
|
+
function cleanComment(e) {
|
|
325
|
+
return e = e.trim(), e.startsWith("/**") && e.endsWith("*/") ? (e = e.slice(3, -2).split("\n").map((e) => {
|
|
326
|
+
let x = e.trim();
|
|
327
|
+
return x.startsWith("* ") ? x.slice(2) : x;
|
|
328
|
+
}).join("\n").trim(), e.trim()) : e;
|
|
329
|
+
}
|
|
330
|
+
function cleanUnion(e) {
|
|
331
|
+
e.elements.find((e) => [EVarType.undefined, EVarType.void].includes(e.type)) && (e.optional = !0, e.elements = e.elements.filter((e) => ![EVarType.undefined, EVarType.void].includes(e.type)));
|
|
332
|
+
let x = e.elements.filter((e) => e.type === EVarType.union);
|
|
333
|
+
if (x.length > 0) {
|
|
334
|
+
e.elements = e.elements.filter((e) => e.type !== EVarType.union);
|
|
335
|
+
for (let S of x) e.elements.push(...S.elements);
|
|
336
|
+
}
|
|
337
|
+
let S = e.elements.filter((e) => e.type === EVarType.string);
|
|
338
|
+
if (S.length > 1) {
|
|
339
|
+
let x = [], C = !1;
|
|
340
|
+
for (let e of S) e.enum ? x.push(...e.enum) : C = !0;
|
|
341
|
+
e.elements = e.elements.filter((e) => e.type !== EVarType.string), C ? e.elements.push(LogicType.string()) : e.elements.push(LogicType.string({ enum: x }));
|
|
342
|
+
}
|
|
343
|
+
let C = e.elements.filter((e) => e.type === EVarType.number);
|
|
344
|
+
if (C.length > 1) {
|
|
345
|
+
let x = [], S = !1;
|
|
346
|
+
for (let e of C) e.enum ? x.push(...e.enum) : S = !0;
|
|
347
|
+
e.elements = e.elements.filter((e) => e.type !== EVarType.number), S ? e.elements.push(LogicType.number()) : e.elements.push(LogicType.number({ enum: x }));
|
|
348
|
+
}
|
|
349
|
+
if (e.elements.length === 1) {
|
|
350
|
+
let x = e.elements[0];
|
|
351
|
+
return x.optional = e.optional, x;
|
|
352
|
+
}
|
|
353
|
+
return e.elements.length === 0 ? LogicType.void() : e;
|
|
354
|
+
}
|
|
355
|
+
function cleanInterface(e) {
|
|
356
|
+
return e.className === "Array" ? LogicType.array(e.options.template[0]) : e.className === "keyof" ? LogicType.string() : e.className === "Record" ? LogicType.object({}) : e.className === "PropertyKey" ? LogicType.union([LogicType.string(), LogicType.number()]) : [
|
|
357
|
+
"Promise",
|
|
358
|
+
"Partial",
|
|
359
|
+
"Required"
|
|
360
|
+
].includes(e.className) ? LogicUtil[e.className.toLocaleLowerCase()](e.options.template[0]) : ["Omit", "Pick"].includes(e.className) ? LogicUtil[e.className.toLocaleLowerCase()](e.options.template[0], e.options.template[1]?.enum) : e;
|
|
361
|
+
}
|
|
362
|
+
function parser(e, x = {}) {
|
|
363
|
+
if (typeof e == "string") return e === "string" ? LogicType.string(x) : e === "number" ? LogicType.number(x) : e === "boolean" ? LogicType.boolean(x) : e === "undefined" ? LogicType.void(x) : ["unknown", "any"].includes(e) ? LogicType.unknown(x) : ["undefined", "null"].includes(e) ? LogicType.undefined(x) : cleanInterface(LogicType.interface(e, x));
|
|
364
|
+
if (Array.isArray(e)) {
|
|
365
|
+
if (e[0] === "readonly" && e.shift(), e.length === 1) return parser(e[0], x);
|
|
366
|
+
if (e.includes("|")) return cleanUnion(LogicType.union(separate(e, (e) => e === "|").map((e) => parser(e)), x));
|
|
367
|
+
if (e.includes("&")) return cleanUnion(LogicType.union(separate(e, (e) => e === "&").map((e) => parser(e)), x));
|
|
368
|
+
if (e.at(-1)?.type === "wrap" && e.at(-1).style === "[]") return LogicType.array(parser(e.slice(0, -1)), x);
|
|
369
|
+
if (e[0] === "import" && e[2] === ".") return parser(e.slice(3), x);
|
|
370
|
+
if (e.length === 2 && e[1].type === "wrap" && e[1].style === "<>") {
|
|
371
|
+
let S = e[1].content;
|
|
372
|
+
return Array.isArray(S) || (S = [S]), Array.isArray(S[0]) || (S = S.some((e) => e.type === "wrap" && e.style === "[]") || S.some((e) => e.type === "wrap" && e.style === "<>") || S.includes("&") || S.includes("|") ? [S] : S.map((e) => [e])), S = S.map((e) => parser(e)), cleanInterface(LogicType.interface(e[0], {
|
|
373
|
+
...x,
|
|
374
|
+
options: { template: S }
|
|
375
|
+
}));
|
|
376
|
+
}
|
|
377
|
+
if (e.length === 3 && e[1] === "=>") {
|
|
378
|
+
let x = !e[0].content.length || Array.isArray(e[0].content[0]) ? e[0].content : [e[0].content];
|
|
379
|
+
return LogicType.function(LogicType.object(Object.fromEntries(x.map((e) => [e[0], parser(e.slice(2))]))), parser(e[2]));
|
|
380
|
+
}
|
|
381
|
+
return parser(e[0], x);
|
|
382
|
+
}
|
|
383
|
+
if (typeof e == "object" && e && e.type === "wrap") {
|
|
384
|
+
if (["''", "\"\""].includes(e.style)) return LogicType.string({
|
|
385
|
+
...x,
|
|
386
|
+
enum: [e.content]
|
|
387
|
+
});
|
|
388
|
+
if (e.style === "{}") {
|
|
389
|
+
let S = !e.content.length || Array.isArray(e.content[0]) ? e.content : [e.content];
|
|
390
|
+
return LogicType.object(Object.fromEntries(S.filter((e) => typeof e[0] == "string").map((e) => [e[0], e[1] === "?" ? parser(e.slice(3), { optional: !0 }) : parser(e.slice(2))])), x);
|
|
391
|
+
}
|
|
392
|
+
if (e.style === "[]") return e.content[1] === ":" ? LogicType.array(parser(e.content.slice(2)), x) : LogicType.array(parser(e.content), x);
|
|
393
|
+
if (e.style === "()") return parser(e.content, x);
|
|
394
|
+
}
|
|
395
|
+
return console.log("Unknown element"), console.log(e), LogicType.unknown();
|
|
396
|
+
}
|
|
397
|
+
function separate(e, x) {
|
|
398
|
+
let S = [[]];
|
|
399
|
+
for (let C of e) x(C) ? S.push([]) : S[S.length - 1].push(C);
|
|
400
|
+
return S;
|
|
401
|
+
}
|
|
402
|
+
function typeToSchema(e) {
|
|
403
|
+
try {
|
|
404
|
+
if (/^[A-Za-z]+\??:/.test(e)) {
|
|
405
|
+
let [, x, S, C] = e.match(/([A-Za-z]+)(\??):(.*)/), w = parser(lexer(scanner(C)));
|
|
406
|
+
return w.name = x, S === "?" && (w.optional = !0), w;
|
|
407
|
+
}
|
|
408
|
+
return parser(lexer(scanner(e)));
|
|
409
|
+
} catch (x) {
|
|
410
|
+
return console.error("Failed to parse type", e), console.error(x), LogicType.unknown();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function schemaLoop(e, x, S) {
|
|
414
|
+
if (e = x({
|
|
415
|
+
key: S,
|
|
416
|
+
schema: e
|
|
417
|
+
}) || e, e.type === EVarType.object) for (let S in e.properties) e.properties[S] = schemaLoop(e.properties[S], x, S);
|
|
418
|
+
if (e.type === EVarType.array && (e.items = schemaLoop(e.items, x)), e.type === EVarType.function && (e.inputs = schemaLoop(e.inputs, x), e.output = schemaLoop(e.output, x)), e.type === EVarType.union) for (let S in e.elements) e.elements[S] = schemaLoop(e.elements[S], x);
|
|
419
|
+
return e;
|
|
420
|
+
}
|
|
421
|
+
export { LogicUtil as a, typeToSchema as c, objectMap as d, LogicType as i, cleanObject as l, ELogicType as n, makeLogicNode as o, EVarType as r, schemaLoop as s, ELogicScope as t, cloneWithFunctions as u };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
function e(e){if(typeof e!=`object`)return e;let n=[()=>JSON.parse(JSON.stringify(e)),()=>structuredClone(e),()=>t(e)],r;for(let e of n)try{return e()}catch(e){r=e;continue}throw console.error(`Failed to deep clone object:`,e),Error(r)}function t(e){let t=new WeakSet;return n(e);function n(e){if(typeof e!=`object`)return e;if(t.has(e))return{recursive:!0};if(t.add(e),Array.isArray(e))return e.map(e=>n(e));let r=Object.getOwnPropertyDescriptors(e),i={};for(let[e,t]of Object.entries(r))i[e]=n(t.value);return i}}function n(e){if(Array.isArray(e))return e.map(n);if(typeof e!=`object`)return e;let t={};for(let[r,i]of Object.entries(e)){if(typeof i==`function`){t[r]=i;continue}t[r]=n(i)}return t}function r(e,t){return e?Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t({key:e,value:n})])):{}}function i(e,t){return e?Object.fromEntries(Object.entries(e).filter(([e,n])=>t({key:e,value:n}))):{}}function a(t){for(let r in t=e(t),t)n(t,r);function n(e,t){if(typeof e[t]==`object`){for(let r in e[t])n(e[t],r);Object.keys(e[t]).length===0&&delete e[t]}}return t}var o=function(e){return e.exec=`exec`,e.number=`number`,e.string=`string`,e.boolean=`boolean`,e.object=`object`,e.record=`record`,e.array=`array`,e.interface=`interface`,e.type=`type`,e.function=`function`,e.union=`union`,e.unknown=`unknown`,e.undefined=`undefined`,e.void=`void`,e}({}),s={array:(e,t={})=>({...t,items:e,type:o.array}),boolean:(e={})=>({...e,type:o.boolean}),exec:(e={})=>({...e,type:o.exec}),function:(e={properties:{},type:o.object},t={type:o.void},n={})=>({...n,inputs:e,output:t,type:o.function}),interface:(e,t={})=>({...t,className:typeof e==`string`?e:e.name,type:o.interface}),number:(e={})=>({...e,type:o.number}),object:(e={},t={})=>({...t,properties:e,type:o.object}),record:(e,t,n={})=>({...n,key:e,type:o.record,value:t}),string:(e={})=>({...e,type:o.string}),type:(e,t={})=>({...t,target:e,type:o.type}),undefined:(e={})=>({...e,type:o.undefined}),union:(e,t={})=>({...t,elements:e,type:o.union}),unknown:(e={})=>({...e,type:o.unknown}),void:(e={})=>({...e,type:o.void})},c={omit(e,t){return{...e,properties:i(e.properties,({key:e})=>!t.includes(e))}},partial(e,t=!1){return{...e,properties:r(e.properties,({value:e})=>({...e,optional:!t||!e.required}))}},pick(e,t){return{...e,properties:i(e.properties,({key:e})=>t.includes(e))}},promise(e){return{...e,promise:!0}},required(e){return{...e,properties:r(e.properties,({value:e})=>({...e,optional:!1}))}}},l=function(e){return e.function=`function`,e.macro=`macro`,e.operation=`operation`,e}({}),u=function(e){return e.Frontend=`frontend`,e.Backend=`backend`,e.Desktop=`desktop`,e.Shared=`shared`,e}({});function d(e){return e}function f(e){let t=[];for(e=e.replaceAll(/ +/g,` `),e=e.replaceAll(/\s*\n\s*/g,`
|
|
2
|
+
`);e.length;){if([` `,`
|
|
3
|
+
`].includes(e[0])){e=e.slice(1);continue}if(e.startsWith(`/*`)){let n=e.indexOf(`*/`);t.push(e.slice(0,n+2)),e=e.slice(n+2);continue}let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];if(n){e=e.slice(n.length),t.push(n);continue}let r=e.match(/^([0-9]+)/)?.[0];if(r){e=e.slice(r.length),t.push(r);continue}if(e[0]===`>`&&t.at(-1)===`=`){t.pop(),t.push(`=>`),e=e.slice(1);continue}t.push(e[0]),e=e.slice(1)}return t}var p=[[`(`,`)`],[`[`,`]`],[`{`,`}`],[`<`,`>`],[`'`,`'`],[`"`,`"`]];function m(e){return y(_(e,`;`))}function h(e,t,n=1){let r=[];for(p.find(e=>e[1]===t)?.[0];e.length&&(e[0],!(e[0]===t&&(n--,n<=0)));){let i=v(e);if(r.push(i),n===0&&typeof i==`object`&&i.type===`wrap`&&i.style.endsWith(t))break}return e.shift(),r}function g(e,t){for(;e.length;){if(e[0]===t){e.shift();break}e.shift()}}function _(e,t){let n=[[]];for(;e.length;){if(e[0]===t){n.push([]),e.shift();continue}n.at(-1).push(v(e))}return n.filter(e=>e.length)}function v(e){let t=e.shift(),n=!1;if(t===`export`){if(n=!0,t=e.shift(),t===`=`)return{type:`export`,content:e.shift()};if(t===`as`)return g(e,`;`),v(e)}if(t===`declare`&&(t=e.shift()),t===`namespace`){let r=e.shift();e.shift();let i=_(h(e,`}`,0),`;`);return e.unshift(`;`),{name:r,type:t,content:i,export:n}}if(t===`function`){let r=e.shift(),i=e.shift(),a={name:r,type:t};i===`<`&&(a.template=h(e,`>`),e.shift());let o=_(h(e,`)`,0),`,`);return a.export=n,a.params=o,e[0]===`:`&&(e.shift(),a.returns=h(e,`;`)),e.unshift(`;`),a}if(t===`interface`){let t=e.shift();e.shift();let n=_(h(e,`}`,0),`;`);return e.unshift(`;`),{name:t,type:`interface`,content:n}}if(t===`type`&&/^[A-Za-z0-9]*$/.test(e[0])){let n=e.shift(),r=e.shift(),i={name:n,type:t};return r===`<`&&(i.template=h(e,`>`),e.shift()),i.content=h(e,`;`),e.unshift(`;`),i}if(t===`enum`){let t=e.shift();e.shift();let n=h(e,`}`);return e.unshift(`;`),{name:t,type:`enum`,options:Object.fromEntries(n.join(``).split(`,`).filter(e=>e.trim()).map(e=>{if(e.includes(`=`)){let[t,n]=e.split(`=`);return[JSON.parse(n),t]}return[t,t]}))}}if(typeof t==`string`&&t.startsWith(`/*`))return{type:`comment`,content:b(t)};for(let n of p)if(t===n[0])return{type:`wrap`,content:_(h(e,n[1]),`;`).map(e=>_(e,`,`)).map(e=>_(e,`|`)),style:n.join(``)};return t}function y(e){return Array.isArray(e)?e.length===1?y(e[0]):e.map(e=>y(e)):typeof e==`object`&&e?r(e,({value:e})=>y(e)):e}function b(e){return e=e.trim(),e.startsWith(`/**`)&&e.endsWith(`*/`)?(e=e.slice(3,-2).split(`
|
|
4
|
+
`).map(e=>{let t=e.trim();return t.startsWith(`* `)?t.slice(2):t}).join(`
|
|
5
|
+
`).trim(),e.trim()):e}function x(e){e.elements.find(e=>[o.undefined,o.void].includes(e.type))&&(e.optional=!0,e.elements=e.elements.filter(e=>![o.undefined,o.void].includes(e.type)));let t=e.elements.filter(e=>e.type===o.union);if(t.length>0){e.elements=e.elements.filter(e=>e.type!==o.union);for(let n of t)e.elements.push(...n.elements)}let n=e.elements.filter(e=>e.type===o.string);if(n.length>1){let t=[],r=!1;for(let e of n)e.enum?t.push(...e.enum):r=!0;e.elements=e.elements.filter(e=>e.type!==o.string),r?e.elements.push(s.string()):e.elements.push(s.string({enum:t}))}let r=e.elements.filter(e=>e.type===o.number);if(r.length>1){let t=[],n=!1;for(let e of r)e.enum?t.push(...e.enum):n=!0;e.elements=e.elements.filter(e=>e.type!==o.number),n?e.elements.push(s.number()):e.elements.push(s.number({enum:t}))}if(e.elements.length===1){let t=e.elements[0];return t.optional=e.optional,t}return e.elements.length===0?s.void():e}function S(e){return e.className===`Array`?s.array(e.options.template[0]):e.className===`keyof`?s.string():e.className===`Record`?s.object({}):e.className===`PropertyKey`?s.union([s.string(),s.number()]):[`Promise`,`Partial`,`Required`].includes(e.className)?c[e.className.toLocaleLowerCase()](e.options.template[0]):[`Omit`,`Pick`].includes(e.className)?c[e.className.toLocaleLowerCase()](e.options.template[0],e.options.template[1]?.enum):e}function C(e,t={}){if(typeof e==`string`)return e===`string`?s.string(t):e===`number`?s.number(t):e===`boolean`?s.boolean(t):e===`undefined`?s.void(t):[`unknown`,`any`].includes(e)?s.unknown(t):[`undefined`,`null`].includes(e)?s.undefined(t):S(s.interface(e,t));if(Array.isArray(e)){if(e[0]===`readonly`&&e.shift(),e.length===1)return C(e[0],t);if(e.includes(`|`))return x(s.union(w(e,e=>e===`|`).map(e=>C(e)),t));if(e.includes(`&`))return x(s.union(w(e,e=>e===`&`).map(e=>C(e)),t));if(e.at(-1)?.type===`wrap`&&e.at(-1).style===`[]`)return s.array(C(e.slice(0,-1)),t);if(e[0]===`import`&&e[2]===`.`)return C(e.slice(3),t);if(e.length===2&&e[1].type===`wrap`&&e[1].style===`<>`){let n=e[1].content;return Array.isArray(n)||(n=[n]),Array.isArray(n[0])||(n=n.some(e=>e.type===`wrap`&&e.style===`[]`)||n.some(e=>e.type===`wrap`&&e.style===`<>`)||n.includes(`&`)||n.includes(`|`)?[n]:n.map(e=>[e])),n=n.map(e=>C(e)),S(s.interface(e[0],{...t,options:{template:n}}))}if(e.length===3&&e[1]===`=>`){let t=!e[0].content.length||Array.isArray(e[0].content[0])?e[0].content:[e[0].content];return s.function(s.object(Object.fromEntries(t.map(e=>[e[0],C(e.slice(2))]))),C(e[2]))}return C(e[0],t)}if(typeof e==`object`&&e&&e.type===`wrap`){if([`''`,`""`].includes(e.style))return s.string({...t,enum:[e.content]});if(e.style===`{}`){let n=!e.content.length||Array.isArray(e.content[0])?e.content:[e.content];return s.object(Object.fromEntries(n.filter(e=>typeof e[0]==`string`).map(e=>[e[0],e[1]===`?`?C(e.slice(3),{optional:!0}):C(e.slice(2))])),t)}if(e.style===`[]`)return e.content[1]===`:`?s.array(C(e.content.slice(2)),t):s.array(C(e.content),t);if(e.style===`()`)return C(e.content,t)}return console.log(`Unknown element`),console.log(e),s.unknown()}function w(e,t){let n=[[]];for(let r of e)t(r)?n.push([]):n[n.length-1].push(r);return n}function T(e){try{if(/^[A-Za-z]+\??:/.test(e)){let[,t,n,r]=e.match(/([A-Za-z]+)(\??):(.*)/),i=C(m(f(r)));return i.name=t,n===`?`&&(i.optional=!0),i}return C(m(f(e)))}catch(t){return console.error(`Failed to parse type`,e),console.error(t),s.unknown()}}function E(e,t,n){if(e=t({key:n,schema:e})||e,e.type===o.object)for(let n in e.properties)e.properties[n]=E(e.properties[n],t,n);if(e.type===o.array&&(e.items=E(e.items,t)),e.type===o.function&&(e.inputs=E(e.inputs,t),e.output=E(e.output,t)),e.type===o.union)for(let n in e.elements)e.elements[n]=E(e.elements[n],t);return e}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return n}});
|
package/dist/extractor.cjs
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
`)});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-rCEYsGS8.cjs`),t=require(`./dist-BkSFkjuo.cjs`);let n=require(`node:fs`);n=e.n(n);let r=require(`typescript`);r=e.n(r);let i=require(`path`);i=e.n(i);let a=require(`fs`);a=e.n(a);function o(e,n={}){if(typeof e!=`object`||!e)return JSON.stringify(e);let r={};for(let t of[`default`,`description`,`name`,`target`,`promise`,`optional`,`example`,`enum`])e[t]&&(r[t]=e[t]);if(e.type===t.r.array)return s(`LogicType.${e.type}`,[o(e.items,n),c(r)]);if(e.type===t.r.interface)return s(`LogicType.${e.type}`,[JSON.stringify(e.className),c(r)]);if(e.type===t.r.union)return s(`LogicType.${e.type}`,[`[${e.elements.map(e=>o(e,n)).join(`, `)}]`,c(r)]);if(e.type===t.r.function)return s(`LogicType.${e.type}`,[o(e.inputs,n),o(e.output,n),c(r)]);if(e.type===t.r.object)return s(`LogicType.${e.type}`,[c(t.d(e.properties,({value:e})=>o(e,n)),!0),c(r)]);if(e.type===t.r.type){let t=e.target.at(-1),n=c(r);return n===`{}`?`{ ...${t}, ${n.slice(1,-1)} }`:t}return s(`LogicType.${e.type}`,[c(r)])}function s(e,t){let n=t.findLastIndex(e=>e!==`{}`);return`${e}(${t.slice(0,n+1).join(`, `)})`}function c(e,t){return`{${Object.entries(e).map(([e,n])=>`${l(e)}: ${t?n:JSON.stringify(n)}`).join(`, `)}}`}function l(e){return/^[a-zA-Z]+$/.test(e)?e:JSON.stringify(e)}function u(e,t){let n=[],r=e.components.default,i=Object.keys(e.types);for(let e of[`properties`,`slots`,`models`,`emits`])r[e]&&Object.keys(r[e]).length&&n.push({key:e,value:Object.entries(r[e]).map(([e,t])=>`${l(e)}: ${o(t,{lib:i})}`).join(`,
|
|
2
|
+
`)});let a=Object.entries(e.types).map(([e,t])=>`const ${e} = ${o(t,{lib:i})};`).join(`
|
|
3
3
|
|
|
4
4
|
`);return`import { LogicType, type TComponent } from "@luna-park/plugin";
|
|
5
|
-
import ${
|
|
5
|
+
import ${t.name} from "${t.path}";
|
|
6
6
|
|
|
7
|
-
${
|
|
7
|
+
${a}
|
|
8
8
|
|
|
9
|
-
export const ${
|
|
10
|
-
name: "${
|
|
11
|
-
component: ${
|
|
12
|
-
${
|
|
13
|
-
${l}
|
|
14
|
-
}`).join(`,
|
|
9
|
+
export const ${t.name.toLocaleLowerCase()}: TComponent = {
|
|
10
|
+
name: "${t.name}",
|
|
11
|
+
component: ${t.name},
|
|
12
|
+
${n.map(({key:e,value:t})=>`${e}: {\n ${t}\n }`).join(`,
|
|
15
13
|
`)}
|
|
16
|
-
}`}function h(t,e){const o={description:x(t.getDocumentationComment(e))||void 0};for(const n of t.getJsDocTags()){if(n.name==="param"){o.params||(o.params={});let i=x(n.text?.slice(1)).trim();i.startsWith("- ")&&(i=i.slice(2));const r=n.text[0]?.text;o.params[r]=i;continue}o[n.name]=x(n.text)}return p.F(o)}function x(t=[]){return t.map(e=>e.text).join("")}function w(t,e){const o=e.checker.getPropertiesOfType(t),n={};return o.forEach(i=>{const r=A(e.checker.getTypeOfSymbol(i)).type,s=e.checker.getSignaturesOfType(r,m.SignatureKind.Call)[0]?.parameters?.[0];if(s){const c=e.checker.getTypeOfSymbol(s);n[i.name]={type:e.typeToString(c)},e.extractType(c)}else n[i.name]={type:"{}"}}),n}function N(t,e){const o=e.checker.getPropertiesOfType(t),n={},i={};return o.forEach(r=>{if(["onVnode","ref_"].some(s=>r.name.startsWith(s))||["ref","class","style","key"].includes(r.name))return;const l=e.checker.getTypeOfSymbol(r);if(e.extractType(l),W(r.name)){i[H(r.name)]=L(l,r,e);return}n[r.name]=L(l,r,e)}),{emits:i,props:n}}function v(t){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}function A(t){if(t.isUnion()){const e=t.types.filter(o=>o.flags!==m.TypeFlags.Undefined);if(e.length===1)return{optional:!0,type:e[0]}}return{type:t}}function L(t,e,o){const n=A(t);return p.F({description:h(e,o.checker).description,optional:n.optional,type:o.typeToString(n.type)})}function W(t){return/^on[A-Z]/.test(t)}function H(t){return t=t.slice(2),t.charAt(0).toLowerCase()+t.slice(1)}function K(t,e){return Object.fromEntries((t.getTypeParameters()??[]).map(o=>{let n="unknown";const i=o.getDefault();i&&(n=e.typeToString(i));const r=o.getConstraint();return r&&(n=e.typeToString(r)),[o.symbol.name,n]}))}function Q(t,e){const o=new Map,n=t.getExportsOfModule(e);for(const i of n){let r=i;for(;r.flags&m.SymbolFlags.Alias;)r=t.getAliasedSymbol(r);o.set(i.name,r)}return o}function k(t,e){let o=t.getFullyQualifiedName(e);return o.includes('".')&&(o=o.split('".').pop()),o.includes(").")&&(o=o.split(").").pop()),o}function F(t,e){for(const[o,n]of Object.entries(e))t=t.replace(new RegExp(`\\b${o}\\b`,"g"),n);return t}function R(t){const e=[];return t.members.forEach(n=>{const i=n.name.getText();if(n.initializer){let r;m.isStringLiteral(n.initializer)?r=`"${n.initializer.text}"`:m.isNumericLiteral(n.initializer)?r=n.initializer.text:r=n.initializer.getText(),e.push(`${i} = ${r}`)}else e.push(i)}),`{ ${e.join(", ")} }`}function $(t){if(t.getFlags()&(f.TypeFlags.StringLike|f.TypeFlags.NumberLike|f.TypeFlags.BooleanLike|f.TypeFlags.ESSymbolLike|f.TypeFlags.Void|f.TypeFlags.Undefined|f.TypeFlags.Null|f.TypeFlags.Any|f.TypeFlags.Unknown|f.TypeFlags.Never))return!1;const o=t.getSymbol();if(!o)return!0;const n=o.declarations?.[0];if(!n)return!0;const i=n.getSourceFile();return!(/lib\..*\.d\.ts$/.test(i.fileName)||i.fileName.startsWith("/@vue/"))}const E=f.TypeFormatFlags.WriteArrowStyleSignature|f.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope|f.TypeFormatFlags.NoTruncation|f.TypeFormatFlags.UseFullyQualifiedType;class D{constructor(e){this.program=e,this.checker=e.getTypeChecker()}checker;index;cache=new Set;result;get(e){if(this.index=this.program.getSourceFile(e),!this.index)throw new Error(`Cannot find file ${e}`);const o=this.checker.getSymbolAtLocation(this.index);if(!o)throw new Error(`Cannot find module ${e}`);this.result={components:{},functions:{},types:{}};const n=this.index.statements.find(i=>f.isExportAssignment(i));if(n){const r=this.checker.getTypeAtLocation(n.expression).getCallSignatures()[0];r&&this.exportFunction("default",r)}return this.exportModule(o),this.result}exportModule(e){const o=Q(this.checker,e);for(const[n,i]of o.entries()){let r=this.checker.getTypeOfSymbol(i);if(r.symbol&&r.symbol.flags&f.SymbolFlags.Module){const s=r.symbol.exports?.get("default");s&&(r=this.checker.getTypeOfSymbol(s))}const l=r.symbol||r.aliasSymbol;if(l?.flags&f.SymbolFlags.Function){const s=this.checker.getTypeOfSymbol(l),c=this.checker.getSignaturesOfType(s,f.SignatureKind.Call)[0];if(c){const a=k(this.checker,l);this.exportFunction(a,c)}}else if(this.typeToString(r).includes("DefineComponent<"))try{this.exportComponent(n,r)}catch(c){console.error(`Fail to export component ${n}`),console.error(c)}}}exportComponent(e,o){const n=o.getConstructSignatures()[0];if(!n)return;const i=this.checker.getReturnTypeOfSignature(n),r={},l=this.checker.getPropertyOfType(i,"$props");if(l){const c=this.checker.getTypeOfSymbol(l),a=N(c,this);r.properties=a.props,r.emits=a.emits}const s=this.checker.getPropertyOfType(i,"$slots");if(s){const c=this.checker.getTypeOfSymbol(s);r.slots=w(c,this)}this.result.components[e]=v(r)}exportFunction(e,o){const n=h(o,this.checker),i=K(o,this),r=o.getParameters().map(s=>{const c=s.valueDeclaration??this.index,a=this.checker.getTypeOfSymbol(s);this.extractType(a,c);const u=s.valueDeclaration?.initializer?.getText();return p.F({default:u,description:n.params?.[s.name],name:s.name,optional:!!c.questionToken||u!==void 0||void 0,type:F(this.typeToString(a),i)})});if(r.some(s=>s.name?.startsWith("__VLS_"))){const s={},c=r.findIndex(y=>y.name==="__VLS_props"),a=o.getParameters()[c];if(a){const y=this.checker.getTypeOfSymbol(a),b=N(y,this);s.properties=b.props,s.emits=b.emits,Object.values(s.properties).forEach(C=>{C.type=F(C.type,i)})}const u=r.findIndex(y=>y.name==="__VLS_slots"),g=o.getParameters()[u];if(g){const y=this.checker.getTypeOfSymbol(g);s.slots=w(y,this),Object.values(s.slots).forEach(b=>{b.type=F(b.type,i)})}this.result.components[e]=v(s);return}const l=this.checker.getReturnTypeOfSignature(o);this.extractType(l),this.result.functions[e]=p.F({description:n.description,parameters:r,return:{description:n.returns,type:F(this.typeToString(l),i)}})}extractType(e,o=this.index){if(this.cache.has(e))return;this.cache.add(e);const n=e.symbol||e.aliasSymbol;if((e.isUnion()||e.isIntersection())&&!(n?.flags&f.SymbolFlags.Enum)&&e.types.forEach(i=>{this.extractType(i,o)}),n){if(this.checker.getFullyQualifiedName(n).includes("/@vue/"))return;const i=k(this.checker,n);if(n.flags&f.SymbolFlags.Enum){const r=n.valueDeclaration||n.declarations?.[0];if(r&&f.isEnumDeclaration(r)){const l=k(this.checker,n);this.result.types[l]=p.F({...h(n,this.checker),type:R(r)})}return}if(n.flags&f.SymbolFlags.Namespace){const r=n;this.exportModule(r)}if(n.flags&f.SymbolFlags.TypeAlias){const r=n.valueDeclaration||n.declarations?.[0];if(!r)return;const l=Object.fromEntries((r?.typeParameters??[]).map(s=>{let c="unknown";const a=s.default;if(a){const g=this.checker.getTypeFromTypeNode(a);c=this.typeToString(g)}const u=s.constraint;if(u){const g=this.checker.getTypeFromTypeNode(u);c=this.typeToString(g)}return[s.symbol.name,c]}));this.result.types[i]={...h(n,this.checker),type:F(this.typeToString(e,E|f.TypeFormatFlags.InTypeAlias),l)}}if(n.flags&f.SymbolFlags.Interface&&$(e)){const r=n.getDeclarations()[0];if(r){const l=this.checker.getPropertiesOfType(e),s={};l.forEach(c=>{const a=this.checker.getTypeOfSymbol(c);this.extractType(a,r),s[c.name]={...h(c,this.checker),optional:!!(c.flags&f.SymbolFlags.Optional)||void 0,type:this.typeToString(a)}}),this.result.types[i]={...h(n,this.checker),type:s}}}if(n.flags&f.SymbolFlags.TypeLiteral){const r=k(this.checker,e.aliasSymbol||e.symbol),l=this.checker.getPropertiesOfType(e),s={};if(["Promise","Partial","Pick","Omit","Required"].includes(r)){this.cache.delete(e),this.extractType(e.aliasTypeArguments[0]);return}if(e.aliasTypeArguments?.some(c=>!$(c)))return;l.forEach(c=>{const a=this.checker.getTypeOfSymbol(c);s[c.name]={...h(c,this.checker),optional:!!(c.flags&f.SymbolFlags.Optional),type:this.typeToString(a)}}),r!=="__type"&&(this.result.types[r]={...h(n,this.checker),type:s})}}if(e.flags&f.TypeFlags.Object){const i=e;if($(e)&&this.checker.getPropertiesOfType(e).forEach(l=>{const s=this.checker.getTypeOfSymbol(l);this.extractType(s,o)}),i.objectFlags&f.ObjectFlags.Reference){const r=i;this.checker.getTypeArguments(r).forEach(s=>{this.extractType(s,o)})}}}typeToString(e,o=E){return this.checker.typeToString(e,void 0,o)}}function M(t,e="unknown"){const o={components:{},functions:{},types:{}};for(const[s,c]of Object.entries(t.types))o.types[s]=n(c,s);for(const[s,c]of Object.entries(t.functions))o.functions[s]=i(c,s);for(const[s,c]of Object.entries(t.components))o.components[s]=r(c,s);return o;function n(s,c=""){if(typeof s.type=="string"){if(s.type==="{}")return p.u.void();const a={...l(p.ot$1(s.type)),...p.F({description:s.description,name:c?.split(".").pop()||void 0,optional:s.optional})};if(s.default)switch(a.type){case p.i.boolean:a.default=s.default==="true";break;case p.i.number:a.default=Number(s.default);break;case p.i.string:a.default=s.default;break}return a.type===p.i.object&&!Object.keys(a.properties).length&&(a.customizable=!0),a}else{const a=p.u.object(p.ot(s.type,({key:u,value:g})=>n(g,u)),p.F({description:s.description,name:c?.split(".").pop(),optional:s.optional}));return Object.keys(a.properties).length||(a.customizable=!0),a}}function i(s,c=""){return{...p.F({description:s.description,name:c?.split(".").pop()}),parameters:(s.parameters??[]).map(a=>n(a,a.name)),return:n(s.return,"result")}}function r(s,c=""){return{...p.F({name:c?.split(".").pop()}),emits:p.ot(s.emits,({value:a})=>n(a)),models:p.ot(s.models,({value:a})=>n(a)),properties:p.ot(s.properties,({key:a,value:u})=>n(u,a)),slots:p.ot(s.slots,({value:a})=>n(a))}}function l(s,c=""){return p.m(s,u=>{if(u.type===p.i.interface)return{...a(u.className,c),description:u.description,name:u.name,optional:u.optional}});function a(u,g=""){let y=`${g}${u}`;for(;!t.types[y]&&y.indexOf(".")!==-1;)y=y.substring(y.indexOf(".")+1);return t.types[y]?p.u.type(["packages",e,...y.split(".")]):p.u.interface(u)}}}function Z(t){for(;;){const e=O.join(t,"tsconfig.json");if(J.existsSync(e))return e;const o=O.dirname(t);if(o===t)return;t=o}}function B(t){const e=m.readConfigFile(t,m.sys.readFile);if(e.error)throw new Error(`Failed to read tsconfig.json: ${e.error.messageText}`);return m.parseJsonConfigFileContent(e.config,m.sys,O.dirname(t))}function G(t,e){const o=O.join(process.cwd(),"__temp__.ts"),n=m.createCompilerHost(e),i=m.resolveModuleName(t,o,e,n);if(i.resolvedModule)return i.resolvedModule.resolvedFileName}function z(t){const e=Z(t);if(!e)throw new Error(`Could not find tsconfig.json for: ${t}`);const n=B(e).options,i=G(t,n);if(!i)throw new Error(`Could not resolve module: ${t}`);const r=m.createCompilerHost(n),l=m.createProgram({host:r,options:n,rootNames:[i]}),s=l.getSourceFile(i);if(!s)throw new Error(`Could not get source file for: ${i}`);return{program:l,sourceFile:s}}const _=I.promises;async function X(t,e){const o=t.split("/").pop().split(".")[0],{program:n,sourceFile:i}=z(t),l=new D(n).get(i.fileName),s=M(l,o);if(s.components.default){const c=V(s,{name:o,path:t});await _.mkdir(e.split("/").slice(0,-1).join("/"),{recursive:!0}),await _.writeFile(e,c)}}exports.CTypeExport=D;exports.extractFile=X;exports.generateNodes=M;exports.getSourceFile=z;
|
|
14
|
+
}`}function d(e,n){let r={description:f(e.getDocumentationComment(n))||void 0};for(let t of e.getJsDocTags()){if(t.name===`param`){r.params||={};let e=f(t.text?.slice(1)).trim();e.startsWith(`- `)&&(e=e.slice(2));let n=t.text[0]?.text;r.params[n]=e;continue}r[t.name]=f(t.text)}return t.l(r)}function f(e=[]){return e.map(e=>e.text).join(``)}function p(e,t){let n=t.checker.getPropertiesOfType(e),i={};return n.forEach(e=>{let n=g(t.checker.getTypeOfSymbol(e)).type,a=t.checker.getSignaturesOfType(n,r.SignatureKind.Call)[0]?.parameters?.[0];if(a){let n=t.checker.getTypeOfSymbol(a);i[e.name]={type:t.typeToString(n)},t.extractType(n)}else i[e.name]={type:`{}`}}),i}function m(e,t){let n=t.checker.getPropertiesOfType(e),r={},i={};return n.forEach(e=>{if([`onVnode`,`ref_`].some(t=>e.name.startsWith(t))||[`ref`,`class`,`style`,`key`].includes(e.name))return;let n=t.checker.getTypeOfSymbol(e);if(t.extractType(n),v(e.name)){i[y(e.name)]=_(n,e,t);return}r[e.name]=_(n,e,t)}),{emits:i,props:r}}function h(e){return e.models=Object.keys(e.properties??{}).reduce((t,n)=>(e.emits?.[`update:${n}`]&&(t[n]=e.properties[n],delete e.properties[n],delete e.emits[`update:${n}`]),t),{}),e}function g(e){if(e.isUnion()){let t=e.types.filter(e=>e.flags!==r.TypeFlags.Undefined);if(t.length===1)return{optional:!0,type:t[0]}}return{type:e}}function _(e,n,r){let i=g(e);return t.l({description:d(n,r.checker).description,optional:i.optional,type:r.typeToString(i.type)})}function v(e){return/^on[A-Z]/.test(e)}function y(e){return e=e.slice(2),e.charAt(0).toLowerCase()+e.slice(1)}function b(e,t){return Object.fromEntries((e.getTypeParameters()??[]).map(e=>{let n=`unknown`,r=e.getDefault();r&&(n=t.typeToString(r));let i=e.getConstraint();return i&&(n=t.typeToString(i)),[e.symbol.name,n]}))}function x(e,t){let n=new Map,i=e.getExportsOfModule(t);for(let t of i){let i=t;for(;i.flags&r.SymbolFlags.Alias;)i=e.getAliasedSymbol(i);n.set(t.name,i)}return n}function S(e,t){let n=e.getFullyQualifiedName(t);return n.includes(`".`)&&(n=n.split(`".`).pop()),n.includes(`).`)&&(n=n.split(`).`).pop()),n}function C(e,t){for(let[n,r]of Object.entries(t))e=e.replace(RegExp(`\\b${n}\\b`,`g`),r);return e}function w(e){let t=[];return e.members.forEach(e=>{let n=e.name.getText();if(e.initializer){let i;i=r.isStringLiteral(e.initializer)?`"${e.initializer.text}"`:r.isNumericLiteral(e.initializer)?e.initializer.text:e.initializer.getText(),t.push(`${n} = ${i}`)}else t.push(n)}),`{ ${t.join(`, `)} }`}function T(e){if(e.getFlags()&(r.default.TypeFlags.StringLike|r.default.TypeFlags.NumberLike|r.default.TypeFlags.BooleanLike|r.default.TypeFlags.ESSymbolLike|r.default.TypeFlags.Void|r.default.TypeFlags.Undefined|r.default.TypeFlags.Null|r.default.TypeFlags.Any|r.default.TypeFlags.Unknown|r.default.TypeFlags.Never))return!1;let t=e.getSymbol();if(!t)return!0;let n=t.declarations?.[0];if(!n)return!0;let i=n.getSourceFile();return!(/lib\..*\.d\.ts$/.test(i.fileName)||i.fileName.startsWith(`/@vue/`))}var E=r.default.TypeFormatFlags.WriteArrowStyleSignature|r.default.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope|r.default.TypeFormatFlags.NoTruncation|r.default.TypeFormatFlags.UseFullyQualifiedType,D=class{checker;index;cache=new Set;result;constructor(e){this.program=e,this.checker=e.getTypeChecker()}get(e){if(this.index=this.program.getSourceFile(e),!this.index)throw Error(`Cannot find file ${e}`);let t=this.checker.getSymbolAtLocation(this.index);if(!t)throw Error(`Cannot find module ${e}`);this.result={components:{},functions:{},types:{}};let n=this.index.statements.find(e=>r.default.isExportAssignment(e));if(n){let e=this.checker.getTypeAtLocation(n.expression).getCallSignatures()[0];e&&this.exportFunction(`default`,e)}return this.exportModule(t),this.result}exportModule(e){let t=x(this.checker,e);for(let[e,n]of t.entries()){let t=this.checker.getTypeOfSymbol(n);if(t.symbol&&t.symbol.flags&r.default.SymbolFlags.Module){let e=t.symbol.exports?.get(`default`);e&&(t=this.checker.getTypeOfSymbol(e))}let i=t.symbol||t.aliasSymbol;if(i?.flags&r.default.SymbolFlags.Function){let e=this.checker.getTypeOfSymbol(i),t=this.checker.getSignaturesOfType(e,r.default.SignatureKind.Call)[0];if(t){let e=S(this.checker,i);this.exportFunction(e,t)}}else if(this.typeToString(t).includes(`DefineComponent<`))try{this.exportComponent(e,t)}catch(t){console.error(`Fail to export component ${e}`),console.error(t)}}}exportComponent(e,t){let n=t.getConstructSignatures()[0];if(!n)return;let r=this.checker.getReturnTypeOfSignature(n),i={},a=this.checker.getPropertyOfType(r,`$props`);if(a){let e=m(this.checker.getTypeOfSymbol(a),this);i.properties=e.props,i.emits=e.emits}let o=this.checker.getPropertyOfType(r,`$slots`);o&&(i.slots=p(this.checker.getTypeOfSymbol(o),this)),this.result.components[e]=h(i)}exportFunction(e,n){let r=d(n,this.checker),i=b(n,this),a=n.getParameters().map(e=>{let n=e.valueDeclaration??this.index,a=this.checker.getTypeOfSymbol(e);this.extractType(a,n);let o=e.valueDeclaration?.initializer?.getText();return t.l({default:o,description:r.params?.[e.name],name:e.name,optional:!!n.questionToken||o!==void 0||void 0,type:C(this.typeToString(a),i)})});if(a.some(e=>e.name?.startsWith(`__VLS_`))){let t={},r=a.findIndex(e=>e.name===`__VLS_props`),o=n.getParameters()[r];if(o){let e=m(this.checker.getTypeOfSymbol(o),this);t.properties=e.props,t.emits=e.emits,Object.values(t.properties).forEach(e=>{e.type=C(e.type,i)})}let s=a.findIndex(e=>e.name===`__VLS_slots`),c=n.getParameters()[s];c&&(t.slots=p(this.checker.getTypeOfSymbol(c),this),Object.values(t.slots).forEach(e=>{e.type=C(e.type,i)})),this.result.components[e]=h(t);return}let o=this.checker.getReturnTypeOfSignature(n);this.extractType(o),this.result.functions[e]=t.l({description:r.description,parameters:a,return:{description:r.returns,type:C(this.typeToString(o),i)}})}extractType(e,n=this.index){if(this.cache.has(e))return;this.cache.add(e);let i=e.symbol||e.aliasSymbol;if((e.isUnion()||e.isIntersection())&&!(i?.flags&r.default.SymbolFlags.Enum)&&e.types.forEach(e=>{this.extractType(e,n)}),i){if(this.checker.getFullyQualifiedName(i).includes(`/@vue/`))return;let n=S(this.checker,i);if(i.flags&r.default.SymbolFlags.Enum){let e=i.valueDeclaration||i.declarations?.[0];if(e&&r.default.isEnumDeclaration(e)){let n=S(this.checker,i);this.result.types[n]=t.l({...d(i,this.checker),type:w(e)})}return}if(i.flags&r.default.SymbolFlags.Namespace){let e=i;this.exportModule(e)}if(i.flags&r.default.SymbolFlags.TypeAlias){let t=i.valueDeclaration||i.declarations?.[0];if(!t)return;let a=Object.fromEntries((t?.typeParameters??[]).map(e=>{let t=`unknown`,n=e.default;if(n){let e=this.checker.getTypeFromTypeNode(n);t=this.typeToString(e)}let r=e.constraint;if(r){let e=this.checker.getTypeFromTypeNode(r);t=this.typeToString(e)}return[e.symbol.name,t]}));this.result.types[n]={...d(i,this.checker),type:C(this.typeToString(e,E|r.default.TypeFormatFlags.InTypeAlias),a)}}if(i.flags&r.default.SymbolFlags.Interface&&T(e)){let t=i.getDeclarations()[0];if(t){let a=this.checker.getPropertiesOfType(e),o={};a.forEach(e=>{let n=this.checker.getTypeOfSymbol(e);this.extractType(n,t),o[e.name]={...d(e,this.checker),optional:!!(e.flags&r.default.SymbolFlags.Optional)||void 0,type:this.typeToString(n)}}),this.result.types[n]={...d(i,this.checker),type:o}}}if(i.flags&r.default.SymbolFlags.TypeLiteral){let t=S(this.checker,e.aliasSymbol||e.symbol),n=this.checker.getPropertiesOfType(e),a={};if([`Promise`,`Partial`,`Pick`,`Omit`,`Required`].includes(t)){this.cache.delete(e),this.extractType(e.aliasTypeArguments[0]);return}if(e.aliasTypeArguments?.some(e=>!T(e)))return;n.forEach(e=>{let t=this.checker.getTypeOfSymbol(e);a[e.name]={...d(e,this.checker),optional:!!(e.flags&r.default.SymbolFlags.Optional),type:this.typeToString(t)}}),t!==`__type`&&(this.result.types[t]={...d(i,this.checker),type:a})}}if(e.flags&r.default.TypeFlags.Object){let t=e;if(T(e)&&this.checker.getPropertiesOfType(e).forEach(e=>{let t=this.checker.getTypeOfSymbol(e);this.extractType(t,n)}),t.objectFlags&r.default.ObjectFlags.Reference){let e=t;this.checker.getTypeArguments(e).forEach(e=>{this.extractType(e,n)})}}}typeToString(e,t=E){return this.checker.typeToString(e,void 0,t)}};function O(e,n=`unknown`){let r={components:{},functions:{},types:{}};for(let[t,n]of Object.entries(e.types))r.types[t]=i(n,t);for(let[t,n]of Object.entries(e.functions))r.functions[t]=a(n,t);for(let[t,n]of Object.entries(e.components))r.components[t]=o(n,t);return r;function i(e,n=``){if(typeof e.type==`string`){if(e.type===`{}`)return t.i.void();let r={...s(t.c(e.type)),...t.l({description:e.description,name:n?.split(`.`).pop()||void 0,optional:e.optional})};if(e.default)switch(r.type){case t.r.boolean:r.default=e.default===`true`;break;case t.r.number:r.default=Number(e.default);break;case t.r.string:r.default=e.default;break}return r.type===t.r.object&&!Object.keys(r.properties).length&&(r.customizable=!0),r}else{let r=t.i.object(t.d(e.type,({key:e,value:t})=>i(t,e)),t.l({description:e.description,name:n?.split(`.`).pop(),optional:e.optional}));return Object.keys(r.properties).length||(r.customizable=!0),r}}function a(e,n=``){return{...t.l({description:e.description,name:n?.split(`.`).pop()}),parameters:(e.parameters??[]).map(e=>i(e,e.name)),return:i(e.return,`result`)}}function o(e,n=``){return{...t.l({name:n?.split(`.`).pop()}),emits:t.d(e.emits,({value:e})=>i(e)),models:t.d(e.models,({value:e})=>i(e)),properties:t.d(e.properties,({key:e,value:t})=>i(t,e)),slots:t.d(e.slots,({value:e})=>i(e))}}function s(r,i=``){return t.s(r,({schema:e})=>{if(e.type===t.r.interface)return{...a(e.className,i),description:e.description,name:e.name,optional:e.optional}});function a(r,i=``){let a=`${i}${r}`;for(;!e.types[a]&&a.indexOf(`.`)!==-1;)a=a.substring(a.indexOf(`.`)+1);return e.types[a]?t.i.type([`packages`,n,...a.split(`.`)]):t.i.interface(r)}}}function k(e){for(;;){let t=i.join(e,`tsconfig.json`);if(a.existsSync(t))return t;let n=i.dirname(e);if(n===e)return;e=n}}function A(e){let t=r.readConfigFile(e,r.sys.readFile);if(t.error)throw Error(`Failed to read tsconfig.json: ${t.error.messageText}`);return r.parseJsonConfigFileContent(t.config,r.sys,i.dirname(e))}function j(e,t){let n=i.join(process.cwd(),`__temp__.ts`),a=r.createCompilerHost(t),o=r.resolveModuleName(e,n,t,a);if(o.resolvedModule)return o.resolvedModule.resolvedFileName}function M(e){let t=k(e);if(!t)throw Error(`Could not find tsconfig.json for: ${e}`);let n=A(t).options,i=j(e,n);if(!i)throw Error(`Could not resolve module: ${e}`);let a=r.createCompilerHost(n),o=r.createProgram({host:a,options:n,rootNames:[i]}),s=o.getSourceFile(i);if(!s)throw Error(`Could not get source file for: ${i}`);return{program:o,sourceFile:s}}var N=n.default.promises;async function P(e,t){let n=e.split(`/`).pop().split(`.`)[0],{program:r,sourceFile:i}=M(e),a=O(new D(r).get(i.fileName),n);if(a.components.default){let r=u(a,{name:n,path:e});await N.mkdir(t.split(`/`).slice(0,-1).join(`/`),{recursive:!0}),await N.writeFile(t,r)}}exports.CTypeExport=D,exports.extractFile=P,exports.generateNodes=O,exports.getSourceFile=M;
|