aboutsummaryrefslogtreecommitdiff
path: root/scripts
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
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')
-rw-r--r--scripts/apidoc/directMethods.ts43
-rw-r--r--scripts/apidoc/moduleMethods.ts62
2 files changed, 65 insertions, 40 deletions
diff --git a/scripts/apidoc/directMethods.ts b/scripts/apidoc/directMethods.ts
index fbdd094e..f8268f5c 100644
--- a/scripts/apidoc/directMethods.ts
+++ b/scripts/apidoc/directMethods.ts
@@ -1,26 +1,40 @@
-import * as TypeDoc from 'typedoc';
+import type {
+ DeclarationReflection,
+ ProjectReflection,
+ ReflectionType,
+} from 'typedoc';
+import { ReflectionKind } from 'typedoc';
import { writeApiDocsData, writeApiDocsDirectPage } from './apiDocsWriter';
import { analyzeSignature } from './signature';
import type { Page, PageIndex } from './utils';
/**
+ * Selects the direct methods from the project that needs to be documented.
+ *
+ * @param project The project used to extract the direct methods.
+ * @returns The direct methods to document.
+ */
+export function selectDirectMethods(
+ project: ProjectReflection
+): DeclarationReflection[] {
+ return project
+ .getChildrenByKind(ReflectionKind.Class)
+ .filter((ref) => ref.name === 'Faker')[0]
+ .getChildrenByKind(ReflectionKind.Property)
+ .filter((ref) => ['fake', 'unique'].includes(ref.name));
+}
+
+/**
* Analyzes and writes the documentation for direct methods such as `faker.fake()`.
*
* @param project The project used to extract the direct methods.
* @returns The generated pages.
*/
-export function processDirectMethods(
- project: TypeDoc.ProjectReflection
-): PageIndex {
+export function processDirectMethods(project: ProjectReflection): PageIndex {
const pages: PageIndex = [];
- const directs = project
- .getChildrenByKind(TypeDoc.ReflectionKind.Class)
- .filter((ref) => ref.name === 'Faker')[0]
- .getChildrenByKind(TypeDoc.ReflectionKind.Property)
- .filter((ref) => ['fake', 'unique'].includes(ref.name));
-
- for (const direct of directs) {
+ // Generate direct method files
+ for (const direct of selectDirectMethods(project)) {
pages.push(processDirectMethod(direct));
}
@@ -33,16 +47,13 @@ export function processDirectMethods(
* @param direct The direct method to process.
* @returns The generated pages.
*/
-export function processDirectMethod(
- direct: TypeDoc.DeclarationReflection
-): Page {
+export function processDirectMethod(direct: DeclarationReflection): Page {
const methodName = direct.name;
const capitalizedMethodName =
methodName.substring(0, 1).toUpperCase() + methodName.substring(1);
console.log(`Processing Direct: ${capitalizedMethodName}`);
- const signatures = (direct.type as TypeDoc.ReflectionType).declaration
- .signatures;
+ const signatures = (direct.type as ReflectionType).declaration.signatures;
const signature = signatures[signatures.length - 1];
writeApiDocsDirectPage(methodName, capitalizedMethodName);
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`,
},
];
}