-
Notifications
You must be signed in to change notification settings - Fork 0
/
web-types-generator.ts
78 lines (68 loc) · 2.8 KB
/
web-types-generator.ts
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
import {JsonDocs} from "@stencil/core/internal";
import fs from "fs";
export interface WebTypesGeneratorConfig {
name: string;
version: string;
defaultIconPath: string;
outputPath: string;
}
export class WebTypesGenerator {
constructor(public config: WebTypesGeneratorConfig) {}
generateWebTypesJson = async(docsData: JsonDocs) => {
const jsonData = {
"$schema": "https://json.schemastore.org/web-types",
"name": this.config.name,
"version": this.config.version,
"default-icon": this.config.defaultIconPath,
"description-markup": "markdown",
"contributions": {
"html": {
"elements": docsData.components.map((component) => ({
name: component.tag,
description: component.docs,
attributes: component.props
.filter((prop) => prop.attr)
.map((prop) => ({
name: prop.attr,
description: prop.docs,
type: prop.type,
defaultValue: prop.default,
required: prop.required,
})),
properties: component.props.map((prop) => ({
name: prop.name,
type: prop.type,
description: prop.docs,
defaultValue: prop.default,
required: prop.required,
})),
"/js/events": component.events.map((event) => ({
name: event.event,
description: event.docs,
})),
methods: component.methods.map((method) => ({
name: method.name,
description: method.docs,
signature: method.signature,
})),
cssProperties: component.styles
.filter((style) => style.annotation === 'prop')
.map((style) => ({
name: style.name,
description: style.docs,
})),
cssParts: component.parts.map((part) => ({
name: part.name,
description: part.docs,
})),
}))
}
}
};
await fs.writeFile(
this.config.outputPath,
JSON.stringify(jsonData, null, 2),
() => {}
);
}
}