slicejs-cli 3.6.6 → 3.7.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/LICENSE +21 -21
- package/README.md +225 -225
- package/client.js +740 -740
- package/commands/Print.js +163 -163
- package/commands/Validations.js +92 -92
- package/commands/build/build.js +40 -40
- package/commands/buildProduction/buildProduction.js +577 -577
- package/commands/bundle/bundle.js +236 -236
- package/commands/createComponent/VisualComponentTemplate.js +55 -55
- package/commands/createComponent/createComponent.js +128 -128
- package/commands/deleteComponent/deleteComponent.js +81 -81
- package/commands/doctor/doctor.js +516 -516
- package/commands/getComponent/getComponent.js +695 -695
- package/commands/init/init.js +475 -473
- package/commands/listComponents/listComponents.js +172 -172
- package/commands/startServer/startServer.js +240 -240
- package/commands/startServer/watchServer.js +66 -66
- package/commands/types/types.js +974 -583
- package/commands/utils/LocalCliDelegation.js +53 -53
- package/commands/utils/PackageManager.js +148 -148
- package/commands/utils/PathHelper.js +75 -75
- package/commands/utils/VersionChecker.js +169 -169
- package/commands/utils/bundling/BundleGenerator.js +2525 -2525
- package/commands/utils/bundling/DependencyAnalyzer.js +941 -933
- package/commands/utils/loadConfig.js +31 -31
- package/commands/utils/sliceScripts.js +48 -48
- package/commands/utils/updateManager.js +471 -471
- package/package.json +71 -71
package/commands/types/types.js
CHANGED
|
@@ -1,583 +1,974 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { parse } from '@babel/parser';
|
|
4
|
-
import traverse from '@babel/traverse';
|
|
5
|
-
|
|
6
|
-
import Print from '../Print.js';
|
|
7
|
-
import { getConfigPath, getComponentsJsPath, joinRoot } from '../utils/PathHelper.js';
|
|
8
|
-
|
|
9
|
-
const TYPE_MAP = {
|
|
10
|
-
string: 'string',
|
|
11
|
-
number: 'number',
|
|
12
|
-
boolean: 'boolean',
|
|
13
|
-
object: 'Record<string, unknown>',
|
|
14
|
-
array: 'unknown[]',
|
|
15
|
-
function: '(...args: unknown[]) => unknown',
|
|
16
|
-
any: 'unknown'
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const literalValueFromAst = (node) => {
|
|
20
|
-
if (!node) return undefined;
|
|
21
|
-
if (node.type === 'StringLiteral' || node.type === 'NumericLiteral' || node.type === 'BooleanLiteral') {
|
|
22
|
-
return node.value;
|
|
23
|
-
}
|
|
24
|
-
if (node.type === 'NullLiteral') {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
return undefined;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const keyNameFromAst = (keyNode) => {
|
|
31
|
-
if (!keyNode) return null;
|
|
32
|
-
if (keyNode.type === 'Identifier') return keyNode.name;
|
|
33
|
-
if (keyNode.type === 'StringLiteral') return keyNode.value;
|
|
34
|
-
return null;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const astNodeToValue = (node) => {
|
|
38
|
-
if (!node) return undefined;
|
|
39
|
-
|
|
40
|
-
const literal = literalValueFromAst(node);
|
|
41
|
-
if (literal !== undefined || (node && node.type === 'NullLiteral')) {
|
|
42
|
-
return literal;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (node.type === 'ArrayExpression') {
|
|
46
|
-
return (node.elements || [])
|
|
47
|
-
.map((element) => astNodeToValue(element))
|
|
48
|
-
.filter((value) => value !== undefined);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (node.type === 'ObjectExpression') {
|
|
52
|
-
const out = {};
|
|
53
|
-
for (const property of node.properties || []) {
|
|
54
|
-
if (property.type !== 'ObjectProperty') continue;
|
|
55
|
-
const key = keyNameFromAst(property.key);
|
|
56
|
-
if (!key) continue;
|
|
57
|
-
const value = astNodeToValue(property.value);
|
|
58
|
-
if (value !== undefined) {
|
|
59
|
-
out[key] = value;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return out;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return undefined;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const normalizePropConfig = (rawConfig) => {
|
|
69
|
-
if (!rawConfig || typeof rawConfig !== 'object' || Array.isArray(rawConfig)) {
|
|
70
|
-
return { type: 'any', required: false };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const config = {
|
|
74
|
-
type: typeof rawConfig.type === 'string' ? rawConfig.type.toLowerCase() : 'any',
|
|
75
|
-
required: rawConfig.required === true
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
if (Array.isArray(rawConfig.allowedValues) && rawConfig.allowedValues.length > 0) {
|
|
79
|
-
config.allowedValues = rawConfig.allowedValues;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (rawConfig.schema && typeof rawConfig.schema === 'object' && !Array.isArray(rawConfig.schema)) {
|
|
83
|
-
const schema = {};
|
|
84
|
-
for (const [name, nestedRaw] of Object.entries(rawConfig.schema)) {
|
|
85
|
-
schema[name] = normalizePropConfig(nestedRaw);
|
|
86
|
-
}
|
|
87
|
-
config.schema = schema;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (rawConfig.items && typeof rawConfig.items === 'object' && !Array.isArray(rawConfig.items)) {
|
|
91
|
-
config.items = normalizePropConfig(rawConfig.items);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return config;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const extractStaticPropsFromObjectExpression = (objectExpressionNode) => {
|
|
98
|
-
const raw = astNodeToValue(objectExpressionNode);
|
|
99
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
100
|
-
|
|
101
|
-
const props = {};
|
|
102
|
-
for (const [propName, rawConfig] of Object.entries(raw)) {
|
|
103
|
-
props[propName] = normalizePropConfig(rawConfig);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return Object.keys(props).length > 0 ? props : null;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (!(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
parsed
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { parse } from '@babel/parser';
|
|
4
|
+
import traverse from '@babel/traverse';
|
|
5
|
+
|
|
6
|
+
import Print from '../Print.js';
|
|
7
|
+
import { getConfigPath, getComponentsJsPath, joinRoot } from '../utils/PathHelper.js';
|
|
8
|
+
|
|
9
|
+
const TYPE_MAP = {
|
|
10
|
+
string: 'string',
|
|
11
|
+
number: 'number',
|
|
12
|
+
boolean: 'boolean',
|
|
13
|
+
object: 'Record<string, unknown>',
|
|
14
|
+
array: 'unknown[]',
|
|
15
|
+
function: '(...args: unknown[]) => unknown',
|
|
16
|
+
any: 'unknown'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const literalValueFromAst = (node) => {
|
|
20
|
+
if (!node) return undefined;
|
|
21
|
+
if (node.type === 'StringLiteral' || node.type === 'NumericLiteral' || node.type === 'BooleanLiteral') {
|
|
22
|
+
return node.value;
|
|
23
|
+
}
|
|
24
|
+
if (node.type === 'NullLiteral') {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const keyNameFromAst = (keyNode) => {
|
|
31
|
+
if (!keyNode) return null;
|
|
32
|
+
if (keyNode.type === 'Identifier') return keyNode.name;
|
|
33
|
+
if (keyNode.type === 'StringLiteral') return keyNode.value;
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const astNodeToValue = (node) => {
|
|
38
|
+
if (!node) return undefined;
|
|
39
|
+
|
|
40
|
+
const literal = literalValueFromAst(node);
|
|
41
|
+
if (literal !== undefined || (node && node.type === 'NullLiteral')) {
|
|
42
|
+
return literal;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (node.type === 'ArrayExpression') {
|
|
46
|
+
return (node.elements || [])
|
|
47
|
+
.map((element) => astNodeToValue(element))
|
|
48
|
+
.filter((value) => value !== undefined);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (node.type === 'ObjectExpression') {
|
|
52
|
+
const out = {};
|
|
53
|
+
for (const property of node.properties || []) {
|
|
54
|
+
if (property.type !== 'ObjectProperty') continue;
|
|
55
|
+
const key = keyNameFromAst(property.key);
|
|
56
|
+
if (!key) continue;
|
|
57
|
+
const value = astNodeToValue(property.value);
|
|
58
|
+
if (value !== undefined) {
|
|
59
|
+
out[key] = value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return undefined;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const normalizePropConfig = (rawConfig) => {
|
|
69
|
+
if (!rawConfig || typeof rawConfig !== 'object' || Array.isArray(rawConfig)) {
|
|
70
|
+
return { type: 'any', required: false };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const config = {
|
|
74
|
+
type: typeof rawConfig.type === 'string' ? rawConfig.type.toLowerCase() : 'any',
|
|
75
|
+
required: rawConfig.required === true
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (Array.isArray(rawConfig.allowedValues) && rawConfig.allowedValues.length > 0) {
|
|
79
|
+
config.allowedValues = rawConfig.allowedValues;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (rawConfig.schema && typeof rawConfig.schema === 'object' && !Array.isArray(rawConfig.schema)) {
|
|
83
|
+
const schema = {};
|
|
84
|
+
for (const [name, nestedRaw] of Object.entries(rawConfig.schema)) {
|
|
85
|
+
schema[name] = normalizePropConfig(nestedRaw);
|
|
86
|
+
}
|
|
87
|
+
config.schema = schema;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (rawConfig.items && typeof rawConfig.items === 'object' && !Array.isArray(rawConfig.items)) {
|
|
91
|
+
config.items = normalizePropConfig(rawConfig.items);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return config;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const extractStaticPropsFromObjectExpression = (objectExpressionNode) => {
|
|
98
|
+
const raw = astNodeToValue(objectExpressionNode);
|
|
99
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
|
|
100
|
+
|
|
101
|
+
const props = {};
|
|
102
|
+
for (const [propName, rawConfig] of Object.entries(raw)) {
|
|
103
|
+
props[propName] = normalizePropConfig(rawConfig);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return Object.keys(props).length > 0 ? props : null;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// ============================================================
|
|
110
|
+
// Event registry scanning (slice.events.register(...) call sites)
|
|
111
|
+
// ============================================================
|
|
112
|
+
|
|
113
|
+
const PAYLOAD_TYPE_MAP = {
|
|
114
|
+
string: 'string',
|
|
115
|
+
number: 'number',
|
|
116
|
+
boolean: 'boolean',
|
|
117
|
+
object: 'Record<string, unknown>',
|
|
118
|
+
array: 'unknown[]',
|
|
119
|
+
function: '(...args: unknown[]) => unknown',
|
|
120
|
+
any: 'unknown'
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// Translate a payload mini-schema into a TS type.
|
|
124
|
+
// - null/undefined => 'void'
|
|
125
|
+
// - 'string' (a scalar) => 'string'
|
|
126
|
+
// - { id: 'number', ... } => '{ id: number; ... }'
|
|
127
|
+
// - field value may also be { type: 'number' } (long form)
|
|
128
|
+
const payloadToTs = (payload) => {
|
|
129
|
+
if (payload === null || payload === undefined) return 'void';
|
|
130
|
+
if (typeof payload === 'string') return PAYLOAD_TYPE_MAP[payload.toLowerCase()] || 'unknown';
|
|
131
|
+
if (typeof payload === 'object' && !Array.isArray(payload)) {
|
|
132
|
+
const inner = Object.entries(payload)
|
|
133
|
+
.map(([key, value]) => {
|
|
134
|
+
let tsType = 'unknown';
|
|
135
|
+
if (typeof value === 'string') {
|
|
136
|
+
tsType = PAYLOAD_TYPE_MAP[value.toLowerCase()] || 'unknown';
|
|
137
|
+
} else if (value && typeof value === 'object' && typeof value.type === 'string') {
|
|
138
|
+
tsType = PAYLOAD_TYPE_MAP[value.type.toLowerCase()] || 'unknown';
|
|
139
|
+
}
|
|
140
|
+
return `${key}: ${tsType}`;
|
|
141
|
+
})
|
|
142
|
+
.join('; ');
|
|
143
|
+
return inner.length > 0 ? `{ ${inner} }` : 'Record<string, unknown>';
|
|
144
|
+
}
|
|
145
|
+
return 'unknown';
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const parseModule = (source, filePath) => {
|
|
149
|
+
try {
|
|
150
|
+
return parse(source, { sourceType: 'module', plugins: ['classProperties'] });
|
|
151
|
+
} catch (parseError) {
|
|
152
|
+
const loc = parseError.loc ? ` at line ${parseError.loc.line}, column ${parseError.loc.column}` : '';
|
|
153
|
+
Print.warning(`Parse error in ${filePath || 'unknown file'}${loc}: ${parseError.message}`);
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// Matches `<x>.events.register(...)` — covers slice.events, this.events (bind), window.slice.events.
|
|
159
|
+
const isEventsRegisterCallee = (callee) => {
|
|
160
|
+
return (
|
|
161
|
+
callee &&
|
|
162
|
+
callee.type === 'MemberExpression' &&
|
|
163
|
+
keyNameFromAst(callee.property) === 'register' &&
|
|
164
|
+
callee.object &&
|
|
165
|
+
callee.object.type === 'MemberExpression' &&
|
|
166
|
+
keyNameFromAst(callee.object.property) === 'events'
|
|
167
|
+
);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// Resolve an exported object literal from a module file (export const NAME = {...} / export default {...}).
|
|
171
|
+
const resolveExportedObject = async (modulePath, exportName) => {
|
|
172
|
+
if (!(await fs.pathExists(modulePath))) return null;
|
|
173
|
+
let source;
|
|
174
|
+
try {
|
|
175
|
+
source = await fs.readFile(modulePath, 'utf8');
|
|
176
|
+
} catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const ast = parseModule(source, modulePath);
|
|
180
|
+
if (!ast) return null;
|
|
181
|
+
|
|
182
|
+
let found = null;
|
|
183
|
+
traverse.default(ast, {
|
|
184
|
+
ExportDefaultDeclaration(pathRef) {
|
|
185
|
+
if (exportName !== 'default') return;
|
|
186
|
+
const decl = pathRef.node.declaration;
|
|
187
|
+
if (decl && decl.type === 'ObjectExpression') found = decl;
|
|
188
|
+
},
|
|
189
|
+
ExportNamedDeclaration(pathRef) {
|
|
190
|
+
const decl = pathRef.node.declaration;
|
|
191
|
+
if (decl && decl.type === 'VariableDeclaration') {
|
|
192
|
+
for (const d of decl.declarations) {
|
|
193
|
+
if (keyNameFromAst(d.id) === exportName && d.init && d.init.type === 'ObjectExpression') {
|
|
194
|
+
found = d.init;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
return found ? astNodeToValue(found) : null;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// Resolve a relative import specifier to an absolute .js file path.
|
|
205
|
+
const resolveRelativeModule = async (fromFile, specifier) => {
|
|
206
|
+
if (!specifier.startsWith('.')) return null; // bare imports are not followed
|
|
207
|
+
const base = path.resolve(path.dirname(fromFile), specifier);
|
|
208
|
+
const candidates = [base, `${base}.js`, path.join(base, 'index.js')];
|
|
209
|
+
for (const candidate of candidates) {
|
|
210
|
+
if (await fs.pathExists(candidate) && (await fs.stat(candidate)).isFile()) return candidate;
|
|
211
|
+
}
|
|
212
|
+
return null;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const mergeCatalog = (registry, catalog, prefix = '') => {
|
|
216
|
+
if (!catalog || typeof catalog !== 'object' || Array.isArray(catalog)) return;
|
|
217
|
+
for (const [key, definition] of Object.entries(catalog)) {
|
|
218
|
+
const eventName = `${prefix}${key}`;
|
|
219
|
+
const payload =
|
|
220
|
+
definition && typeof definition === 'object' && !Array.isArray(definition)
|
|
221
|
+
? definition.payload ?? null
|
|
222
|
+
: null;
|
|
223
|
+
registry[eventName] = { payload };
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// Scan src/**/*.js for slice.events.register(<catalog>) calls and build the event registry.
|
|
228
|
+
const collectEventRegistry = async ({ projectRoot }) => {
|
|
229
|
+
const srcDir = joinRoot(projectRoot, 'src');
|
|
230
|
+
const files = await collectJavaScriptFiles(srcDir);
|
|
231
|
+
const registry = {};
|
|
232
|
+
|
|
233
|
+
for (const file of files) {
|
|
234
|
+
let source;
|
|
235
|
+
try {
|
|
236
|
+
source = await fs.readFile(file, 'utf8');
|
|
237
|
+
} catch {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (!source.includes('.events.register(')) continue; // cheap prefilter
|
|
241
|
+
|
|
242
|
+
const ast = parseModule(source, file);
|
|
243
|
+
if (!ast) continue;
|
|
244
|
+
|
|
245
|
+
// Collect local object-literal consts and import bindings up front.
|
|
246
|
+
const localObjects = new Map(); // name -> ObjectExpression node
|
|
247
|
+
const imports = new Map(); // localName -> { source, imported }
|
|
248
|
+
traverse.default(ast, {
|
|
249
|
+
VariableDeclarator(pathRef) {
|
|
250
|
+
const node = pathRef.node;
|
|
251
|
+
if (node.id?.type === 'Identifier' && node.init?.type === 'ObjectExpression') {
|
|
252
|
+
localObjects.set(node.id.name, node.init);
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
ImportDeclaration(pathRef) {
|
|
256
|
+
const src = pathRef.node.source?.value;
|
|
257
|
+
for (const spec of pathRef.node.specifiers || []) {
|
|
258
|
+
if (spec.type === 'ImportDefaultSpecifier') {
|
|
259
|
+
imports.set(spec.local.name, { source: src, imported: 'default' });
|
|
260
|
+
} else if (spec.type === 'ImportSpecifier') {
|
|
261
|
+
imports.set(spec.local.name, { source: src, imported: keyNameFromAst(spec.imported) });
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// Find the register() call sites and capture their arguments. Supports both
|
|
268
|
+
// register(catalog) and register('namespace', catalog).
|
|
269
|
+
const pendingCalls = [];
|
|
270
|
+
traverse.default(ast, {
|
|
271
|
+
CallExpression(pathRef) {
|
|
272
|
+
if (!isEventsRegisterCallee(pathRef.node.callee)) return;
|
|
273
|
+
pendingCalls.push(pathRef.node.arguments);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Resolve a catalog arg node to a plain object (inline literal, local const, or import).
|
|
278
|
+
const resolveCatalogArg = async (arg) => {
|
|
279
|
+
if (!arg) return null;
|
|
280
|
+
if (arg.type === 'ObjectExpression') return astNodeToValue(arg);
|
|
281
|
+
if (arg.type === 'Identifier') {
|
|
282
|
+
if (localObjects.has(arg.name)) return astNodeToValue(localObjects.get(arg.name));
|
|
283
|
+
if (imports.has(arg.name)) {
|
|
284
|
+
const { source: importSource, imported } = imports.get(arg.name);
|
|
285
|
+
const modulePath = await resolveRelativeModule(file, importSource);
|
|
286
|
+
if (modulePath) return resolveExportedObject(modulePath, imported);
|
|
287
|
+
Print.warning(`Could not resolve event catalog import "${arg.name}" from "${importSource}" in ${file}`);
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
Print.warning(`slice.events.register(${arg.name}) in ${file}: argument is not a literal/imported object — skipped for typing.`);
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
Print.warning(`slice.events.register(...) in ${file}: argument is not an object literal — skipped for typing.`);
|
|
294
|
+
return null;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
for (const args of pendingCalls) {
|
|
298
|
+
let prefix = '';
|
|
299
|
+
let catalogArg = args[0];
|
|
300
|
+
// register('namespace', catalog) — first arg is a string literal.
|
|
301
|
+
if (args[0] && args[0].type === 'StringLiteral') {
|
|
302
|
+
const ns = String(args[0].value).trim();
|
|
303
|
+
prefix = ns.endsWith(':') ? ns : `${ns}:`;
|
|
304
|
+
catalogArg = args[1];
|
|
305
|
+
}
|
|
306
|
+
const catalog = await resolveCatalogArg(catalogArg);
|
|
307
|
+
mergeCatalog(registry, catalog, prefix);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return registry;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// Matches `<x>.events.<method>(...)` — covers slice.events / this.events (bind) / window.slice.events.
|
|
315
|
+
const isEventsMethodCallee = (callee, methods) => {
|
|
316
|
+
return (
|
|
317
|
+
callee &&
|
|
318
|
+
callee.type === 'MemberExpression' &&
|
|
319
|
+
methods.includes(keyNameFromAst(callee.property)) &&
|
|
320
|
+
callee.object &&
|
|
321
|
+
callee.object.type === 'MemberExpression' &&
|
|
322
|
+
keyNameFromAst(callee.object.property) === 'events'
|
|
323
|
+
);
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
// Nearest enclosing class name for a call site (the component/service that emits/listens).
|
|
327
|
+
const enclosingClassName = (pathRef) => {
|
|
328
|
+
const classPath = pathRef.findParent((p) => p.isClassDeclaration() || p.isClassExpression());
|
|
329
|
+
return classPath?.node?.id?.name || null;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// Static pub/sub graph: scan emit()/subscribe() call sites so emitters/listeners are
|
|
333
|
+
// documented WITHOUT executing the code (complements the observational runtime tracing).
|
|
334
|
+
// Returns { events: { name: { emitters:[], listeners:[] } }, dynamic: { emitters:[], listeners:[] } }.
|
|
335
|
+
const collectEventGraph = async ({ projectRoot }) => {
|
|
336
|
+
const srcDir = joinRoot(projectRoot, 'src');
|
|
337
|
+
const files = await collectJavaScriptFiles(srcDir);
|
|
338
|
+
const events = {};
|
|
339
|
+
const dynamic = { emitters: [], listeners: [] };
|
|
340
|
+
|
|
341
|
+
const bucketFor = (eventName, kind) => {
|
|
342
|
+
if (!events[eventName]) events[eventName] = { emitters: [], listeners: [] };
|
|
343
|
+
return events[eventName][kind];
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
for (const file of files) {
|
|
347
|
+
let source;
|
|
348
|
+
try {
|
|
349
|
+
source = await fs.readFile(file, 'utf8');
|
|
350
|
+
} catch {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (!source.includes('.events.emit(') && !source.includes('.events.subscribe(') && !source.includes('.events.subscribeOnce(')) {
|
|
354
|
+
continue; // cheap prefilter
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const ast = parseModule(source, file);
|
|
358
|
+
if (!ast) continue;
|
|
359
|
+
|
|
360
|
+
const relFile = path.relative(projectRoot, file).replace(/\\/g, '/');
|
|
361
|
+
|
|
362
|
+
traverse.default(ast, {
|
|
363
|
+
CallExpression(pathRef) {
|
|
364
|
+
const callee = pathRef.node.callee;
|
|
365
|
+
let kind = null;
|
|
366
|
+
if (isEventsMethodCallee(callee, ['emit'])) kind = 'emitters';
|
|
367
|
+
else if (isEventsMethodCallee(callee, ['subscribe', 'subscribeOnce'])) kind = 'listeners';
|
|
368
|
+
if (!kind) return;
|
|
369
|
+
|
|
370
|
+
const site = {
|
|
371
|
+
file: relFile,
|
|
372
|
+
line: pathRef.node.loc?.start?.line || 0,
|
|
373
|
+
component: enclosingClassName(pathRef)
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const nameArg = pathRef.node.arguments[0];
|
|
377
|
+
if (nameArg && nameArg.type === 'StringLiteral') {
|
|
378
|
+
bucketFor(nameArg.value, kind).push(site);
|
|
379
|
+
} else {
|
|
380
|
+
dynamic[kind].push(site); // computed event name — can't be resolved statically
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return { events, dynamic };
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const sortKeys = (obj) => {
|
|
390
|
+
return Object.keys(obj)
|
|
391
|
+
.sort((a, b) => a.localeCompare(b))
|
|
392
|
+
.reduce((acc, key) => {
|
|
393
|
+
acc[key] = obj[key];
|
|
394
|
+
return acc;
|
|
395
|
+
}, {});
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
const parseComponentsRegistry = (content, filePath) => {
|
|
399
|
+
const match = content.match(/const components = ({[\s\S]*?});/);
|
|
400
|
+
if (!match) {
|
|
401
|
+
throw new Error(`Invalid format in ${filePath}. Expected: const components = { ... };`);
|
|
402
|
+
}
|
|
403
|
+
try {
|
|
404
|
+
return JSON.parse(match[1]);
|
|
405
|
+
} catch (parseError) {
|
|
406
|
+
throw new Error(`Failed to parse components registry in ${filePath}: ${parseError.message}`);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
const extractStaticPropsFromSource = (source, filePath) => {
|
|
411
|
+
let ast;
|
|
412
|
+
try {
|
|
413
|
+
ast = parse(source, {
|
|
414
|
+
sourceType: 'module',
|
|
415
|
+
plugins: ['classProperties']
|
|
416
|
+
});
|
|
417
|
+
} catch (parseError) {
|
|
418
|
+
const sourceDesc = filePath || 'unknown file';
|
|
419
|
+
const loc = parseError.loc ? ` at line ${parseError.loc.line}, column ${parseError.loc.column}` : '';
|
|
420
|
+
Print.warning(`Parse error in ${sourceDesc}${loc}: ${parseError.message}`);
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
let staticPropsObject = null;
|
|
425
|
+
traverse.default(ast, {
|
|
426
|
+
ClassProperty(pathRef) {
|
|
427
|
+
const node = pathRef.node;
|
|
428
|
+
if (!node.static || !node.key || keyNameFromAst(node.key) !== 'props') return;
|
|
429
|
+
if (node.value && node.value.type === 'ObjectExpression') {
|
|
430
|
+
staticPropsObject = node.value;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
if (!staticPropsObject) return null;
|
|
436
|
+
return extractStaticPropsFromObjectExpression(staticPropsObject);
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
const typeFromProp = (propMeta) => {
|
|
440
|
+
if (propMeta.type === 'object' && propMeta.schema && typeof propMeta.schema === 'object') {
|
|
441
|
+
const schemaEntries = Object.entries(sortKeys(propMeta.schema));
|
|
442
|
+
const inner = schemaEntries
|
|
443
|
+
.map(([name, meta]) => {
|
|
444
|
+
const optionalMark = meta.required ? '' : '?';
|
|
445
|
+
return `${name}${optionalMark}: ${typeFromProp(meta)};`;
|
|
446
|
+
})
|
|
447
|
+
.join(' ');
|
|
448
|
+
return `{ ${inner} }`;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (propMeta.type === 'array' && propMeta.items && typeof propMeta.items === 'object') {
|
|
452
|
+
return `${typeFromProp(propMeta.items)}[]`;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const allowedValues = Array.isArray(propMeta.allowedValues) ? propMeta.allowedValues : [];
|
|
456
|
+
|
|
457
|
+
if (allowedValues.length > 0 && propMeta.type === 'string' && allowedValues.every((value) => typeof value === 'string')) {
|
|
458
|
+
return allowedValues.map((value) => `'${String(value).replace(/'/g, "\\'")}'`).join(' | ');
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (allowedValues.length > 0 && propMeta.type === 'number' && allowedValues.every((value) => typeof value === 'number' && Number.isFinite(value))) {
|
|
462
|
+
return allowedValues.join(' | ');
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return TYPE_MAP[propMeta.type] || 'unknown';
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const interfaceNameFor = (componentName) => `${componentName}Props`;
|
|
469
|
+
const DYNAMIC_FALLBACK_PROP = '__dynamicPropsFallback';
|
|
470
|
+
|
|
471
|
+
const DEFAULT_EDITOR_COMPILER_OPTIONS = {
|
|
472
|
+
allowJs: true,
|
|
473
|
+
checkJs: true,
|
|
474
|
+
strict: false,
|
|
475
|
+
noImplicitAny: false,
|
|
476
|
+
strictNullChecks: false,
|
|
477
|
+
maxNodeModuleJsDepth: 2
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
const DEFAULT_EDITOR_INCLUDE = ['src/Components/**/*.js', 'src/**/*.d.ts'];
|
|
481
|
+
const DEFAULT_EDITOR_EXCLUDE = ['node_modules', 'dist', 'src/libs/**', 'tests/**'];
|
|
482
|
+
const NOISY_INCLUDE_PATTERNS = new Set(['src/**/*.js', 'api/**/*.js', 'tests/**/*.js']);
|
|
483
|
+
|
|
484
|
+
const readPublicFolderExcludes = async (projectRoot) => {
|
|
485
|
+
const configPath = getConfigPath(import.meta.url, projectRoot);
|
|
486
|
+
if (!(await fs.pathExists(configPath))) return [];
|
|
487
|
+
|
|
488
|
+
try {
|
|
489
|
+
const raw = await fs.readFile(configPath, 'utf8');
|
|
490
|
+
const parsed = JSON.parse(raw);
|
|
491
|
+
const folders = Array.isArray(parsed?.publicFolders) ? parsed.publicFolders : [];
|
|
492
|
+
return folders
|
|
493
|
+
.map((folder) => String(folder || '').trim())
|
|
494
|
+
.filter(Boolean)
|
|
495
|
+
.map((folder) => folder.replace(/^[/\\]+/, ''))
|
|
496
|
+
.map((folder) => `src/${folder}/**`);
|
|
497
|
+
} catch {
|
|
498
|
+
return [];
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
const collectJavaScriptFiles = async (dirPath) => {
|
|
503
|
+
if (!(await fs.pathExists(dirPath))) return [];
|
|
504
|
+
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
505
|
+
const files = [];
|
|
506
|
+
|
|
507
|
+
for (const entry of entries) {
|
|
508
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
509
|
+
if (entry.isDirectory()) {
|
|
510
|
+
const nested = await collectJavaScriptFiles(fullPath);
|
|
511
|
+
files.push(...nested);
|
|
512
|
+
} else if (entry.isFile() && entry.name.toLowerCase().endsWith('.js')) {
|
|
513
|
+
files.push(fullPath);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return files;
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
const ensureNoCheckInPublicVendorFiles = async (projectRoot) => {
|
|
521
|
+
const configPath = getConfigPath(import.meta.url, projectRoot);
|
|
522
|
+
if (!(await fs.pathExists(configPath))) return { updatedFiles: 0, scannedFiles: 0 };
|
|
523
|
+
|
|
524
|
+
let parsed;
|
|
525
|
+
try {
|
|
526
|
+
parsed = JSON.parse(await fs.readFile(configPath, 'utf8'));
|
|
527
|
+
} catch {
|
|
528
|
+
return { updatedFiles: 0, scannedFiles: 0 };
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const publicFolders = Array.isArray(parsed?.publicFolders) ? parsed.publicFolders : [];
|
|
532
|
+
const candidateDirs = publicFolders
|
|
533
|
+
.map((folder) => String(folder || '').trim())
|
|
534
|
+
.filter(Boolean)
|
|
535
|
+
.map((folder) => folder.replace(/^[/\\]+/, ''))
|
|
536
|
+
.map((folder) => joinRoot(projectRoot, 'src', folder));
|
|
537
|
+
|
|
538
|
+
const uniqueDirs = Array.from(new Set(candidateDirs));
|
|
539
|
+
let scannedFiles = 0;
|
|
540
|
+
let updatedFiles = 0;
|
|
541
|
+
|
|
542
|
+
for (const dirPath of uniqueDirs) {
|
|
543
|
+
const jsFiles = await collectJavaScriptFiles(dirPath);
|
|
544
|
+
for (const filePath of jsFiles) {
|
|
545
|
+
scannedFiles += 1;
|
|
546
|
+
const raw = await fs.readFile(filePath, 'utf8');
|
|
547
|
+
if (raw.startsWith('// @ts-nocheck')) {
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
await fs.writeFile(filePath, `// @ts-nocheck\n${raw}`, 'utf8');
|
|
552
|
+
updatedFiles += 1;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
return { updatedFiles, scannedFiles };
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
const generateEventRegistryLines = (eventRegistry) => {
|
|
560
|
+
const events = sortKeys(eventRegistry || {});
|
|
561
|
+
const names = Object.keys(events);
|
|
562
|
+
if (names.length === 0) return [];
|
|
563
|
+
|
|
564
|
+
const lines = [];
|
|
565
|
+
lines.push('export interface SliceEventRegistry {');
|
|
566
|
+
for (const name of names) {
|
|
567
|
+
lines.push(` '${name}': ${payloadToTs(events[name].payload)};`);
|
|
568
|
+
}
|
|
569
|
+
lines.push('}');
|
|
570
|
+
lines.push('');
|
|
571
|
+
lines.push('type SliceEventCatalog = Record<string, { description?: string; payload?: unknown }>;');
|
|
572
|
+
lines.push('');
|
|
573
|
+
// Single conditional-type signatures (not overload pairs): for a KNOWN event');
|
|
574
|
+
lines.push('// name the payload is enforced; for any other (unknown / framework / dynamic');
|
|
575
|
+
lines.push('// context:* events) it stays permissive. A plain string-fallback overload');
|
|
576
|
+
lines.push('// would swallow wrong-payload calls and defeat the whole point.');
|
|
577
|
+
lines.push('type SliceEventData<K extends string> = K extends keyof SliceEventRegistry ? SliceEventRegistry[K] : unknown;');
|
|
578
|
+
lines.push('type SliceEventArgs<K extends string> = K extends keyof SliceEventRegistry');
|
|
579
|
+
lines.push(' ? (SliceEventRegistry[K] extends void ? [] : [SliceEventRegistry[K]])');
|
|
580
|
+
lines.push(' : unknown[];');
|
|
581
|
+
lines.push('');
|
|
582
|
+
lines.push('export interface SliceTypedEventBinding {');
|
|
583
|
+
lines.push(' subscribe<K extends string>(eventName: K, callback: (data: SliceEventData<K>) => void): string | null;');
|
|
584
|
+
lines.push(' subscribeOnce<K extends string>(eventName: K, callback: (data: SliceEventData<K>) => void): string | null;');
|
|
585
|
+
lines.push(' emit<K extends string>(eventName: K, ...data: SliceEventArgs<K>): void;');
|
|
586
|
+
lines.push(' register(namespace: string, catalog: SliceEventCatalog): unknown;');
|
|
587
|
+
lines.push(' register(catalog: SliceEventCatalog): unknown;');
|
|
588
|
+
lines.push('}');
|
|
589
|
+
lines.push('');
|
|
590
|
+
lines.push('export interface SliceTypedEventManager {');
|
|
591
|
+
lines.push(' init(): boolean;');
|
|
592
|
+
lines.push(' subscribe<K extends string>(eventName: K, callback: (data: SliceEventData<K>) => void, options?: { component?: HTMLElement }): string | null;');
|
|
593
|
+
lines.push(' subscribeOnce<K extends string>(eventName: K, callback: (data: SliceEventData<K>) => void, options?: { component?: HTMLElement }): string | null;');
|
|
594
|
+
lines.push(' unsubscribe(eventName: string, subscriptionId: string): boolean;');
|
|
595
|
+
lines.push(' emit<K extends string>(eventName: K, ...data: SliceEventArgs<K>): void;');
|
|
596
|
+
lines.push(' bind(component: HTMLElement): SliceTypedEventBinding | null;');
|
|
597
|
+
lines.push(' cleanupComponent(sliceId: string): number;');
|
|
598
|
+
lines.push(' hasSubscribers(eventName: string): boolean;');
|
|
599
|
+
lines.push(' subscriberCount(eventName: string): number;');
|
|
600
|
+
lines.push(' isDeclared(eventName: string): boolean;');
|
|
601
|
+
lines.push(' namespaceOf(eventName: string): string | null;');
|
|
602
|
+
lines.push(' register(namespace: string, catalog: SliceEventCatalog): SliceTypedEventManager;');
|
|
603
|
+
lines.push(' register(catalog: SliceEventCatalog): SliceTypedEventManager;');
|
|
604
|
+
lines.push(' clear(): void;');
|
|
605
|
+
lines.push('}');
|
|
606
|
+
lines.push('');
|
|
607
|
+
return lines;
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
const generateDeclarationContent = (componentPropsMap, eventRegistry = {}) => {
|
|
611
|
+
const componentsSorted = sortKeys(componentPropsMap);
|
|
612
|
+
const hasEvents = Object.keys(eventRegistry || {}).length > 0;
|
|
613
|
+
const lines = [];
|
|
614
|
+
|
|
615
|
+
lines.push('/* Auto-generated by slice types generate. Do not edit manually. */');
|
|
616
|
+
lines.push('');
|
|
617
|
+
|
|
618
|
+
for (const [componentName, props] of Object.entries(componentsSorted)) {
|
|
619
|
+
lines.push(`export interface ${interfaceNameFor(componentName)} {`);
|
|
620
|
+
lines.push(' [key: string]: unknown;');
|
|
621
|
+
const sortedProps = sortKeys(props);
|
|
622
|
+
const isDynamicFallback = Object.keys(sortedProps).length === 1 && sortedProps[DYNAMIC_FALLBACK_PROP];
|
|
623
|
+
if (!isDynamicFallback) {
|
|
624
|
+
for (const [propName, propMeta] of Object.entries(sortedProps)) {
|
|
625
|
+
const optionalMark = propMeta.required ? '' : '?';
|
|
626
|
+
lines.push(` ${propName}${optionalMark}: ${typeFromProp(propMeta)};`);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
lines.push('}');
|
|
630
|
+
lines.push('');
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
lines.push('export interface SliceComponentPropsMap {');
|
|
634
|
+
for (const componentName of Object.keys(componentsSorted)) {
|
|
635
|
+
lines.push(` ${componentName}: ${interfaceNameFor(componentName)};`);
|
|
636
|
+
}
|
|
637
|
+
lines.push('}');
|
|
638
|
+
lines.push('');
|
|
639
|
+
lines.push('export type SliceComponentName = keyof SliceComponentPropsMap;');
|
|
640
|
+
lines.push('export type SliceDynamicElement = HTMLElement & Record<string, any>;');
|
|
641
|
+
lines.push('');
|
|
642
|
+
if (hasEvents) {
|
|
643
|
+
lines.push(...generateEventRegistryLines(eventRegistry));
|
|
644
|
+
}
|
|
645
|
+
lines.push('declare global {');
|
|
646
|
+
// When typed events exist we declare slice with an index-signature interface so
|
|
647
|
+
// that explicit members (build, events) keep their precise type while dynamic
|
|
648
|
+
// access (slice.anything) stays `any` — `& Record<string, any>` would otherwise
|
|
649
|
+
// collapse slice.events to `any`.
|
|
650
|
+
lines.push(` const slice: SliceBuildApi${hasEvents ? '' : ' & Record<string, any>'};`);
|
|
651
|
+
lines.push('');
|
|
652
|
+
lines.push(' interface Event {');
|
|
653
|
+
lines.push(' detail: any;');
|
|
654
|
+
lines.push(' key: any;');
|
|
655
|
+
lines.push(' request: any;');
|
|
656
|
+
lines.push(' waitUntil: any;');
|
|
657
|
+
lines.push(' respondWith: any;');
|
|
658
|
+
lines.push(' target: any;');
|
|
659
|
+
lines.push(' currentTarget: any;');
|
|
660
|
+
lines.push(' }');
|
|
661
|
+
lines.push('');
|
|
662
|
+
lines.push(' interface Element {');
|
|
663
|
+
lines.push(' querySelector<E extends Element = HTMLElement>(selectors: string): E | null;');
|
|
664
|
+
lines.push(' querySelectorAll<E extends Element = HTMLElement>(selectors: string): NodeListOf<E>;');
|
|
665
|
+
lines.push(' }');
|
|
666
|
+
lines.push(' interface HTMLElement {');
|
|
667
|
+
lines.push(' [key: string]: any;');
|
|
668
|
+
lines.push(' }');
|
|
669
|
+
lines.push(' interface EventTarget {');
|
|
670
|
+
lines.push(' [key: string]: any;');
|
|
671
|
+
lines.push(' }');
|
|
672
|
+
lines.push('');
|
|
673
|
+
lines.push(' interface SliceBuildApi {');
|
|
674
|
+
if (hasEvents) {
|
|
675
|
+
lines.push(' [key: string]: any;');
|
|
676
|
+
}
|
|
677
|
+
lines.push(' build<K extends SliceComponentName>(');
|
|
678
|
+
lines.push(' name: K,');
|
|
679
|
+
lines.push(' props?: SliceComponentPropsMap[K]');
|
|
680
|
+
lines.push(' ): Promise<SliceDynamicElement | null>;');
|
|
681
|
+
if (hasEvents) {
|
|
682
|
+
lines.push(' events: SliceTypedEventManager;');
|
|
683
|
+
}
|
|
684
|
+
lines.push(' }');
|
|
685
|
+
lines.push('}');
|
|
686
|
+
lines.push('');
|
|
687
|
+
lines.push("declare module 'slicejs-web-framework' {");
|
|
688
|
+
lines.push(' interface SliceApi {');
|
|
689
|
+
lines.push(' build<K extends SliceComponentName>(');
|
|
690
|
+
lines.push(' name: K,');
|
|
691
|
+
lines.push(' props?: SliceComponentPropsMap[K]');
|
|
692
|
+
lines.push(' ): Promise<SliceDynamicElement | null>;');
|
|
693
|
+
lines.push(' getComponent<K extends SliceComponentName>(');
|
|
694
|
+
lines.push(' componentSliceId: K | `${K}-${string}`');
|
|
695
|
+
lines.push(' ): SliceDynamicElement | undefined;');
|
|
696
|
+
lines.push(' getComponent<T extends SliceDynamicElement = SliceDynamicElement>(');
|
|
697
|
+
lines.push(' componentSliceId: string');
|
|
698
|
+
lines.push(' ): T | undefined;');
|
|
699
|
+
if (hasEvents) {
|
|
700
|
+
lines.push(' events: SliceTypedEventManager;');
|
|
701
|
+
}
|
|
702
|
+
lines.push(' }');
|
|
703
|
+
lines.push('}');
|
|
704
|
+
lines.push('');
|
|
705
|
+
lines.push('export {};');
|
|
706
|
+
lines.push('');
|
|
707
|
+
|
|
708
|
+
return lines.join('\n');
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
const readCategoryPathFromConfig = async (configPath, category) => {
|
|
712
|
+
const raw = await fs.readFile(configPath, 'utf8');
|
|
713
|
+
const config = JSON.parse(raw);
|
|
714
|
+
const categoryEntry = config?.paths?.components?.[category];
|
|
715
|
+
if (!categoryEntry || !categoryEntry.path) {
|
|
716
|
+
return null;
|
|
717
|
+
}
|
|
718
|
+
return categoryEntry.path.replace(/^[/\\]+/, '');
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
const loadComponentStaticProps = async ({ projectRoot, registryMap }) => {
|
|
722
|
+
const configPath = getConfigPath(import.meta.url, projectRoot);
|
|
723
|
+
const categoryPathCache = new Map();
|
|
724
|
+
const componentPropsMap = {};
|
|
725
|
+
let skippedCount = 0;
|
|
726
|
+
let processedCount = 0;
|
|
727
|
+
|
|
728
|
+
for (const [componentName, category] of Object.entries(sortKeys(registryMap))) {
|
|
729
|
+
if (!categoryPathCache.has(category)) {
|
|
730
|
+
const categoryPath = await readCategoryPathFromConfig(configPath, category);
|
|
731
|
+
categoryPathCache.set(category, categoryPath);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
const categoryPath = categoryPathCache.get(category);
|
|
735
|
+
if (!categoryPath) {
|
|
736
|
+
skippedCount++;
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
const componentFile = joinRoot(projectRoot, 'src', categoryPath, componentName, `${componentName}.js`);
|
|
741
|
+
if (!(await fs.pathExists(componentFile))) {
|
|
742
|
+
skippedCount++;
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
let source;
|
|
747
|
+
try {
|
|
748
|
+
source = await fs.readFile(componentFile, 'utf8');
|
|
749
|
+
} catch (readError) {
|
|
750
|
+
Print.warning(`Cannot read ${componentFile}: ${readError.message}`);
|
|
751
|
+
skippedCount++;
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
const props = extractStaticPropsFromSource(source, componentFile);
|
|
756
|
+
if (props) {
|
|
757
|
+
componentPropsMap[componentName] = props;
|
|
758
|
+
processedCount++;
|
|
759
|
+
} else {
|
|
760
|
+
componentPropsMap[componentName] = { [DYNAMIC_FALLBACK_PROP]: { type: 'any', required: false } };
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
if (skippedCount > 0) {
|
|
765
|
+
Print.info(`Skipped ${skippedCount} component(s) with missing or unreadable files`);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
return componentPropsMap;
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
const generateTypesFile = async ({ projectRoot, outputPath }) => {
|
|
772
|
+
const registryPath = getComponentsJsPath(import.meta.url, projectRoot);
|
|
773
|
+
let registryContent;
|
|
774
|
+
try {
|
|
775
|
+
registryContent = await fs.readFile(registryPath, 'utf8');
|
|
776
|
+
} catch (readError) {
|
|
777
|
+
throw new Error(`Cannot read components registry at ${registryPath}: ${readError.message}`);
|
|
778
|
+
}
|
|
779
|
+
const registryMap = parseComponentsRegistry(registryContent, registryPath);
|
|
780
|
+
|
|
781
|
+
const componentPropsMap = await loadComponentStaticProps({ projectRoot, registryMap });
|
|
782
|
+
const eventRegistry = await collectEventRegistry({ projectRoot });
|
|
783
|
+
|
|
784
|
+
const declaration = generateDeclarationContent(componentPropsMap, eventRegistry);
|
|
785
|
+
await fs.ensureDir(path.dirname(outputPath));
|
|
786
|
+
await fs.writeFile(outputPath, declaration, 'utf8');
|
|
787
|
+
|
|
788
|
+
// Static pub/sub graph manifest (documentation): emitters/listeners by call site.
|
|
789
|
+
const eventGraph = await collectEventGraph({ projectRoot });
|
|
790
|
+
const manifest = buildEventManifest(eventRegistry, eventGraph);
|
|
791
|
+
const manifestPath = path.join(path.dirname(outputPath), 'slice-events.generated.js');
|
|
792
|
+
await fs.writeFile(manifestPath, generateEventManifestContent(manifest), 'utf8');
|
|
793
|
+
|
|
794
|
+
const siteCount = Object.values(eventGraph.events).reduce(
|
|
795
|
+
(sum, e) => sum + e.emitters.length + e.listeners.length,
|
|
796
|
+
0
|
|
797
|
+
);
|
|
798
|
+
|
|
799
|
+
return {
|
|
800
|
+
outputPath,
|
|
801
|
+
manifestPath,
|
|
802
|
+
componentsProcessed: Object.keys(componentPropsMap).length,
|
|
803
|
+
eventsProcessed: Object.keys(eventRegistry).length,
|
|
804
|
+
graphSites: siteCount
|
|
805
|
+
};
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
// Merge the declared registry (payloads) with the static graph (call sites) into one manifest.
|
|
809
|
+
const buildEventManifest = (registry, graph) => {
|
|
810
|
+
const names = new Set([...Object.keys(registry), ...Object.keys(graph.events)]);
|
|
811
|
+
const events = {};
|
|
812
|
+
for (const name of Array.from(names).sort((a, b) => a.localeCompare(b))) {
|
|
813
|
+
events[name] = {
|
|
814
|
+
payload: registry[name]?.payload ?? null,
|
|
815
|
+
emitters: graph.events[name]?.emitters || [],
|
|
816
|
+
listeners: graph.events[name]?.listeners || []
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
return { events, dynamic: graph.dynamic };
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
const generateEventManifestContent = (manifest) => {
|
|
823
|
+
return `/* Auto-generated by slice types generate. Do not edit manually. */\nexport default ${JSON.stringify(manifest, null, 2)};\n`;
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
const toPosixRelative = (projectRoot, targetPath) => {
|
|
827
|
+
const relative = path.relative(projectRoot, targetPath).replace(/\\/g, '/');
|
|
828
|
+
return relative;
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
const ensureEditorConfigForTypes = async ({ projectRoot, outputPath }) => {
|
|
832
|
+
try {
|
|
833
|
+
const tsconfigPath = joinRoot(projectRoot, 'tsconfig.json');
|
|
834
|
+
if (await fs.pathExists(tsconfigPath)) {
|
|
835
|
+
return { mode: 'tsconfig_exists', filePath: tsconfigPath, includeAdded: false };
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
const jsconfigPath = joinRoot(projectRoot, 'jsconfig.json');
|
|
839
|
+
const declarationGlob = (() => {
|
|
840
|
+
const relative = toPosixRelative(projectRoot, outputPath);
|
|
841
|
+
if (!relative) return 'src/**/*.d.ts';
|
|
842
|
+
const idx = relative.lastIndexOf('/');
|
|
843
|
+
if (idx === -1) return relative;
|
|
844
|
+
const dir = relative.slice(0, idx);
|
|
845
|
+
return `${dir}/**/*.d.ts`;
|
|
846
|
+
})();
|
|
847
|
+
|
|
848
|
+
const writeDefaultJsconfig = async () => {
|
|
849
|
+
const jsconfig = {
|
|
850
|
+
compilerOptions: { ...DEFAULT_EDITOR_COMPILER_OPTIONS },
|
|
851
|
+
include: [...DEFAULT_EDITOR_INCLUDE, declarationGlob],
|
|
852
|
+
exclude: [...DEFAULT_EDITOR_EXCLUDE]
|
|
853
|
+
};
|
|
854
|
+
await fs.writeFile(jsconfigPath, `${JSON.stringify(jsconfig, null, 2)}\n`, 'utf8');
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
if (!(await fs.pathExists(jsconfigPath))) {
|
|
858
|
+
await writeDefaultJsconfig();
|
|
859
|
+
return { mode: 'created_jsconfig', filePath: jsconfigPath, includeAdded: true };
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
let jsconfigRaw;
|
|
863
|
+
try {
|
|
864
|
+
jsconfigRaw = await fs.readFile(jsconfigPath, 'utf8');
|
|
865
|
+
} catch {
|
|
866
|
+
// Don't fail — fall back to writing the default options.
|
|
867
|
+
await writeDefaultJsconfig();
|
|
868
|
+
return { mode: 'reset_jsconfig', reason: 'unreadable', filePath: jsconfigPath, includeAdded: true };
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
let parsed;
|
|
872
|
+
try {
|
|
873
|
+
parsed = JSON.parse(jsconfigRaw);
|
|
874
|
+
} catch {
|
|
875
|
+
// The jsconfig was edited into invalid JSON (a typo, comments, trailing commas...).
|
|
876
|
+
// Don't fail — just write the default options so editor IntelliSense keeps working.
|
|
877
|
+
await writeDefaultJsconfig();
|
|
878
|
+
return { mode: 'reset_jsconfig', reason: 'invalid_json', filePath: jsconfigPath, includeAdded: true };
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
const include = Array.isArray(parsed.include) ? parsed.include : [];
|
|
882
|
+
const needsInclude = !include.includes(declarationGlob);
|
|
883
|
+
const hasAllDefaultInclude = DEFAULT_EDITOR_INCLUDE.every((entry) => include.includes(entry));
|
|
884
|
+
const hasNoisyInclude = include.some((entry) => NOISY_INCLUDE_PATTERNS.has(entry));
|
|
885
|
+
const exclude = Array.isArray(parsed.exclude) ? parsed.exclude : [];
|
|
886
|
+
const publicFolderExcludes = await readPublicFolderExcludes(projectRoot);
|
|
887
|
+
const desiredExcludes = Array.from(new Set([...DEFAULT_EDITOR_EXCLUDE, ...publicFolderExcludes]));
|
|
888
|
+
const hasAllDefaultExclude = desiredExcludes.every((entry) => exclude.includes(entry));
|
|
889
|
+
|
|
890
|
+
const compilerOptions = parsed && typeof parsed.compilerOptions === 'object' && parsed.compilerOptions !== null
|
|
891
|
+
? { ...parsed.compilerOptions }
|
|
892
|
+
: {};
|
|
893
|
+
|
|
894
|
+
let compilerOptionsChanged = false;
|
|
895
|
+
for (const [key, value] of Object.entries(DEFAULT_EDITOR_COMPILER_OPTIONS)) {
|
|
896
|
+
if (compilerOptions[key] === undefined) {
|
|
897
|
+
compilerOptions[key] = value;
|
|
898
|
+
compilerOptionsChanged = true;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
if (!needsInclude && !compilerOptionsChanged && hasAllDefaultInclude && hasAllDefaultExclude && !hasNoisyInclude) {
|
|
903
|
+
return { mode: 'jsconfig_already_has_include', filePath: jsconfigPath, includeAdded: false };
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
parsed.compilerOptions = compilerOptions;
|
|
907
|
+
parsed.include = needsInclude ? [...include, declarationGlob] : include;
|
|
908
|
+
const includeSet = new Set(
|
|
909
|
+
(Array.isArray(parsed.include) ? parsed.include : []).filter((entry) => !NOISY_INCLUDE_PATTERNS.has(entry))
|
|
910
|
+
);
|
|
911
|
+
DEFAULT_EDITOR_INCLUDE.forEach((entry) => includeSet.add(entry));
|
|
912
|
+
parsed.include = Array.from(includeSet);
|
|
913
|
+
|
|
914
|
+
const excludeSet = new Set(Array.isArray(parsed.exclude) ? parsed.exclude : []);
|
|
915
|
+
desiredExcludes.forEach((entry) => excludeSet.add(entry));
|
|
916
|
+
parsed.exclude = Array.from(excludeSet);
|
|
917
|
+
await fs.writeFile(jsconfigPath, `${JSON.stringify(parsed, null, 2)}\n`, 'utf8');
|
|
918
|
+
return { mode: 'updated_jsconfig', filePath: jsconfigPath, includeAdded: needsInclude };
|
|
919
|
+
} catch (error) {
|
|
920
|
+
return {
|
|
921
|
+
mode: 'editor_config_error',
|
|
922
|
+
filePath: projectRoot,
|
|
923
|
+
includeAdded: false,
|
|
924
|
+
errorMessage: error?.message || 'Unknown editor config setup error'
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
const runGenerateTypes = async ({ projectRoot, outputPath }) => {
|
|
930
|
+
const result = await generateTypesFile({ projectRoot, outputPath });
|
|
931
|
+
const editorConfig = await ensureEditorConfigForTypes({ projectRoot, outputPath });
|
|
932
|
+
const publicVendorSuppression = await ensureNoCheckInPublicVendorFiles(projectRoot);
|
|
933
|
+
Print.success(`Generated TypeScript declarations at ${result.outputPath}`);
|
|
934
|
+
Print.info(`Components with static props: ${result.componentsProcessed}`);
|
|
935
|
+
if (typeof result.eventsProcessed === 'number') {
|
|
936
|
+
Print.info(`Registered events typed: ${result.eventsProcessed}`);
|
|
937
|
+
}
|
|
938
|
+
if (result.manifestPath) {
|
|
939
|
+
Print.info(`Event graph manifest: ${toPosixRelative(projectRoot, result.manifestPath)} (${result.graphSites} call site(s))`);
|
|
940
|
+
}
|
|
941
|
+
if (editorConfig.mode === 'created_jsconfig') {
|
|
942
|
+
Print.info(`Created jsconfig.json and included declaration glob for editor IntelliSense.`);
|
|
943
|
+
} else if (editorConfig.mode === 'updated_jsconfig') {
|
|
944
|
+
Print.info(`Updated jsconfig.json include list for declaration IntelliSense.`);
|
|
945
|
+
} else if (editorConfig.mode === 'jsconfig_already_has_include') {
|
|
946
|
+
Print.info(`jsconfig.json already includes declaration glob. Editor IntelliSense should pick generated types.`);
|
|
947
|
+
} else if (editorConfig.mode === 'tsconfig_exists') {
|
|
948
|
+
Print.info(`tsconfig.json detected. Types declaration is generated; ensure include covers ${toPosixRelative(projectRoot, outputPath)}.`);
|
|
949
|
+
} else if (editorConfig.mode === 'reset_jsconfig') {
|
|
950
|
+
const why = editorConfig.reason === 'invalid_json' ? 'contained invalid JSON' : 'could not be read';
|
|
951
|
+
Print.warning(`jsconfig.json ${why}; wrote the default options so editor IntelliSense keeps working.`);
|
|
952
|
+
Print.info(`Review ${editorConfig.filePath} if you had custom settings there.`);
|
|
953
|
+
} else if (editorConfig.mode === 'editor_config_error') {
|
|
954
|
+
Print.warning(`Unexpected editor config setup error: ${editorConfig.errorMessage}`);
|
|
955
|
+
}
|
|
956
|
+
if (publicVendorSuppression.updatedFiles > 0) {
|
|
957
|
+
Print.info(`Added // @ts-nocheck to ${publicVendorSuppression.updatedFiles} vendor JS files from publicFolders.`);
|
|
958
|
+
}
|
|
959
|
+
return result;
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
export {
|
|
963
|
+
ensureNoCheckInPublicVendorFiles,
|
|
964
|
+
ensureEditorConfigForTypes,
|
|
965
|
+
extractStaticPropsFromSource,
|
|
966
|
+
generateDeclarationContent,
|
|
967
|
+
generateTypesFile,
|
|
968
|
+
parseComponentsRegistry,
|
|
969
|
+
collectEventRegistry,
|
|
970
|
+
collectEventGraph,
|
|
971
|
+
buildEventManifest,
|
|
972
|
+
payloadToTs,
|
|
973
|
+
runGenerateTypes
|
|
974
|
+
};
|