aboutsummaryrefslogtreecommitdiff
path: root/scripts/apidoc
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-04-07 16:08:09 +0200
committerGitHub <[email protected]>2022-04-07 16:08:09 +0200
commit5aa8eeb3649955bf03239e93c4b87b1bc874cb2e (patch)
treea2c33ddc66ff7a313e7ae40ff6d175e2fcc0644b /scripts/apidoc
parent81171c9f9f2e548f9a86eaae3683ead7e28dbd72 (diff)
downloadfaker-5aa8eeb3649955bf03239e93c4b87b1bc874cb2e.tar.xz
faker-5aa8eeb3649955bf03239e93c4b87b1bc874cb2e.zip
test: add parameter defaults to our signature generation test (#793)
Diffstat (limited to 'scripts/apidoc')
-rw-r--r--scripts/apidoc/utils.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/apidoc/utils.ts b/scripts/apidoc/utils.ts
index ee38d58d..68b69746 100644
--- a/scripts/apidoc/utils.ts
+++ b/scripts/apidoc/utils.ts
@@ -1,4 +1,10 @@
import { resolve } from 'node:path';
+import * as TypeDoc from 'typedoc';
+import {
+ DefaultParameterAwareSerializer,
+ parameterDefaultReader,
+ patchProjectParameterDefaults,
+} from './parameterDefaults';
export type Page = { text: string; link: string };
export type PageIndex = Array<Page>;
@@ -6,3 +12,35 @@ export type PageIndex = Array<Page>;
const pathRoot = resolve(__dirname, '..', '..');
export const pathDocsDir = resolve(pathRoot, 'docs');
export const pathOutputDir = resolve(pathDocsDir, 'api');
+
+/**
+ * Creates and configures a new typedoc application.
+ */
+export function newTypeDocApp(): TypeDoc.Application {
+ const app = new TypeDoc.Application();
+
+ app.options.addReader(new TypeDoc.TSConfigReader());
+ // If you want TypeDoc to load typedoc.json files
+ //app.options.addReader(new TypeDoc.TypeDocReader());
+
+ // Read parameter defaults
+ app.converter.on(
+ TypeDoc.Converter.EVENT_CREATE_DECLARATION,
+ parameterDefaultReader
+ );
+ // Add to debug json output
+ app.serializer.addSerializer(new DefaultParameterAwareSerializer(undefined));
+
+ return app;
+}
+
+/**
+ * Apply our patches to the generated typedoc data.
+ *
+ * This is moved to a separate method to allow printing/saving the original content before patching it.
+ *
+ * @param project The project to patch.
+ */
+export function patchProject(project: TypeDoc.ProjectReflection): void {
+ patchProjectParameterDefaults(project);
+}