diff options
Diffstat (limited to 'scripts/apidoc/moduleMethods.ts')
| -rw-r--r-- | scripts/apidoc/moduleMethods.ts | 47 |
1 files changed, 9 insertions, 38 deletions
diff --git a/scripts/apidoc/moduleMethods.ts b/scripts/apidoc/moduleMethods.ts index dd4f528a..b52d4780 100644 --- a/scripts/apidoc/moduleMethods.ts +++ b/scripts/apidoc/moduleMethods.ts @@ -1,26 +1,16 @@ import type { DeclarationReflection, ProjectReflection } from 'typedoc'; -import { ReflectionKind } from 'typedoc'; import type { Method } from '../../docs/.vitepress/components/api-docs/method'; -import { faker } from '../../src'; import { writeApiDocsData, writeApiDocsModulePage } from './apiDocsWriter'; import { analyzeSignature, toBlock } from './signature'; +import { + extractModuleFieldName, + extractModuleName, + selectApiMethodSignatures, + selectApiModules, +} from './typedoc'; import type { PageIndex } from './utils'; /** - * Selects the modules from the project that needs to be documented. - * - * @param project The project used to extract the modules. - * @returns The modules to document. - */ -export function selectApiModules( - project: ProjectReflection -): DeclarationReflection[] { - return project - .getChildrenByKind(ReflectionKind.Class) - .filter((module) => faker[extractModuleFieldName(module)] != null); -} - -/** * Analyzes and writes the documentation for modules and their methods such as `faker.animal.cat()`. * * @param project The project used to extract the modules. @@ -37,24 +27,6 @@ export function processModuleMethods(project: ProjectReflection): PageIndex { return pages; } -export function extractModuleName(module: DeclarationReflection): string { - const { name } = module; - // TODO @ST-DDT 2022-10-16: Remove in v10. - // Typedoc prefers the name of the module that is exported first. - if (name === 'AddressModule') { - return 'Location'; - } else if (name === 'NameModule') { - return 'Person'; - } - - return name.replace(/Module$/, ''); -} - -function extractModuleFieldName(module: DeclarationReflection): string { - const moduleName = extractModuleName(module); - return moduleName.substring(0, 1).toLowerCase() + moduleName.substring(1); -} - /** * Analyzes and writes the documentation for a module and its methods such as `faker.animal.cat()`. * @@ -69,11 +41,10 @@ function processModuleMethod(module: DeclarationReflection): PageIndex { const methods: Method[] = []; // Generate method section - for (const method of module.getChildrenByKind(ReflectionKind.Method)) { - const methodName = method.name; + for (const [methodName, signature] of Object.entries( + selectApiMethodSignatures(module) + )) { console.debug(`- ${methodName}`); - const signatures = method.signatures; - const signature = signatures[signatures.length - 1]; methods.push(analyzeSignature(signature, moduleFieldName, methodName)); } |
