aboutsummaryrefslogtreecommitdiff
path: root/scripts/apidoc/moduleMethods.ts
diff options
context:
space:
mode:
authorrenovate[bot] <29139614+renovate[bot]@users.noreply.github.com>2022-08-16 09:05:35 +0000
committerGitHub <[email protected]>2022-08-16 09:05:35 +0000
commit47f7fc9b1914ce6a78575522aa0168a53f6248e6 (patch)
tree3c7663ebb628a47d3ebb6b9297996e5567671514 /scripts/apidoc/moduleMethods.ts
parent5dd30f33c0f3135a2d47c7d5f5a2d51c78774c0d (diff)
downloadfaker-47f7fc9b1914ce6a78575522aa0168a53f6248e6.tar.xz
faker-47f7fc9b1914ce6a78575522aa0168a53f6248e6.zip
chore(deps): update dependency typedoc-plugin-missing-exports to v1 (#1272)
* chore(deps): update dependency typedoc-plugin-missing-exports to v1 * docs: update api-docs generator Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: ST-DDT <[email protected]>
Diffstat (limited to 'scripts/apidoc/moduleMethods.ts')
-rw-r--r--scripts/apidoc/moduleMethods.ts62
1 files changed, 38 insertions, 24 deletions
diff --git a/scripts/apidoc/moduleMethods.ts b/scripts/apidoc/moduleMethods.ts
index 64f6ed1b..a37bcae0 100644
--- a/scripts/apidoc/moduleMethods.ts
+++ b/scripts/apidoc/moduleMethods.ts
@@ -1,4 +1,5 @@
-import * as TypeDoc from 'typedoc';
+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';
@@ -6,68 +7,81 @@ import { analyzeSignature, toBlock } from './signature';
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.Module)[0]
+ .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.
* @returns The generated pages.
*/
-export function processModuleMethods(
- project: TypeDoc.ProjectReflection
-): PageIndex {
- const modules = project
- .getChildrenByKind(TypeDoc.ReflectionKind.Namespace)[0]
- .getChildrenByKind(TypeDoc.ReflectionKind.Class);
-
+export function processModuleMethods(project: ProjectReflection): PageIndex {
const pages: PageIndex = [];
- // Generate module file
- for (const module of modules) {
+
+ // Generate module files
+ for (const module of selectApiModules(project)) {
pages.push(...processModuleMethod(module));
}
return pages;
}
+function extractModuleName(module: DeclarationReflection): string {
+ return module.name.replace('_', '');
+}
+
+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()`.
*
* @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 [];
- }
+function processModuleMethod(module: DeclarationReflection): PageIndex {
+ const moduleName = extractModuleName(module);
+ const moduleFieldName = extractModuleFieldName(module);
console.log(`Processing Module ${moduleName}`);
const methods: Method[] = [];
// Generate method section
- for (const method of module.getChildrenByKind(
- TypeDoc.ReflectionKind.Method
- )) {
+ for (const method of module.getChildrenByKind(ReflectionKind.Method)) {
const methodName = method.name;
console.debug(`- ${methodName}`);
const signatures = method.signatures;
const signature = signatures[signatures.length - 1];
- methods.push(analyzeSignature(signature, lowerModuleName, methodName));
+ methods.push(analyzeSignature(signature, moduleFieldName, methodName));
}
writeApiDocsModulePage(
moduleName,
- lowerModuleName,
+ moduleFieldName,
toBlock(module.comment),
methods
);
- writeApiDocsData(lowerModuleName, methods);
+ writeApiDocsData(moduleFieldName, methods);
return [
{
text: moduleName,
- link: `/api/${lowerModuleName}.html`,
+ link: `/api/${moduleFieldName}.html`,
},
];
}