@next-core/build-config-factory 2.18.52 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/package.json +3 -3
- package/src/generateBrickDocs.js +167 -36
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,48 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.21.0](https://github.com/easyops-cn/next-core/compare/@next-core/build-config-factory@2.20.0...@next-core/build-config-factory@2.21.0) (2022-07-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **generateBrickDocs:** support description of enum and interface ([3b81fe1](https://github.com/easyops-cn/next-core/commit/3b81fe1a5ee3d1666083fad50c7da8d62379c98a))
|
|
12
|
+
* **generateBrickDocs:** support get detail of reflection type from declaration ([b62557f](https://github.com/easyops-cn/next-core/commit/b62557f09a362a85ac25151d8940cec4e691700b))
|
|
13
|
+
* **generateBrickDocs:** support get parameters type of method from declaration ([e88bef6](https://github.com/easyops-cn/next-core/commit/e88bef6006140001bd44271911566df497e03ca4))
|
|
14
|
+
* **generateBrickDocs:** support get property type from setter ([5825363](https://github.com/easyops-cn/next-core/commit/5825363195c4359a21b9b80360a58a261e886825))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# [2.20.0](https://github.com/easyops-cn/next-core/compare/@next-core/build-config-factory@2.19.0...@next-core/build-config-factory@2.20.0) (2022-07-05)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* **generateBrickDocs:** support infer required and default of property and detail of event from declaration ([6a60f26](https://github.com/easyops-cn/next-core/commit/6a60f26563683d89d5b36bb766f973cb23522e70))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# [2.19.0](https://github.com/easyops-cn/next-core/compare/@next-core/build-config-factory@2.18.52...@next-core/build-config-factory@2.19.0) (2022-07-05)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Bug Fixes
|
|
35
|
+
|
|
36
|
+
* **generateBrickDocs:** type will not be traversed in another module once traversed ([c539bcf](https://github.com/easyops-cn/next-core/commit/c539bcf86a8d7d0955f4115373db838032c5c677))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
* **generateBrickDocs:** add support for extendedTypes ([12c9e53](https://github.com/easyops-cn/next-core/commit/12c9e536b07104a9ee8478cbe8c2aa6887751335))
|
|
42
|
+
* **generateBrickDocs:** add support for index signature ([1f16c2c](https://github.com/easyops-cn/next-core/commit/1f16c2c1a961a43a139f8bef1117c8eb4e4ba3f6))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
6
48
|
## [2.18.52](https://github.com/easyops-cn/next-core/compare/@next-core/build-config-factory@2.18.51...@next-core/build-config-factory@2.18.52) (2022-06-28)
|
|
7
49
|
|
|
8
50
|
**Note:** Version bump only for package @next-core/build-config-factory
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/build-config-factory",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.21.0",
|
|
4
4
|
"description": "build config factory",
|
|
5
5
|
"homepage": "https://github.com/easyops-cn/next-core/tree/master/packages/build-config-factory",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@next-core/brick-utils": "^2.37.
|
|
21
|
+
"@next-core/brick-utils": "^2.37.21",
|
|
22
22
|
"@next-core/repo-config": "^0.2.1",
|
|
23
23
|
"@next-core/typedoc-plugin-filter-inherit": "^1.2.2",
|
|
24
24
|
"@next-core/webpack-config-factory": "^2.16.6",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"typedoc": "^0.19.2",
|
|
38
38
|
"typedoc-plugin-no-inherit": "^1.2.2"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "34a0808712ecaa925d0860d281ab23cf3bec7317"
|
|
41
41
|
}
|
package/src/generateBrickDocs.js
CHANGED
|
@@ -100,12 +100,26 @@ function convertTagsToMapByFields(tags, fields) {
|
|
|
100
100
|
}, {});
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
function getClassChildType(child) {
|
|
104
|
+
let type = child.type;
|
|
105
|
+
|
|
106
|
+
// setter
|
|
107
|
+
if (!type && child.kindString === "Accessor" && child.setSignature) {
|
|
108
|
+
type = child.setSignature[0].parameters[0].type;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return type;
|
|
112
|
+
}
|
|
113
|
+
|
|
103
114
|
function composeBrickDocProperties(brick) {
|
|
104
|
-
const { name, comment } = brick;
|
|
105
|
-
const type = brick
|
|
115
|
+
const { name, comment, flags, defaultValue } = brick;
|
|
116
|
+
const type = getClassChildType(brick);
|
|
117
|
+
|
|
106
118
|
return {
|
|
107
119
|
name,
|
|
108
|
-
type: extractRealInterfaceType(type
|
|
120
|
+
type: extractRealInterfaceType(type),
|
|
121
|
+
required: flags?.isOptional !== true,
|
|
122
|
+
default: defaultValue,
|
|
109
123
|
...convertTagsToMapByFields(get(comment, "tags", []), propertyDocComments),
|
|
110
124
|
};
|
|
111
125
|
}
|
|
@@ -122,11 +136,19 @@ function getEventTypeByDecorators(decorators) {
|
|
|
122
136
|
return null;
|
|
123
137
|
}
|
|
124
138
|
|
|
139
|
+
function getDetailTypeByEventType(type) {
|
|
140
|
+
if (type.name === "EventEmitter" && type.typeArguments?.length > 0) {
|
|
141
|
+
const argument = type.typeArguments[0];
|
|
142
|
+
return extractRealInterfaceType(argument);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
125
146
|
function composeBrickDocEvents(brick) {
|
|
126
|
-
const { comment, decorators } = brick;
|
|
147
|
+
const { comment, decorators, type } = brick;
|
|
127
148
|
|
|
128
149
|
return {
|
|
129
150
|
type: getEventTypeByDecorators(decorators),
|
|
151
|
+
detail: getDetailTypeByEventType(type),
|
|
130
152
|
...convertTagsToMapByFields(get(comment, "tags", []), eventDocComments),
|
|
131
153
|
};
|
|
132
154
|
}
|
|
@@ -139,6 +161,14 @@ function composeBrickDocMethods(brick) {
|
|
|
139
161
|
[];
|
|
140
162
|
return {
|
|
141
163
|
name,
|
|
164
|
+
params: signatures[0].parameters
|
|
165
|
+
?.map(
|
|
166
|
+
(parameter) =>
|
|
167
|
+
`${parameter.name}${
|
|
168
|
+
parameter.flags?.isOptional ? "?" : ""
|
|
169
|
+
}: ${extractRealInterfaceType(parameter.type)}`
|
|
170
|
+
)
|
|
171
|
+
.join(" "),
|
|
142
172
|
...convertTagsToMapByFields(tags, methodComments),
|
|
143
173
|
};
|
|
144
174
|
}
|
|
@@ -284,8 +314,8 @@ function existBrickDocId(element) {
|
|
|
284
314
|
}
|
|
285
315
|
}
|
|
286
316
|
|
|
287
|
-
function extractRealInterfaceType(
|
|
288
|
-
switch (type) {
|
|
317
|
+
function extractRealInterfaceType(typeData, parentType) {
|
|
318
|
+
switch (typeData?.type) {
|
|
289
319
|
case "reference":
|
|
290
320
|
// eslint-disable-next-line no-case-declarations
|
|
291
321
|
let result = "";
|
|
@@ -295,25 +325,24 @@ function extractRealInterfaceType(type, typeData, parentType) {
|
|
|
295
325
|
|
|
296
326
|
if (typeData.typeArguments && typeData.typeArguments.length > 0) {
|
|
297
327
|
result += `<${typeData.typeArguments
|
|
298
|
-
.map((type) => extractRealInterfaceType(type
|
|
328
|
+
.map((type) => extractRealInterfaceType(type))
|
|
299
329
|
.join(", ")}>`;
|
|
300
330
|
}
|
|
301
331
|
|
|
302
332
|
return result;
|
|
303
333
|
case "array":
|
|
304
334
|
return `${extractRealInterfaceType(
|
|
305
|
-
typeData.elementType.type,
|
|
306
335
|
typeData.elementType,
|
|
307
|
-
type
|
|
336
|
+
typeData.type
|
|
308
337
|
)}[]`;
|
|
309
338
|
case "union":
|
|
310
339
|
if (parentType === "array") {
|
|
311
340
|
return `(${typeData.types
|
|
312
|
-
.map((type) => extractRealInterfaceType(type
|
|
341
|
+
.map((type) => extractRealInterfaceType(type))
|
|
313
342
|
.join(" | ")})`;
|
|
314
343
|
}
|
|
315
344
|
return typeData.types
|
|
316
|
-
.map((type) => extractRealInterfaceType(type
|
|
345
|
+
.map((type) => extractRealInterfaceType(type))
|
|
317
346
|
.join(" | ");
|
|
318
347
|
case "stringLiteral":
|
|
319
348
|
return `"${typeData.value}"`;
|
|
@@ -323,10 +352,31 @@ function extractRealInterfaceType(type, typeData, parentType) {
|
|
|
323
352
|
return typeData.name;
|
|
324
353
|
case "intersection":
|
|
325
354
|
return typeData.types
|
|
326
|
-
.map((type) => extractRealInterfaceType(type
|
|
355
|
+
.map((type) => extractRealInterfaceType(type))
|
|
327
356
|
.join(" & ");
|
|
328
|
-
case "reflection":
|
|
329
|
-
|
|
357
|
+
case "reflection": {
|
|
358
|
+
if (typeData.declaration) {
|
|
359
|
+
const { children = [], indexSignature = [] } = typeData.declaration;
|
|
360
|
+
|
|
361
|
+
return `{ ${[
|
|
362
|
+
...children.map(
|
|
363
|
+
(child) =>
|
|
364
|
+
`${child.name}${
|
|
365
|
+
child.flags?.isOptional ? "?" : ""
|
|
366
|
+
}: ${extractRealInterfaceType(child.type)};`
|
|
367
|
+
),
|
|
368
|
+
...indexSignature.map((item) => {
|
|
369
|
+
const parameter = item.parameters[0];
|
|
370
|
+
return `[${parameter.name}: ${extractRealInterfaceType(
|
|
371
|
+
parameter.type.type,
|
|
372
|
+
parameter.type
|
|
373
|
+
)}]: ${extractRealInterfaceType(item.type)};`;
|
|
374
|
+
}),
|
|
375
|
+
].join(" ")} }`;
|
|
376
|
+
} else {
|
|
377
|
+
return "object";
|
|
378
|
+
}
|
|
379
|
+
}
|
|
330
380
|
default:
|
|
331
381
|
return "";
|
|
332
382
|
}
|
|
@@ -338,7 +388,7 @@ function extractBrickDocTypes(type) {
|
|
|
338
388
|
typeParameter: getTypeParameter(type),
|
|
339
389
|
kind: "type",
|
|
340
390
|
description: get(type, ["comment", "shortText"], "").trim(),
|
|
341
|
-
type: extractRealInterfaceType(type.type
|
|
391
|
+
type: extractRealInterfaceType(type.type),
|
|
342
392
|
};
|
|
343
393
|
}
|
|
344
394
|
|
|
@@ -347,6 +397,7 @@ function extractBrickDocEnumerations(enumerations) {
|
|
|
347
397
|
name: enumerations.name,
|
|
348
398
|
typeParameter: null,
|
|
349
399
|
kind: "enum",
|
|
400
|
+
description: enumerations?.comment?.shortText?.trim(),
|
|
350
401
|
children: [
|
|
351
402
|
...enumerations.children.map((child) => {
|
|
352
403
|
return {
|
|
@@ -392,16 +443,30 @@ function extractBrickDocInterface(typeIds, references) {
|
|
|
392
443
|
name: finder.name,
|
|
393
444
|
typeParameter: getTypeParameter(finder),
|
|
394
445
|
kind: "interface",
|
|
395
|
-
|
|
396
|
-
|
|
446
|
+
extendedTypes: finder.extendedTypes,
|
|
447
|
+
description: finder?.comment?.shortText?.trim(),
|
|
448
|
+
children:
|
|
449
|
+
finder.children?.map((child) => {
|
|
450
|
+
return {
|
|
451
|
+
name: child.name,
|
|
452
|
+
type: extractRealInterfaceType(child.type),
|
|
453
|
+
required: !get(child, ["flags", "isOptional"], false),
|
|
454
|
+
description: get(child, ["comment", "shortText"], "").trim(),
|
|
455
|
+
};
|
|
456
|
+
}) || [],
|
|
457
|
+
indexSignature:
|
|
458
|
+
finder.indexSignature?.map((child) => {
|
|
397
459
|
return {
|
|
398
460
|
name: child.name,
|
|
399
|
-
|
|
461
|
+
parameters: child.parameters.map((parameter) => ({
|
|
462
|
+
...parameter,
|
|
463
|
+
type: extractRealInterfaceType(parameter.type),
|
|
464
|
+
})),
|
|
465
|
+
type: extractRealInterfaceType(child.type),
|
|
400
466
|
required: !get(child, ["flags", "isOptional"], false),
|
|
401
467
|
description: get(child, ["comment", "shortText"], "").trim(),
|
|
402
468
|
};
|
|
403
|
-
}),
|
|
404
|
-
],
|
|
469
|
+
}) || [],
|
|
405
470
|
};
|
|
406
471
|
}
|
|
407
472
|
|
|
@@ -438,10 +503,29 @@ function traverseExtraInterfaceReferences(modules, References) {
|
|
|
438
503
|
function traverseElementUsedInterfaceIds(
|
|
439
504
|
element,
|
|
440
505
|
usedReferenceIds,
|
|
441
|
-
references
|
|
506
|
+
references,
|
|
507
|
+
traversedTypeSet
|
|
442
508
|
) {
|
|
443
509
|
element.children.forEach((child) => {
|
|
444
|
-
|
|
510
|
+
if (child.kindString === "Method") {
|
|
511
|
+
child.signatures[0].parameters?.map((parameter) =>
|
|
512
|
+
traverseUsedReferenceIdsByType(
|
|
513
|
+
parameter.type,
|
|
514
|
+
usedReferenceIds,
|
|
515
|
+
references,
|
|
516
|
+
traversedTypeSet
|
|
517
|
+
)
|
|
518
|
+
);
|
|
519
|
+
} else {
|
|
520
|
+
const type = getClassChildType(child);
|
|
521
|
+
|
|
522
|
+
traverseUsedReferenceIdsByType(
|
|
523
|
+
type,
|
|
524
|
+
usedReferenceIds,
|
|
525
|
+
references,
|
|
526
|
+
traversedTypeSet
|
|
527
|
+
);
|
|
528
|
+
}
|
|
445
529
|
});
|
|
446
530
|
}
|
|
447
531
|
|
|
@@ -461,13 +545,19 @@ function traverseModules(modules, brickDocs) {
|
|
|
461
545
|
if (!elementId) return;
|
|
462
546
|
|
|
463
547
|
const usedReferenceIds = new Set();
|
|
548
|
+
const traversedTypeSet = new Set();
|
|
464
549
|
const classElement = module.children.find(
|
|
465
550
|
(child) => child.id === elementId && existBrickDocId(child)
|
|
466
551
|
);
|
|
467
552
|
if (!classElement) return;
|
|
468
553
|
const { comment, children, groups } = classElement;
|
|
469
554
|
const references = [...module.children, ...extraInterfaceReferencesValues];
|
|
470
|
-
traverseElementUsedInterfaceIds(
|
|
555
|
+
traverseElementUsedInterfaceIds(
|
|
556
|
+
classElement,
|
|
557
|
+
usedReferenceIds,
|
|
558
|
+
references,
|
|
559
|
+
traversedTypeSet
|
|
560
|
+
);
|
|
471
561
|
const brick = {
|
|
472
562
|
...extractBrickDocBaseKind(comment.tags),
|
|
473
563
|
...extractBrickDocComplexKind(groups, children),
|
|
@@ -480,25 +570,38 @@ function traverseModules(modules, brickDocs) {
|
|
|
480
570
|
});
|
|
481
571
|
}
|
|
482
572
|
|
|
483
|
-
function traverseUsedReferenceIdsByType(
|
|
573
|
+
function traverseUsedReferenceIdsByType(
|
|
574
|
+
type,
|
|
575
|
+
usedReferenceIds,
|
|
576
|
+
references,
|
|
577
|
+
traversedTypeSet
|
|
578
|
+
) {
|
|
484
579
|
if (!type || !type.type) return;
|
|
485
580
|
|
|
486
|
-
if (type
|
|
581
|
+
if (traversedTypeSet.has(type)) {
|
|
487
582
|
return;
|
|
488
583
|
}
|
|
489
|
-
|
|
584
|
+
|
|
585
|
+
traversedTypeSet.add(type);
|
|
586
|
+
|
|
490
587
|
switch (type.type) {
|
|
491
588
|
case "union":
|
|
492
589
|
case "intersection":
|
|
493
590
|
type.types.forEach((item) =>
|
|
494
|
-
traverseUsedReferenceIdsByType(
|
|
591
|
+
traverseUsedReferenceIdsByType(
|
|
592
|
+
item,
|
|
593
|
+
usedReferenceIds,
|
|
594
|
+
references,
|
|
595
|
+
traversedTypeSet
|
|
596
|
+
)
|
|
495
597
|
);
|
|
496
598
|
break;
|
|
497
599
|
case "array":
|
|
498
600
|
traverseUsedReferenceIdsByType(
|
|
499
601
|
type.elementType,
|
|
500
602
|
usedReferenceIds,
|
|
501
|
-
references
|
|
603
|
+
references,
|
|
604
|
+
traversedTypeSet
|
|
502
605
|
);
|
|
503
606
|
break;
|
|
504
607
|
case "reference":
|
|
@@ -507,12 +610,18 @@ function traverseUsedReferenceIdsByType(type, usedReferenceIds, references) {
|
|
|
507
610
|
traverseUsedReferenceIdsByReflection(
|
|
508
611
|
references.find((child) => child.id === type.id),
|
|
509
612
|
usedReferenceIds,
|
|
510
|
-
references
|
|
613
|
+
references,
|
|
614
|
+
traversedTypeSet
|
|
511
615
|
);
|
|
512
616
|
}
|
|
513
617
|
if (type.typeArguments && type.typeArguments.length > 0) {
|
|
514
618
|
type.typeArguments.forEach((item) =>
|
|
515
|
-
traverseUsedReferenceIdsByType(
|
|
619
|
+
traverseUsedReferenceIdsByType(
|
|
620
|
+
item,
|
|
621
|
+
usedReferenceIds,
|
|
622
|
+
references,
|
|
623
|
+
traversedTypeSet
|
|
624
|
+
)
|
|
516
625
|
);
|
|
517
626
|
}
|
|
518
627
|
break;
|
|
@@ -521,7 +630,8 @@ function traverseUsedReferenceIdsByType(type, usedReferenceIds, references) {
|
|
|
521
630
|
traverseUsedReferenceIdsByType(
|
|
522
631
|
type.objectType,
|
|
523
632
|
usedReferenceIds,
|
|
524
|
-
references
|
|
633
|
+
references,
|
|
634
|
+
traversedTypeSet
|
|
525
635
|
);
|
|
526
636
|
break;
|
|
527
637
|
}
|
|
@@ -530,20 +640,40 @@ function traverseUsedReferenceIdsByType(type, usedReferenceIds, references) {
|
|
|
530
640
|
function traverseUsedReferenceIdsByReflection(
|
|
531
641
|
reflection,
|
|
532
642
|
usedReferenceIds,
|
|
533
|
-
references
|
|
643
|
+
references,
|
|
644
|
+
traversedTypeSet
|
|
534
645
|
) {
|
|
535
646
|
if (!reflection) {
|
|
536
647
|
return;
|
|
537
648
|
}
|
|
538
649
|
switch (reflection.kindString) {
|
|
539
650
|
case "Interface":
|
|
651
|
+
reflection.extendedTypes?.forEach((type) =>
|
|
652
|
+
traverseUsedReferenceIdsByType(
|
|
653
|
+
type,
|
|
654
|
+
usedReferenceIds,
|
|
655
|
+
references,
|
|
656
|
+
traversedTypeSet
|
|
657
|
+
)
|
|
658
|
+
);
|
|
540
659
|
reflection.children
|
|
541
|
-
|
|
660
|
+
?.filter((item) => item.kindString === "Property")
|
|
661
|
+
.forEach((item) =>
|
|
662
|
+
traverseUsedReferenceIdsByType(
|
|
663
|
+
item.type,
|
|
664
|
+
usedReferenceIds,
|
|
665
|
+
references,
|
|
666
|
+
traversedTypeSet
|
|
667
|
+
)
|
|
668
|
+
);
|
|
669
|
+
reflection.indexSignature
|
|
670
|
+
?.filter((item) => item.kindString === "Index signature")
|
|
542
671
|
.forEach((item) =>
|
|
543
672
|
traverseUsedReferenceIdsByType(
|
|
544
673
|
item.type,
|
|
545
674
|
usedReferenceIds,
|
|
546
|
-
references
|
|
675
|
+
references,
|
|
676
|
+
traversedTypeSet
|
|
547
677
|
)
|
|
548
678
|
);
|
|
549
679
|
break;
|
|
@@ -551,7 +681,8 @@ function traverseUsedReferenceIdsByReflection(
|
|
|
551
681
|
traverseUsedReferenceIdsByType(
|
|
552
682
|
reflection.type,
|
|
553
683
|
usedReferenceIds,
|
|
554
|
-
references
|
|
684
|
+
references,
|
|
685
|
+
traversedTypeSet
|
|
555
686
|
);
|
|
556
687
|
break;
|
|
557
688
|
}
|
|
@@ -590,7 +721,7 @@ function generateBrickBook(docsJson) {
|
|
|
590
721
|
fs.writeFileSync(storiesPath, JSON.stringify(stories, null, 2), {
|
|
591
722
|
encoding: "utf-8",
|
|
592
723
|
});
|
|
593
|
-
console.log("Brick book written to
|
|
724
|
+
console.log("Brick book written to stories.json.");
|
|
594
725
|
}
|
|
595
726
|
|
|
596
727
|
module.exports = function generateBrickDocs(packageName) {
|