Skip to content

Commit

Permalink
[code-infra] Adapt API code generator to Base UI repo needs (#41475)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed Mar 13, 2024
1 parent ded9a41 commit ad3a936
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 17 additions & 9 deletions packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts
Expand Up @@ -734,6 +734,10 @@ export default async function generateComponentApi(
});
}

if (!reactApi.props) {
reactApi.props = {};
}

// Ignore what we might have generated in `annotateComponentDefinition`
const annotatedDescriptionMatch = reactApi.description.match(/(Demos|API):\r?\n\r?\n/);
if (annotatedDescriptionMatch !== null) {
Expand All @@ -747,6 +751,8 @@ export default async function generateComponentApi(
reactApi.muiName = componentInfo.muiName;
reactApi.apiPathname = componentInfo.apiPathname;
reactApi.EOL = EOL;
reactApi.slots = [];
reactApi.classes = [];
reactApi.demos = componentInfo.getDemos();
if (reactApi.demos.length === 0) {
throw new Error(
Expand All @@ -770,16 +776,18 @@ export default async function generateComponentApi(
}
}

const { slots, classes } = parseSlotsAndClasses({
typescriptProject: project,
projectSettings,
componentName: reactApi.name,
muiName: reactApi.muiName,
slotInterfaceName: componentInfo.slotInterfaceName,
});
if (!projectSettings.skipSlotsAndClasses) {
const { slots, classes } = parseSlotsAndClasses({
typescriptProject: project,
projectSettings,
componentName: reactApi.name,
muiName: reactApi.muiName,
slotInterfaceName: componentInfo.slotInterfaceName,
});

reactApi.slots = slots;
reactApi.classes = classes;
reactApi.slots = slots;
reactApi.classes = classes;
}

attachPropsTable(reactApi, projectSettings.propsSettings);
attachTranslations(reactApi, projectSettings.propsSettings);
Expand Down
4 changes: 4 additions & 0 deletions packages/api-docs-builder/ProjectSettings.ts
Expand Up @@ -60,6 +60,10 @@ export interface ProjectSettings {
* Determine is the component definition should be updated.
*/
skipAnnotatingComponentDefinition?: boolean | ((filename: string) => boolean);
/**
* If `true`, skips extracting CSS class and slot information from the component.
*/
skipSlotsAndClasses?: boolean;
/**
* The path to the translation directory.
*/
Expand Down

0 comments on commit ad3a936

Please sign in to comment.