import type { DeclarationReflection, ProjectReflection } from 'typedoc'; import { ReflectionKind } from 'typedoc'; import type { Method } from '../../docs/.vitepress/components/api-docs/method'; import { writeApiDocsModule } from './apiDocsWriter'; import { analyzeModule, processModuleMethods } from './moduleMethods'; import { analyzeSignature } from './signature'; import { extractModuleFieldName, selectApiSignature } from './typedoc'; import type { ModuleSummary } from './utils'; export async function processFakerClasses( project: ProjectReflection ): Promise { const fakerClasses = project .getChildrenByKind(ReflectionKind.Class) .filter((clazz) => clazz.name === 'Faker' || clazz.name === 'SimpleFaker'); if (fakerClasses.length !== 2) { throw new Error('Faker classes not found'); } return Promise.all(fakerClasses.map(processClass)); } export async function processFakerRandomizer( project: ProjectReflection ): Promise { const randomizerClass = project .getChildrenByKind(ReflectionKind.Interface) .find((clazz) => clazz.name === 'Randomizer'); return processClass(randomizerClass); } async function processClass( clazz: DeclarationReflection ): Promise { const { name } = clazz; const moduleFieldName = extractModuleFieldName(clazz); console.log(`Processing ${name} class`); const { comment, deprecated, examples } = analyzeModule(clazz); const methods: Method[] = []; if (hasConstructor(clazz)) { console.debug(`- constructor`); methods.push(await processConstructor(clazz)); } methods.push(...(await processModuleMethods(clazz, `${moduleFieldName}.`))); return writeApiDocsModule( name, moduleFieldName, comment, examples, deprecated, methods ); } function hasConstructor(clazz: DeclarationReflection): boolean { return clazz .getChildrenByKind(ReflectionKind.Constructor) .some((constructor) => constructor.signatures.length > 0); } async function processConstructor( clazz: DeclarationReflection ): Promise { const constructor = clazz.getChildrenByKind(ReflectionKind.Constructor)[0]; const signature = selectApiSignature(constructor); const method = await analyzeSignature(signature, '', `new ${clazz.name}`); return { ...method, name: 'constructor', }; }