forked from Trendyol/baklava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-elements-manifest.config.mjs
49 lines (43 loc) · 1.73 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
export default {
globs: ['src/components/**/!(*.test).ts'],
exclude: ['src/**/*.css', '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 }) {
switch (node.kind) {
case ts.SyntaxKind.ClassDeclaration: {
const className = node.name.getText();
const classDoc = moduleDoc?.declarations?.find(declaration => declaration.name === className);
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.replace(/.*<([a-z]+)>/, '$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;
}
}
},
}
],
};