aboutsummaryrefslogtreecommitdiff
path: root/scripts/apidoc/moduleMethods.ts
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-03-01 19:55:53 +0100
committerGitHub <[email protected]>2022-03-01 19:55:53 +0100
commit61fafe47547873fcde74e98bff2a70738df7d4f2 (patch)
tree379432fee1ba309ba1a004bd37af04bba4628a79 /scripts/apidoc/moduleMethods.ts
parent442812f66a5ad9a42e389ad1ae06dbbcddad4e99 (diff)
downloadfaker-61fafe47547873fcde74e98bff2a70738df7d4f2.tar.xz
faker-61fafe47547873fcde74e98bff2a70738df7d4f2.zip
docs: generate docs for fake() and unique() (#564)
Diffstat (limited to 'scripts/apidoc/moduleMethods.ts')
-rw-r--r--scripts/apidoc/moduleMethods.ts67
1 files changed, 67 insertions, 0 deletions
diff --git a/scripts/apidoc/moduleMethods.ts b/scripts/apidoc/moduleMethods.ts
new file mode 100644
index 00000000..89c42a33
--- /dev/null
+++ b/scripts/apidoc/moduleMethods.ts
@@ -0,0 +1,67 @@
+import * as TypeDoc 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 type { PageIndex } from './utils';
+
+/**
+ * Analyzes and writes the documentation for modules and their methods such as `faker.animal.cat()`.
+ *
+ * @param project The project used to extract the modules.
+ * @returns The generated pages.
+ */
+export function processModuleMethods(
+ project: TypeDoc.ProjectReflection
+): PageIndex {
+ const modules = project
+ .getChildrenByKind(TypeDoc.ReflectionKind.Namespace)[0]
+ .getChildrenByKind(TypeDoc.ReflectionKind.Class);
+
+ const pages: PageIndex = [];
+ // Generate module file
+ for (const module of modules) {
+ pages.push(...processModuleMethod(module));
+ }
+
+ return pages;
+}
+
+/**
+ * Analyzes and writes the documentation for a module and its methods such as `faker.animal.cat()`.
+ *
+ * @param direct The module to process.
+ * @returns The generated pages.
+ */
+function processModuleMethod(module: TypeDoc.DeclarationReflection): PageIndex {
+ const moduleName = module.name.replace('_', '');
+ const lowerModuleName =
+ moduleName.substring(0, 1).toLowerCase() + moduleName.substring(1);
+ if (faker[lowerModuleName] === undefined) {
+ return [];
+ }
+ console.log(`Processing Module ${moduleName}`);
+
+ const methods: Method[] = [];
+
+ // Generate method section
+ for (const method of module.getChildrenByKind(
+ TypeDoc.ReflectionKind.Method
+ )) {
+ const methodName = method.name;
+ console.debug(`- ${methodName}`);
+ const signature = method.signatures[0];
+
+ methods.push(analyzeSignature(signature, lowerModuleName, methodName));
+ }
+
+ writeApiDocsModulePage(moduleName, lowerModuleName, toBlock(module.comment));
+ writeApiDocsData(lowerModuleName, methods);
+
+ return [
+ {
+ text: moduleName,
+ link: `/api/${lowerModuleName}.html`,
+ },
+ ];
+}