aboutsummaryrefslogtreecommitdiff
path: root/scripts/apidoc/fakerClass.ts
blob: f8de8653af35f028ef226056d062f33c3aa26e30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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 { selectApiSignature } from './typedoc';
import type { ModuleSummary } from './utils';

export function processFakerClass(project: ProjectReflection): ModuleSummary {
  const fakerClass = project
    .getChildrenByKind(ReflectionKind.Class)
    .filter((clazz) => clazz.name === 'Faker')[0];

  if (!fakerClass) {
    throw new Error('Faker class not found');
  }

  return processClass(fakerClass);
}

function processClass(fakerClass: DeclarationReflection): ModuleSummary {
  console.log(`Processing Faker class`);
  const { comment, deprecated } = analyzeModule(fakerClass);
  const methods: Method[] = [];

  console.debug(`- constructor`);
  methods.push(processConstructor(fakerClass));

  methods.push(...processModuleMethods(fakerClass, 'faker.'));

  return writeApiDocsModule('Faker', 'faker', comment, deprecated, methods);
}

function processConstructor(fakerClass: DeclarationReflection): Method {
  const constructor = fakerClass.getChildrenByKind(
    ReflectionKind.Constructor
  )[0];

  const signature = selectApiSignature(constructor);

  const method = analyzeSignature(signature, '', 'new Faker');

  return {
    ...method,
    name: 'constructor',
  };
}