Skip to content

Commit dcb829b

Browse files
authored
fix: fix API build for composite components (#391)
Background: some of the components do not have separate sample page, but they are appended to others sample page. The API of those components is part (in most cases) of parent components API, that use them as composite components. Issue: the API of the composite/child components misses base properties. Root cause: the API generation of the parent component is done before the API generation of the composite/child components. Solution: calculate the API of those composite components before their addition to parents` component API. Before (StandardListItem "selected" and "type" properties are missing)
1 parent 7c3c453 commit dcb829b

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

lib/documentation/index.js

+33-8
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Handlebars.registerHelper('toKebabCase', function (str) {
3434
return kebab !== str ? kebab : "";
3535
});
3636

37-
3837
Handlebars.registerHelper('checkEven', function (iIndex) {
3938
return (iIndex % 2 === 0) ? "api-table-roll-even" : "api-table-roll-odd";
4039
});
@@ -46,35 +45,48 @@ Handlebars.registerPartial('methods', methodsTemplate);
4645

4746
mkdirp(`dist/test-resources/sap/ui/webcomponents/main/api`);
4847

49-
entries.forEach((entry, index) => {
48+
let entriesAPI = [];
5049

51-
const parentName = entry.extends;
52-
let parent = getComponentByName(parentName) || {};
50+
const mergeParentAPI = entry => {
51+
if (entriesAPI.indexOf(entry.basename) !== -1) {
52+
return entry;
53+
}
5354

55+
let parent = getComponentByName(entry.extends) || {};
5456
parent = { ...{ properties: [], events: [], slots: [] }, ...parent };
5557

5658
// extend component documentation
5759
entry.properties = [...(entry.properties || []), ...(parent.properties || [])];
5860
entry.events = [...(entry.events || []), ...(parent.events || [])];
5961
entry.slots = [...(entry.slots || []), ...(parent.slots || [])];
6062

63+
entriesAPI.push(entry.basename);
64+
65+
return entry;
66+
}
67+
68+
const appendAdditionalEntriesAPI = entry => {
6169
if (entry.appenddocs) {
6270
const additionalEntries = entry.appenddocs.split(" ");
63-
6471
entry.additionalDocs = [];
6572

6673
additionalEntries.forEach(entryName => {
67-
entry.additionalDocs.push(getComponentByName(entryName));
74+
let additionalEntry = getComponentByName(entryName);
75+
additionalEntry = mergeParentAPI(additionalEntry);
76+
entry.additionalDocs.push(additionalEntry);
6877
});
6978
}
7079

80+
return entry;
81+
}
82+
83+
const generateSamplePage = entry => {
7184
let content = "";
7285

7386
try {
7487
content = fs.readFileSync(`dist/test-resources/sap/ui/webcomponents/main/samples/${capitalize(entry.basename)}.sample.html`, 'utf8');
7588
} catch (err) { }
7689

77-
7890
if (content) {
7991
const fnRedirect = `
8092
<script>
@@ -105,5 +117,18 @@ entries.forEach((entry, index) => {
105117
// console.log(err);
106118
});
107119
}
120+
}
121+
122+
const generateComponentAPI = entry => {
123+
// (1) merge parent API
124+
entry = mergeParentAPI(entry);
125+
126+
// (2) append additional API for children
127+
entry = appendAdditionalEntriesAPI(entry);
128+
129+
// (3) generate sample page
130+
generateSamplePage(entry);
131+
}
108132

109-
});
133+
entries.forEach(generateComponentAPI);
134+
entriesAPI = [];

0 commit comments

Comments
 (0)