Skip to content

Commit 65091ed

Browse files
committed
feat(builder): Add dynamic section for API reference during JSDoc build
Enables automatic discovery and rendering of documentation sections (FAQ, guides, etc.) from directory structure. Sections are discovered at build time and loaded asynchronously at runtime. JIRA: BGSOFUIPIRIN-6925 Cherry-picked from UI5/openui5@c71a404cb.
1 parent 403429d commit 65091ed

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

packages/builder/lib/processors/jsdoc/lib/transformApiJson.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ const typeParser = new TypeParser();
4747
* @param {string} sLibraryFile Path to the .library file of the library, used to extract further documentation information
4848
* @param {string|string[]} vDependencyAPIFiles Path of folder that contains api.json files of predecessor libs or
4949
* an array of paths of those files
50-
* @param {string} sFAQDir Path to the directory containing the sources for the FAQ section in APiRef
50+
* @param {string} sSectionsDir Path to the directory containing the sources for the sections (FAQ, documentation, etc.) in the API Reference
5151
* @returns {Promise} A Promise that resolves after the transformation has been completed
5252
*/
53-
function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles, sFAQDir, options) {
53+
function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles, sSectionsDir, options) {
5454
const fs = options && options.fs || require("fs");
5555
const returnOutputFiles = options && !!options.returnOutputFiles;
5656

@@ -59,7 +59,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
5959
log.info(" output file: " + sOutputFile);
6060
log.info(" library file: " + sLibraryFile);
6161
log.info(" dependency dir: " + vDependencyAPIFiles);
62-
log.info(" FAQ src dir: " + sFAQDir);
62+
log.info(" sections src dir: " + sSectionsDir);
6363
if (options && options.fs) {
6464
log.info("Using custom fs.");
6565
}
@@ -987,22 +987,43 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
987987
}
988988

989989
/**
990-
* Check for existence of FAQ data
991-
* (FAQ data must be defined as *.md files in the <code>sFAQDir</code>)
990+
* Check for existence of sections data
991+
* (Sections data must be defined as *.md files in the <code>sSectionsDir</code>)
992992
* and add a boolean flag in case it exists
993993
*
994994
* @param oChainObject chain object
995995
*/
996-
function addFlagsForFAQData(oChainObject) {
997-
if (!sFAQDir) {
996+
function addFlagsForSectionsData(oChainObject) {
997+
if (!sSectionsDir) {
998998
return oChainObject;
999999
}
1000+
10001001
const slibName = oChainObject.fileData.library;
1002+
10011003
oChainObject.fileData.symbols.forEach(function(symbol) {
1002-
const sfile = symbol.name.replace(slibName, "").replace(/[.]/g, "/") + ".md";
1003-
if (fs.existsSync(path.join(sFAQDir, sfile))) {
1004-
symbol.hasFAQ = true;
1004+
const sComponentPath = symbol.name.replace(slibName, "").replace(/^[.]/, "").replace(/[.]/g, "/");
1005+
if (!sComponentPath) {
1006+
return;
10051007
}
1008+
1009+
const componentDir = path.join(sSectionsDir, sComponentPath);
1010+
if (fs.existsSync(componentDir)) {
1011+
try {
1012+
1013+
const customSections = fs.readdirSync(componentDir, { withFileTypes: true })
1014+
.filter((dirent) => dirent.isFile() && dirent.name.endsWith('.md'))
1015+
.map((dirent) => dirent.name.replace(/\.md$/, ''));
1016+
1017+
// Store list of available sections for this symbol
1018+
if (customSections.length > 0) {
1019+
symbol.customSections = customSections;
1020+
}
1021+
1022+
} catch (error) {
1023+
log.error('Error scanning component sections directory:', componentDir, error);
1024+
}
1025+
}
1026+
10061027
});
10071028
return oChainObject;
10081029
}
@@ -2375,6 +2396,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
23752396
inputFile: sInputFile,
23762397
outputFile: sOutputFile,
23772398
libraryFile: sLibraryFile,
2399+
sectionsDir: sSectionsDir,
23782400
aDependentLibraryFiles: Array.isArray(vDependencyAPIFiles) ? vDependencyAPIFiles : null
23792401
};
23802402

@@ -2387,7 +2409,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
23872409
.then(getAPIJSONPromise)
23882410
.then(loadDependencyLibraryFiles)
23892411
.then(transformApiJson)
2390-
.then(addFlagsForFAQData)
2412+
.then(addFlagsForSectionsData)
23912413
.then(createApiRefApiJson);
23922414
return p;
23932415

0 commit comments

Comments
 (0)