aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/apidoc.ts11
-rw-r--r--scripts/apidoc/apiDocsWriter.ts57
-rw-r--r--scripts/apidoc/moduleMethods.ts2
3 files changed, 68 insertions, 2 deletions
diff --git a/scripts/apidoc.ts b/scripts/apidoc.ts
index ed6f679f..165034bc 100644
--- a/scripts/apidoc.ts
+++ b/scripts/apidoc.ts
@@ -1,5 +1,8 @@
import { resolve } from 'path';
-import { writeApiPagesIndex } from './apidoc/apiDocsWriter';
+import {
+ writeApiPagesIndex,
+ writeApiSearchIndex,
+} from './apidoc/apiDocsWriter';
import { processDirectMethods } from './apidoc/directMethods';
import { processModuleMethods } from './apidoc/moduleMethods';
import { initMarkdownRenderer } from './apidoc/signature';
@@ -21,6 +24,10 @@ async function build(): Promise<void> {
const project = app.convert();
+ if (!project) {
+ throw new Error('Failed to convert project');
+ }
+
// Useful for manually analyzing the content
await app.generateJson(project, pathOutputJson);
@@ -31,6 +38,8 @@ async function build(): Promise<void> {
modulesPages.push(...processModuleMethods(project));
modulesPages.push(...processDirectMethods(project));
writeApiPagesIndex(modulesPages);
+
+ writeApiSearchIndex(project);
}
build().catch(console.error);
diff --git a/scripts/apidoc/apiDocsWriter.ts b/scripts/apidoc/apiDocsWriter.ts
index 76edc3c3..99193242 100644
--- a/scripts/apidoc/apiDocsWriter.ts
+++ b/scripts/apidoc/apiDocsWriter.ts
@@ -1,6 +1,11 @@
import { writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
+import type { ProjectReflection } from 'typedoc';
+import { ReflectionKind } from 'typedoc';
import type { Method } from '../../docs/.vitepress/components/api-docs/method';
+import type { APIGroup, APIItem } from '../../docs/api/api-types';
+import { selectDirectMethods } from './directMethods';
+import { extractModuleName, selectApiModules } from './moduleMethods';
import type { PageIndex } from './utils';
import {
formatMarkdown,
@@ -10,6 +15,11 @@ import {
} from './utils';
const pathDocsApiPages = resolve(pathDocsDir, '.vitepress', 'api-pages.ts');
+const pathDocsApiSearchIndex = resolve(
+ pathDocsDir,
+ 'api',
+ 'api-search-index.json'
+);
const scriptCommand = 'pnpm run generate:api-docs';
@@ -141,3 +151,50 @@ export function writeApiPagesIndex(pages: PageIndex): void {
writeFileSync(pathDocsApiPages, apiPagesContent);
}
+
+export function writeApiSearchIndex(project: ProjectReflection): void {
+ const apiIndex: APIGroup[] = [];
+
+ const moduleApiSection: APIGroup = {
+ text: 'Module API',
+ items: [],
+ };
+
+ apiIndex.push(moduleApiSection);
+
+ const apiModules = selectApiModules(project);
+ const directMethods = selectDirectMethods(project);
+
+ moduleApiSection.items = [...apiModules, ...directMethods]
+ .map((module) => {
+ const apiSection: APIItem = {
+ text: extractModuleName(module),
+ link: module.name.toLowerCase(),
+ headers: [],
+ };
+ if (module.kind !== ReflectionKind.Property) {
+ apiSection.headers = module
+ .getChildrenByKind(ReflectionKind.Method)
+ .map((child) => ({
+ anchor: child.name,
+ text: child.name,
+ }));
+ } else {
+ // TODO @Shinigami92 2022-08-17: Extract capitalization into own function
+ apiSection.text =
+ apiSection.text.substring(0, 1).toUpperCase() +
+ apiSection.text.substring(1);
+
+ apiSection.headers = [
+ {
+ anchor: module.name,
+ text: module.name,
+ },
+ ];
+ }
+ return apiSection;
+ })
+ .sort((a, b) => a.text.localeCompare(b.text));
+
+ writeFileSync(pathDocsApiSearchIndex, JSON.stringify(apiIndex));
+}
diff --git a/scripts/apidoc/moduleMethods.ts b/scripts/apidoc/moduleMethods.ts
index a37bcae0..d5b8f590 100644
--- a/scripts/apidoc/moduleMethods.ts
+++ b/scripts/apidoc/moduleMethods.ts
@@ -38,7 +38,7 @@ export function processModuleMethods(project: ProjectReflection): PageIndex {
return pages;
}
-function extractModuleName(module: DeclarationReflection): string {
+export function extractModuleName(module: DeclarationReflection): string {
return module.name.replace('_', '');
}