Skip to content

Commit

Permalink
Build docs of services category in a separate folder (#3453)
Browse files Browse the repository at this point in the history
* Build docs of services category in a separate folder

* Remove spaces for autogenerated md filenames
  • Loading branch information
ethanshar authored Dec 11, 2024
1 parent ee8a437 commit b1ceef4
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions scripts/docs/buildDocsCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const childProcess = require('child_process');
const fs = require('fs');

const COMPONENTS_DOCS_DIR = './docs/components';
const VALID_CATEGORIES = [
const SERVICES_DOCS_DIR = './docs/services';

const VALID_COMPONENTS_CATEGORIES = [
'foundation',
'basic',
'assets',
Expand All @@ -21,7 +23,9 @@ const VALID_CATEGORIES = [
'overlays',
'charts',
'incubator',
'infra'
'infra',
// non components categories
'services'
];

function buildDocs(apiFolders, componentsPreProcess) {
Expand Down Expand Up @@ -64,7 +68,7 @@ function processComponents(components) {
const isParentComponent = parentComponents.includes(componentName);
const isIncubatorComponent = component.category === 'incubator';

if (!VALID_CATEGORIES.includes(component.category)) {
if (!VALID_COMPONENTS_CATEGORIES.includes(component.category)) {
console.error(`${componentName} has invalid category "${component.category}"`);
}

Expand All @@ -88,15 +92,21 @@ function processComponents(components) {
content += `${buildOldDocs(component)}\n`;
}

const componentParentDir =
componentParentName || isParentComponent ? `/${componentParentName || componentName}` : '';
const dirPath = `${COMPONENTS_DOCS_DIR}/${component.category}${componentParentDir}`;

let dirPath;
if (component.category === 'services') {
dirPath = `${SERVICES_DOCS_DIR}`;
} else {
const componentParentDir =
componentParentName || isParentComponent ? `/${componentParentName || componentName}` : '';
dirPath = `${COMPONENTS_DOCS_DIR}/${component.category}${componentParentDir}`;
}

if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, {recursive: true});
}

fs.writeFileSync(`${dirPath}/${component.name}.md`, content, {encoding: 'utf8'});
fs.writeFileSync(`${dirPath}/${component.name.replaceAll(' ', '_')}.md`, content, {encoding: 'utf8'});
});
}

Expand Down

0 comments on commit b1ceef4

Please sign in to comment.