diff options
| author | ST-DDT <[email protected]> | 2022-04-08 20:06:01 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-04-08 18:06:01 +0000 |
| commit | 0dfe9a3bd457b8ceaabd20e67a2a71a6a2cabc9a (patch) | |
| tree | ebcd5510db48666272c3bf12f489df184ccd6e98 /scripts | |
| parent | 753ab66ff5e2fe0d622c4c1722f5213be1ab0315 (diff) | |
| download | faker-0dfe9a3bd457b8ceaabd20e67a2a71a6a2cabc9a.tar.xz faker-0dfe9a3bd457b8ceaabd20e67a2a71a6a2cabc9a.zip | |
docs: nice string literals (#814)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/apidoc/apiDocsWriter.ts | 33 | ||||
| -rw-r--r-- | scripts/apidoc/signature.ts | 4 | ||||
| -rw-r--r-- | scripts/apidoc/utils.ts | 31 |
3 files changed, 44 insertions, 24 deletions
diff --git a/scripts/apidoc/apiDocsWriter.ts b/scripts/apidoc/apiDocsWriter.ts index 5d37585d..f712e4aa 100644 --- a/scripts/apidoc/apiDocsWriter.ts +++ b/scripts/apidoc/apiDocsWriter.ts @@ -1,11 +1,13 @@ import { writeFileSync } from 'node:fs'; import { resolve } from 'node:path'; -import type { Options } from 'prettier'; -import { format } from 'prettier'; -import prettierConfig from '../../.prettierrc.cjs'; import type { Method } from '../../docs/.vitepress/components/api-docs/method'; import type { PageIndex } from './utils'; -import { pathDocsDir, pathOutputDir } from './utils'; +import { + formatMarkdown, + formatTypescript, + pathDocsDir, + pathOutputDir, +} from './utils'; const pathDocsApiPages = resolve(pathDocsDir, '.vitepress', 'api-pages.ts'); @@ -18,21 +20,6 @@ editLink: false `; -const prettierMarkdown: Options = { - ...prettierConfig, - parser: 'markdown', -}; - -const prettierTypescript: Options = { - ...prettierConfig, - parser: 'typescript', -}; - -const prettierBabel: Options = { - ...prettierConfig, - parser: 'babel', -}; - /** * Writes the api page for the given module to the correct location. * @@ -75,7 +62,7 @@ export function writeApiDocsModulePage( <ApiDocsMethod v-for="method of methods" :key="method.name" :method="method" v-once /> `.replace(/\n +/g, '\n'); - content = vitePressInFileOptions + format(content, prettierMarkdown); + content = vitePressInFileOptions + formatMarkdown(content); writeFileSync(resolve(pathOutputDir, lowerModuleName + '.md'), content); } @@ -98,7 +85,7 @@ export function writeApiDocsDirectPage(methodName: string): void { <ApiDocsMethod v-for="method of methods" :key="method.name" :method="method" v-once /> `.replace(/\n +/g, '\n'); - content = vitePressInFileOptions + format(content, prettierMarkdown); + content = vitePressInFileOptions + formatMarkdown(content); writeFileSync(resolve(pathOutputDir, methodName + '.md'), content); } @@ -122,7 +109,7 @@ export const ${lowerModuleName}: Method[] = ${JSON.stringify( 2 )}`; - contentTs = format(contentTs, prettierTypescript); + contentTs = formatTypescript(contentTs); writeFileSync(resolve(pathOutputDir, lowerModuleName + '.ts'), contentTs); } @@ -142,7 +129,7 @@ export function writeApiPagesIndex(pages: PageIndex): void { export const apiPages = ${JSON.stringify(pages)}; `.replace(/\n +/, '\n'); - apiPagesContent = format(apiPagesContent, prettierBabel); + apiPagesContent = formatTypescript(apiPagesContent); writeFileSync(pathDocsApiPages, apiPagesContent); } diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts index dafd2c6d..91691e69 100644 --- a/scripts/apidoc/signature.ts +++ b/scripts/apidoc/signature.ts @@ -15,7 +15,7 @@ import type { MethodParameter, } from '../../docs/.vitepress/components/api-docs/method'; import { faker } from '../../src'; -import { pathOutputDir } from './utils'; +import { formatTypescript, pathOutputDir } from './utils'; // TODO ST-DDT 2022-02-20: Actually import this/fix module import errors // import vitepressConfig from '../../docs/.vitepress/config'; @@ -245,6 +245,8 @@ function typeToText(type_: Type, short = false): string { type.indexType, short )}]`; + case 'literal': + return formatTypescript(type.toString()).replace(/;\n$/, ''); default: return type.toString(); } diff --git a/scripts/apidoc/utils.ts b/scripts/apidoc/utils.ts index 68b69746..732c46a6 100644 --- a/scripts/apidoc/utils.ts +++ b/scripts/apidoc/utils.ts @@ -1,5 +1,8 @@ import { resolve } from 'node:path'; +import type { Options } from 'prettier'; +import { format } from 'prettier'; import * as TypeDoc from 'typedoc'; +import prettierConfig from '../../.prettierrc.cjs'; import { DefaultParameterAwareSerializer, parameterDefaultReader, @@ -44,3 +47,31 @@ export function newTypeDocApp(): TypeDoc.Application { export function patchProject(project: TypeDoc.ProjectReflection): void { patchProjectParameterDefaults(project); } + +/** + * Formats markdown contents. + * + * @param text The text to format. + */ +export function formatMarkdown(text: string): string { + return format(text, prettierMarkdown); +} + +/** + * Formats typedoc contents. + * + * @param text The text to format. + */ +export function formatTypescript(text: string): string { + return format(text, prettierTypescript); +} + +const prettierMarkdown: Options = { + ...prettierConfig, + parser: 'markdown', +}; + +const prettierTypescript: Options = { + ...prettierConfig, + parser: 'typescript', +}; |
