-
Notifications
You must be signed in to change notification settings - Fork 0
/
stencil.custom-elements-json.ts
63 lines (54 loc) · 1.71 KB
/
stencil.custom-elements-json.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
import fs from "fs";
import { JsonDocs } from "@stencil/core/internal";
// this outputs the data for the storybook props documentation table
// via https://github.com/ionic-team/stencil/pull/2354#issuecomment-627503893
export function generateCustomElementsJson(docsData: JsonDocs) {
const jsonData = {
version: 1.2,
tags: docsData.components.map(component => ({
name: component.tag,
path: component.filePath,
description: component.docs,
attributes: component.props
.filter(prop => prop.attr)
.map(prop => ({
name: prop.attr,
type: prop.type,
description: prop.docs,
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,
})),
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,
})),
slots: component.slots.map(slot => ({
name: slot.name,
description: slot.docs,
})),
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,
})),
})),
};
fs.writeFileSync("./custom-elements.json", JSON.stringify(jsonData, null, 2));
}