diff options
| author | ST-DDT <[email protected]> | 2023-01-29 16:35:03 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-29 15:35:03 +0000 |
| commit | ac1a3de17c8840e80fe1609b44e26d287eec952c (patch) | |
| tree | ede991078fd15f25132d806d8b0e1e267e6f95c3 /scripts/apidoc | |
| parent | 0bc6c2fbe65de9a9f706aa6f78f3b07940038461 (diff) | |
| download | faker-ac1a3de17c8840e80fe1609b44e26d287eec952c.tar.xz faker-ac1a3de17c8840e80fe1609b44e26d287eec952c.zip | |
refactor(docs): split generate:api-docs execution from import (#1779)
Diffstat (limited to 'scripts/apidoc')
| -rw-r--r-- | scripts/apidoc/generate.ts | 22 | ||||
| -rw-r--r-- | scripts/apidoc/typedoc.ts | 42 |
2 files changed, 52 insertions, 12 deletions
diff --git a/scripts/apidoc/generate.ts b/scripts/apidoc/generate.ts new file mode 100644 index 00000000..1f7c0016 --- /dev/null +++ b/scripts/apidoc/generate.ts @@ -0,0 +1,22 @@ +import { resolve } from 'path'; +import { writeApiPagesIndex, writeApiSearchIndex } from './apiDocsWriter'; +import { processModuleMethods } from './moduleMethods'; +import { loadProject } from './typedoc'; +import { pathOutputDir } from './utils'; + +const pathOutputJson = resolve(pathOutputDir, 'typedoc.json'); + +/** + * Generates the API documentation. + */ +export async function generate(): Promise<void> { + const [app, project] = loadProject(); + + // Useful for manually analyzing the content + await app.generateJson(project, pathOutputJson); + + const modules = processModuleMethods(project); + writeApiPagesIndex(modules); + + writeApiSearchIndex(project); +} diff --git a/scripts/apidoc/typedoc.ts b/scripts/apidoc/typedoc.ts index d9b34a0b..0ff0906e 100644 --- a/scripts/apidoc/typedoc.ts +++ b/scripts/apidoc/typedoc.ts @@ -4,6 +4,7 @@ import type { DeclarationReflection, ProjectReflection, SignatureReflection, + TypeDocOptions, } from 'typedoc'; import { Application, @@ -20,9 +21,37 @@ import { import { mapByName } from './utils'; /** + * Loads the project using TypeDoc. + * + * @param options The options to use for the project. + * @returns The TypeDoc application and the project reflection. + */ +export function loadProject( + options: Partial<TypeDocOptions> = { + entryPoints: ['src/index.ts'], + pretty: true, + cleanOutputDir: true, + } +): [Application, ProjectReflection] { + const app = newTypeDocApp(); + + app.bootstrap(options); + + const project = app.convert(); + + if (!project) { + throw new Error('Failed to convert project'); + } + + patchProjectParameterDefaults(project); + + return [app, project]; +} + +/** * Creates and configures a new typedoc application. */ -export function newTypeDocApp(): Application { +function newTypeDocApp(): Application { const app = new Application(); app.options.addReader(new TSConfigReader()); @@ -38,17 +67,6 @@ export function newTypeDocApp(): Application { } /** - * Apply our patches to the generated typedoc data. - * - * This is moved to a separate method to allow printing/saving the original content before patching it. - * - * @param project The project to patch. - */ -export function patchProject(project: ProjectReflection): void { - patchProjectParameterDefaults(project); -} - -/** * Selects the modules from the project that needs to be documented. * * @param project The project to extract the modules from. |
