forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-spec-generator.js
43 lines (36 loc) · 1.2 KB
/
api-spec-generator.js
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
const fs = require('fs');
function apiSpecGenerator(opts) {
return {
type: 'docs-custom',
generator: (docsData) => {
const content = [];
docsData.components.forEach(cmp => generateComponent(cmp, content));
const contentStr = content.join('\n');
return new Promise(resolve => {
fs.writeFile(opts.file, contentStr, () => {
resolve();
});
});
}
};
}
function generateComponent(component, content) {
content.push('');
content.push(`${component.tag},${component.encapsulation}`);
component.props.forEach(prop => {
content.push(`${component.tag},prop,${prop.name},${prop.type},${prop.default},${prop.required},${prop.reflectToAttr}`);
});
component.methods.forEach(prop => {
content.push(`${component.tag},method,${prop.name},${prop.signature}`);
});
component.events.forEach(prop => {
content.push(`${component.tag},event,${prop.event},${prop.detail},${prop.bubbles}`);
});
component.styles.forEach(prop => {
content.push(`${component.tag},css-prop,${prop.name}`);
});
component.parts.forEach(part => {
content.push(`${component.tag},part,${part.name}`);
});
}
exports.apiSpecGenerator = apiSpecGenerator;