Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[code-infra] Adapt API code generator to Base UI repo needs #41475

Merged
merged 1 commit into from Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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