Skip to content

Commit

Permalink
Make rawDescriptions a command argument
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmoroz committed Nov 13, 2024
1 parent a5c849c commit 663e207
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
4 changes: 0 additions & 4 deletions packages/api-docs-builder/ProjectSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,4 @@ export interface ProjectSettings {
* Determines the base API URL for generated JSDocs
*/
baseApiUrl?: string;
/**
* Whether to output raw JSDoc descriptions or process them as markdown, `false` by default
*/
rawDescriptions?: boolean;
}
23 changes: 13 additions & 10 deletions packages/api-docs-builder/buildApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ async function removeOutdatedApiDocsTranslations(
);
}

export async function buildApi(projectsSettings: ProjectSettings[], grep: RegExp | null = null) {
let rawDescriptionsCurrent = false;

export async function buildApi(
projectsSettings: ProjectSettings[],
grep: RegExp | null = null,
rawDescriptions = false,
) {
rawDescriptionsCurrent = rawDescriptions;
const allTypeScriptProjects = projectsSettings
.flatMap((setting) => setting.typeScriptProjects)
.reduce(
Expand Down Expand Up @@ -106,8 +113,6 @@ export async function buildApi(projectsSettings: ProjectSettings[], grep: RegExp
}
}

let rawDescriptions = false;

async function buildSingleProject(
projectSettings: ProjectSettings,
buildTypeScriptProject: TypeScriptProjectBuilder,
Expand All @@ -123,8 +128,6 @@ async function buildSingleProject(
if (manifestDir) {
mkdirSync(manifestDir, { recursive: true });
}

rawDescriptions = Boolean(projectSettings.rawDescriptions);
const apiBuilds = tsProjects.flatMap((project) => {
const projectComponents = findComponents(path.join(project.rootPath, 'src')).filter(
(component) => {
Expand Down Expand Up @@ -210,18 +213,18 @@ async function buildSingleProject(
}

export function renderMarkdown(markdown: string) {
return rawDescriptions ? markdown : _renderMarkdown(markdown);
return rawDescriptionsCurrent ? markdown : _renderMarkdown(markdown);
}
export function renderCodeTags(value: string) {
return rawDescriptions ? value : value.replace(/`(.*?)`/g, '<code>$1</code>');
return rawDescriptionsCurrent ? value : value.replace(/`(.*?)`/g, '<code>$1</code>');
}
export function escapeEntities(value: string) {
return rawDescriptions ? value : _escapeEntities(value);
return rawDescriptionsCurrent ? value : _escapeEntities(value);
}
export function escapeCell(value: string) {
return rawDescriptions ? value : _escapeCell(value);
return rawDescriptionsCurrent ? value : _escapeCell(value);
}
export function joinUnionTypes(value: string[]) {
// Use unopinionated formatting for raw descriptions
return rawDescriptions ? value.join(' | ') : value.join('<br>&#124;&nbsp;');
return rawDescriptionsCurrent ? value.join(' | ') : value.join('<br>&#124;&nbsp;');
}
21 changes: 14 additions & 7 deletions scripts/buidApiDocs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,30 @@ const projectSettings: ProjectSettings[] = [
muiSystemProjectSettings,
];

type CommandOptions = { grep?: string };
type CommandOptions = { grep?: string; rawDescriptions?: boolean };

async function run(argv: ArgumentsCamelCase<CommandOptions>) {
const grep = argv.grep == null ? null : new RegExp(argv.grep);
return buildApi(projectSettings, grep);
const rawDescriptions = argv.rawDescriptions === true;
return buildApi(projectSettings, grep, rawDescriptions);
}

yargs(process.argv.slice(2))
.command({
command: '$0',
describe: 'Generates API documentation for the MUI packages.',
builder: (command) => {
return command.option('grep', {
description:
'Only generate files for component filenames matching the pattern. The string is treated as a RegExp.',
type: 'string',
});
return command
.option('grep', {
description:
'Only generate files for component filenames matching the pattern. The string is treated as a RegExp.',
type: 'string',
})
.option('rawDescriptions', {
description: 'Whether to output raw JSDoc descriptions or process them as markdown.',
type: 'boolean',
default: false,
});
},
handler: run,
})
Expand Down

0 comments on commit 663e207

Please sign in to comment.