Skip to content

Commit

Permalink
[code-infra] Allow customizing hooks imports in API docs generator (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak authored Apr 11, 2024
1 parent 47b624d commit 802a586
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/api-docs-builder/ApiBuilders/HookApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ const extractInfoFromType = async (
* @param filename The filename where its defined (to infer the package)
* @returns an array of import command
*/
const getHookImports = (name: string, filename: string) => {
const defaultGetHookImports = (name: string, filename: string) => {
const githubPath = toGitHubPath(filename);
const rootImportPath = githubPath.replace(
/\/packages\/mui(?:-(.+?))?\/src\/.*/,
Expand Down Expand Up @@ -552,6 +552,8 @@ export default async function generateHookApi(
if (annotatedDescriptionMatch !== null) {
reactApi.description = reactApi.description.slice(0, annotatedDescriptionMatch.index).trim();
}

const { getHookImports = defaultGetHookImports } = projectSettings;
reactApi.filename = filename;
reactApi.name = name;
reactApi.imports = getHookImports(name, filename);
Expand Down
6 changes: 5 additions & 1 deletion packages/api-docs-builder/ProjectSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ export interface ProjectSettings {
*/
importTranslationPagesDirectory?: string;
/**
* Returns an array of import commands used for the API page header.
* Returns an array of import commands used for the component API page header.
*/
getComponentImports?: (name: string, filename: string) => string[];
/**
* Returns an array of import commands used for the hook API page header.
*/
getHookImports?: (name: string, filename: string) => string[];
/**
* Settings to configure props definition tests.
*/
Expand Down

0 comments on commit 802a586

Please sign in to comment.