diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/apidoc.ts | 38 | ||||
| -rw-r--r-- | scripts/apidoc/generate.ts | 22 | ||||
| -rw-r--r-- | scripts/apidoc/typedoc.ts | 42 |
3 files changed, 54 insertions, 48 deletions
diff --git a/scripts/apidoc.ts b/scripts/apidoc.ts index 352ec978..3c448f8b 100644 --- a/scripts/apidoc.ts +++ b/scripts/apidoc.ts @@ -1,45 +1,11 @@ -import { resolve } from 'path'; import { faker } from '../src'; -import { - writeApiPagesIndex, - writeApiSearchIndex, -} from './apidoc/apiDocsWriter'; -import { processModuleMethods } from './apidoc/moduleMethods'; +import { generate } from './apidoc/generate'; import { initMarkdownRenderer } from './apidoc/signature'; -import { newTypeDocApp, patchProject } from './apidoc/typedoc'; -import type { PageIndex } from './apidoc/utils'; -import { pathOutputDir } from './apidoc/utils'; - -const pathOutputJson = resolve(pathOutputDir, 'typedoc.json'); async function build(): Promise<void> { await initMarkdownRenderer(); faker.setDefaultRefDate(Date.UTC(2023, 0, 1)); - - const app = newTypeDocApp(); - - app.bootstrap({ - entryPoints: ['src/index.ts'], - pretty: true, - cleanOutputDir: true, - }); - - const project = app.convert(); - - if (!project) { - throw new Error('Failed to convert project'); - } - - // Useful for manually analyzing the content - await app.generateJson(project, pathOutputJson); - - patchProject(project); - - const modulesPages: PageIndex = []; - modulesPages.push(...processModuleMethods(project)); - writeApiPagesIndex(modulesPages); - - writeApiSearchIndex(project); + await generate(); } build().catch(console.error); 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. |
