aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-01-29 16:35:03 +0100
committerGitHub <[email protected]>2023-01-29 15:35:03 +0000
commitac1a3de17c8840e80fe1609b44e26d287eec952c (patch)
treeede991078fd15f25132d806d8b0e1e267e6f95c3 /scripts
parent0bc6c2fbe65de9a9f706aa6f78f3b07940038461 (diff)
downloadfaker-ac1a3de17c8840e80fe1609b44e26d287eec952c.tar.xz
faker-ac1a3de17c8840e80fe1609b44e26d287eec952c.zip
refactor(docs): split generate:api-docs execution from import (#1779)
Diffstat (limited to 'scripts')
-rw-r--r--scripts/apidoc.ts38
-rw-r--r--scripts/apidoc/generate.ts22
-rw-r--r--scripts/apidoc/typedoc.ts42
3 files changed, 54 insertions, 48 deletions
diff --git a/scripts/apidoc.ts b/scripts/apidoc.ts
index 352ec978..3c448f8b 100644
--- a/scripts/apidoc.ts
+++ b/scripts/apidoc.ts
@@ -1,45 +1,11 @@
-import { resolve } from 'path';
import { faker } from '../src';
-import {
- writeApiPagesIndex,
- writeApiSearchIndex,
-} from './apidoc/apiDocsWriter';
-import { processModuleMethods } from './apidoc/moduleMethods';
+import { generate } from './apidoc/generate';
import { initMarkdownRenderer } from './apidoc/signature';
-import { newTypeDocApp, patchProject } from './apidoc/typedoc';
-import type { PageIndex } from './apidoc/utils';
-import { pathOutputDir } from './apidoc/utils';
-
-const pathOutputJson = resolve(pathOutputDir, 'typedoc.json');
async function build(): Promise<void> {
await initMarkdownRenderer();
faker.setDefaultRefDate(Date.UTC(2023, 0, 1));
-
- const app = newTypeDocApp();
-
- app.bootstrap({
- entryPoints: ['src/index.ts'],
- pretty: true,
- cleanOutputDir: true,
- });
-
- const project = app.convert();
-
- if (!project) {
- throw new Error('Failed to convert project');
- }
-
- // Useful for manually analyzing the content
- await app.generateJson(project, pathOutputJson);
-
- patchProject(project);
-
- const modulesPages: PageIndex = [];
- modulesPages.push(...processModuleMethods(project));
- writeApiPagesIndex(modulesPages);
-
- writeApiSearchIndex(project);
+ await generate();
}
build().catch(console.error);
diff --git a/scripts/apidoc/generate.ts b/scripts/apidoc/generate.ts
new file mode 100644
index 00000000..1f7c0016
--- /dev/null
+++ b/scripts/apidoc/generate.ts
@@ -0,0 +1,22 @@
+import { resolve } from 'path';
+import { writeApiPagesIndex, writeApiSearchIndex } from './apiDocsWriter';
+import { processModuleMethods } from './moduleMethods';
+import { loadProject } from './typedoc';
+import { pathOutputDir } from './utils';
+
+const pathOutputJson = resolve(pathOutputDir, 'typedoc.json');
+
+/**
+ * Generates the API documentation.
+ */
+export async function generate(): Promise<void> {
+ const [app, project] = loadProject();
+
+ // Useful for manually analyzing the content
+ await app.generateJson(project, pathOutputJson);
+
+ const modules = processModuleMethods(project);
+ writeApiPagesIndex(modules);
+
+ writeApiSearchIndex(project);
+}
diff --git a/scripts/apidoc/typedoc.ts b/scripts/apidoc/typedoc.ts
index d9b34a0b..0ff0906e 100644
--- a/scripts/apidoc/typedoc.ts
+++ b/scripts/apidoc/typedoc.ts
@@ -4,6 +4,7 @@ import type {
DeclarationReflection,
ProjectReflection,
SignatureReflection,
+ TypeDocOptions,
} from 'typedoc';
import {
Application,
@@ -20,9 +21,37 @@ import {
import { mapByName } from './utils';
/**
+ * Loads the project using TypeDoc.
+ *
+ * @param options The options to use for the project.
+ * @returns The TypeDoc application and the project reflection.
+ */
+export function loadProject(
+ options: Partial<TypeDocOptions> = {
+ entryPoints: ['src/index.ts'],
+ pretty: true,
+ cleanOutputDir: true,
+ }
+): [Application, ProjectReflection] {
+ const app = newTypeDocApp();
+
+ app.bootstrap(options);
+
+ const project = app.convert();
+
+ if (!project) {
+ throw new Error('Failed to convert project');
+ }
+
+ patchProjectParameterDefaults(project);
+
+ return [app, project];
+}
+
+/**
* Creates and configures a new typedoc application.
*/
-export function newTypeDocApp(): Application {
+function newTypeDocApp(): Application {
const app = new Application();
app.options.addReader(new TSConfigReader());
@@ -38,17 +67,6 @@ export function newTypeDocApp(): Application {
}
/**
- * 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: ProjectReflection): void {
- patchProjectParameterDefaults(project);
-}
-
-/**
* Selects the modules from the project that needs to be documented.
*
* @param project The project to extract the modules from.