-
Notifications
You must be signed in to change notification settings - Fork 115
/
custom-elements-manifest.config.mjs
125 lines (108 loc) · 3.93 KB
/
custom-elements-manifest.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { parse } from "comment-parser";
export default {
globs: ["src/components/**/!(*.test|*.stories).ts"],
exclude: ["src/**/*.css", "src/**/*.constant.ts","src/**/*/*.types.ts","src/components/icon/icon-list.ts"],
outdir: "dist/",
dev: false,
watch: false,
dependencies: false,
packagejson: true,
litelement: true,
plugins: [
{
name: "filter",
analyzePhase({ ts, node, moduleDoc }) {
const getKind = kind => {
switch (kind) {
case ts.SyntaxKind.StringKeyword: {
return "string";
}
}
return "any";
};
switch (node.kind) {
case ts.SyntaxKind.ClassDeclaration: {
const className = node.name.getText();
const classDoc = moduleDoc?.declarations?.find(
declaration => declaration.name === className
);
if (node.typeParameters?.length > 0) {
classDoc.typeParameters = node.typeParameters.map(p => ({
name: p.name.escapedText,
extends: p.constraint?.typeName.escapedText,
default: getKind(p.default.kind),
}));
}
if (classDoc?.members) {
const eventMembers = classDoc.members.filter(member =>
member.type?.text?.startsWith("EventDispatcher")
);
classDoc.events?.push(
...eventMembers.map(({ description, name, type }) => {
const eventMemberNode = node.members.find(
member => member.name.getText() === name
);
const eventDecorator = eventMemberNode.decorators.find(
decorator => decorator.expression.expression.getText() === "event"
);
name = eventDecorator.expression.arguments[0]?.text || name;
return {
type: {
text: `CustomEvent<${type.text.match(/EventDispatcher<(.*?)>$/s)[1]}>`,
},
description,
name,
};
})
);
// Remove events from properties
classDoc.members = classDoc.members.filter(member =>
member.type?.text?.startsWith("EventDispatcher")
);
// Remove private properties
classDoc.members = classDoc.members.filter(member => member.privacy !== "private");
}
break;
}
}
},
},
{
name: "custom-tags",
analyzePhase({ ts, node, moduleDoc }) {
switch (node.kind) {
case ts.SyntaxKind.ClassDeclaration: {
const className = node.name.getText();
const classDoc = moduleDoc?.declarations?.find(
declaration => declaration.name === className
);
const customTags = ["tag", "summary", "cssproperty"];
let customComments = "/**";
node.jsDoc?.forEach(jsDoc => {
jsDoc?.tags?.forEach(tag => {
const tagName = tag.tagName.getText();
if (customTags.includes(tagName)) {
customComments += `\n * @${tagName} ${tag.comment}`;
}
});
});
// This is what allows us to map JSDOC comments to ReactWrappers.
classDoc["jsDoc"] = node.jsDoc?.map(jsDoc => jsDoc.getFullText()).join("\n");
const parsed = parse(`${customComments}\n */`);
if (!parsed.length) return;
parsed[0].tags?.forEach(t => {
if (!Array.isArray(classDoc[t.tag])) {
classDoc[t.tag] = [];
}
classDoc[t.tag].push({
name: t.name,
description: t.description,
type: t.type || undefined,
});
});
}
}
},
},
],
};