@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
66 lines • 2.72 kB
text/typescript
import type { DemoClientRequirement } from "./loadNextConfig.mjs";
export interface EnsureDemoClientsOptions {
/** Workspace root used to resolve glob patterns. */
baseDir: string;
/**
* Directory used to resolve relative `requireClient` import specifiers.
* Typically the directory containing `next.config.{js,mjs,ts}`. When
* omitted, defaults to `baseDir`.
*/
configDir?: string;
/** Patterns + import specifiers extracted from next.config. */
requirements: DemoClientRequirement[];
}
export interface EnsureDemoClientsResult {
/** Total number of demo `index.ts` files matched across all patterns. */
demoCount: number;
/** Workspace-relative paths of files that were created or modified. */
updatedFiles: string[];
/** Errors encountered during the run. */
errors: {
filePath: string;
message: string;
}[];
}
/**
* Generates the contents for an auto-created demo `client.ts`.
* Exported for tests and reuse.
*/
export declare function generateClientFileContent(requireClient: string): string;
/**
* Returns the import specifier to use inside an auto-generated `client.ts` for
* a given requirement.
*
* - Bare specifiers (e.g. `@/foo`, `package/x`) pass through unchanged.
* - Relative specifiers (`./foo`, `../foo`) are resolved against `configDir`
* and rewritten to be relative to `clientDir`, ensuring the generated file
* imports the same module regardless of how deep it sits in the workspace.
*/
export declare function resolveRequireClientSpecifier(requireClient: string, configDir: string, clientDir: string): string;
/**
* Result of mutating an `index.ts` file.
*/
export interface IndexUpdate {
/** New file contents, or `null` when the file is already wired correctly. */
content: string | null;
}
/**
* Patches a demo `index.ts` so it imports `ClientProvider` from `./client`
* and passes it through to the `create*` factory call.
*
* Reuses the same `parseCreateFactoryCall` + `serializeFunctionArguments`
* helpers the precomputed code highlighter loader uses, so quirky source
* (trailing commas, comments containing `create*` tokens, multi-line option
* objects) is parsed structurally instead of via ad-hoc regexes.
*
* Exported for tests.
*/
export declare function addClientProviderToIndex(source: string, filePath: string): Promise<IndexUpdate>;
/**
* Ensures every demo `index.ts` matched by the configured demo patterns has a
* sibling `client.ts` and that the `index.ts` wires it up via `ClientProvider`.
*
* Returns the list of files that were created or modified, plus any errors
* encountered.
*/
export declare function ensureDemoClients(options: EnsureDemoClientsOptions): Promise<EnsureDemoClientsResult>;