From 9c1437d6034ef5537c079746761c4c71347f768b Mon Sep 17 00:00:00 2001 From: Shinigami Date: Sat, 15 Oct 2022 03:29:21 +0800 Subject: refactor!: cleanup deprecations (#1440) --- scripts/apidoc.ts | 2 -- scripts/apidoc/apiDocsWriter.ts | 35 +-------------------- scripts/apidoc/directMethods.ts | 68 ----------------------------------------- 3 files changed, 1 insertion(+), 104 deletions(-) delete mode 100644 scripts/apidoc/directMethods.ts (limited to 'scripts') diff --git a/scripts/apidoc.ts b/scripts/apidoc.ts index 0ad01248..921859e7 100644 --- a/scripts/apidoc.ts +++ b/scripts/apidoc.ts @@ -3,7 +3,6 @@ import { writeApiPagesIndex, writeApiSearchIndex, } from './apidoc/apiDocsWriter'; -import { processDirectMethods } from './apidoc/directMethods'; import { processModuleMethods } from './apidoc/moduleMethods'; import { initMarkdownRenderer } from './apidoc/signature'; import type { PageIndex } from './apidoc/utils'; @@ -35,7 +34,6 @@ async function build(): Promise { const modulesPages: PageIndex = []; modulesPages.push(...processModuleMethods(project)); - modulesPages.push(...processDirectMethods(project)); writeApiPagesIndex(modulesPages); writeApiSearchIndex(project); diff --git a/scripts/apidoc/apiDocsWriter.ts b/scripts/apidoc/apiDocsWriter.ts index 74caa425..1f0709bb 100644 --- a/scripts/apidoc/apiDocsWriter.ts +++ b/scripts/apidoc/apiDocsWriter.ts @@ -4,7 +4,6 @@ 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 { @@ -78,37 +77,6 @@ export function writeApiDocsModulePage( writeFileSync(resolve(pathOutputDir, `${lowerModuleName}.md`), content); } -/** - * Writes the api page for the given method to the correct location. - * - * @param methodName The name of the method to write the docs for. - * @param capitalizedMethodName The capitalized name of the method. - */ -export function writeApiDocsDirectPage( - methodName: string, - capitalizedMethodName: string -): void { - let content = ` - - - - - - # ${capitalizedMethodName} - - ## ${methodName} - - - `.replace(/\n +/g, '\n'); - - content = vitePressInFileOptions + formatMarkdown(content); - - writeFileSync(resolve(pathOutputDir, `${methodName}.md`), content); -} - /** * Writes the api docs data to correct location. * @@ -164,9 +132,8 @@ export function writeApiSearchIndex(project: ProjectReflection): void { apiIndex.push(moduleApiSection); const apiModules = selectApiModules(project); - const directMethods = selectDirectMethods(project); - moduleApiSection.items = [...apiModules, ...directMethods] + moduleApiSection.items = apiModules .map((module) => { const moduleName = extractModuleName(module); const apiSection: APIItem = { diff --git a/scripts/apidoc/directMethods.ts b/scripts/apidoc/directMethods.ts deleted file mode 100644 index f8268f5c..00000000 --- a/scripts/apidoc/directMethods.ts +++ /dev/null @@ -1,68 +0,0 @@ -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: ProjectReflection): PageIndex { - const pages: PageIndex = []; - - // Generate direct method files - for (const direct of selectDirectMethods(project)) { - pages.push(processDirectMethod(direct)); - } - - return pages; -} - -/** - * Analyzes and writes the documentation for a direct method such as `faker.fake()`. - * - * @param direct The direct method to process. - * @returns The generated pages. - */ -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 ReflectionType).declaration.signatures; - const signature = signatures[signatures.length - 1]; - - writeApiDocsDirectPage(methodName, capitalizedMethodName); - writeApiDocsData(methodName, [ - analyzeSignature(signature, undefined, methodName), - ]); - - return { - text: capitalizedMethodName, - link: `/api/${methodName}.html`, - }; -} -- cgit v1.2.3