Skip to content

Commit

Permalink
chore(deps): update doc-dependencies (#2037)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: ST-DDT <[email protected]>
  • Loading branch information
renovate[bot] and ST-DDT authored Apr 12, 2023
1 parent 89c4cf3 commit 5b689f9
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 79 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@types/markdown-it": "~12.2.3",
"@types/node": "~18.15.11",
"@types/prettier": "~2.7.2",
"@types/react": "~18.0.32",
"@types/react": "~18.0.35",
"@types/sanitize-html": "~2.9.0",
"@types/semver": "~7.3.13",
"@types/validator": "~13.7.14",
Expand Down Expand Up @@ -123,12 +123,12 @@
"semver": "~7.4.0",
"standard-version": "~9.5.0",
"tsx": "~3.12.6",
"typedoc": "~0.23.28",
"typedoc": "~0.24.1",
"typedoc-plugin-missing-exports": "~1.0.0",
"typescript": "~4.9.5",
"validator": "~13.9.0",
"vite": "~4.2.1",
"vitepress": "1.0.0-alpha.64",
"vitepress": "1.0.0-alpha.65",
"vitest": "~0.30.1",
"vue": "~3.2.47"
},
Expand Down
40 changes: 20 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion scripts/apidoc/apiDocsWriter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 } from '../../docs/api/api-types';
import { formatMarkdown, formatTypescript } from './format';
Expand Down Expand Up @@ -216,7 +217,9 @@ export function writeApiSearchIndex(pages: ModuleSummary[]): void {
* @param project The typedoc project.
*/
export function writeSourceBaseUrl(project: ProjectReflection): void {
const baseUrl = extractSourceBaseUrl(project);
const baseUrl = extractSourceBaseUrl(
project.getChildrenByKind(ReflectionKind.Class)[0]
);

let content = `
// This file is automatically generated.
Expand Down
4 changes: 2 additions & 2 deletions scripts/apidoc/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import vitepressConfig from '../../docs/.vitepress/config';
import { formatTypescript } from './format';
import {
extractDeprecated,
extractRawDefault,
extractRawExamples,
extractSeeAlsos,
extractSince,
extractSourcePath,
joinTagContent,
joinTagParts,
} from './typedoc';
import { pathOutputDir } from './utils';
Expand Down Expand Up @@ -382,7 +382,7 @@ function extractDefaultFromComment(comment?: Comment): string | undefined {

const defaultTag = comment.getTag('@default');
if (defaultTag) {
return joinTagContent(defaultTag).join().trim();
return extractRawDefault({ comment });
}

const summary = comment.summary;
Expand Down
54 changes: 43 additions & 11 deletions scripts/apidoc/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
} from './parameterDefaults';
import { mapByName } from './utils';

type CommentHolder = Pick<Reflection, 'comment'>;

/**
* Loads the project using TypeDoc.
*
Expand Down Expand Up @@ -152,7 +154,9 @@ export function extractModuleFieldName(module: DeclarationReflection): string {
*
* @param reflection The reflection instance to extract the source url from.
*/
function extractSourceUrl(reflection: Reflection): string {
function extractSourceUrl(
reflection: DeclarationReflection | SignatureReflection
): string {
const source = reflection.sources?.[0];
return source?.url ?? '';
}
Expand All @@ -162,7 +166,9 @@ function extractSourceUrl(reflection: Reflection): string {
*
* @param reflection The reflection instance to extract the source base url from.
*/
export function extractSourceBaseUrl(reflection: Reflection): string {
export function extractSourceBaseUrl(
reflection: DeclarationReflection | SignatureReflection
): string {
return extractSourceUrl(reflection).replace(
/^(.*\/blob\/[0-9a-f]+\/)(.*)$/,
'$1'
Expand All @@ -174,7 +180,9 @@ export function extractSourceBaseUrl(reflection: Reflection): string {
*
* @param reflection The reflection instance to extract the source path from.
*/
export function extractSourcePath(reflection: Reflection): string {
export function extractSourcePath(
reflection: DeclarationReflection | SignatureReflection
): string {
return extractSourceUrl(reflection).replace(
/^(.*\/blob\/[0-9a-f]+\/)(.*)$/,
'$2'
Expand All @@ -189,29 +197,51 @@ export function extractSourcePath(reflection: Reflection): string {
*/
export function extractTagContent(
tag: `@${string}`,
reflection?: Reflection,
reflection?: CommentHolder,
tagProcessor: (tag: CommentTag) => string[] = joinTagContent
): string[] {
return reflection?.comment?.getTags(tag).flatMap(tagProcessor) ?? [];
}

/**
* Extracts the examples from the jsdocs without the surrounding md code block.
* Extracts the raw code from the jsdocs without the surrounding md code block.
*
* @param reflection The reflection to extract the examples from.
* @param tag The tag to extract the code from.
* @param reflection The reflection to extract the code from.
*/
export function extractRawExamples(reflection?: Reflection): string[] {
return extractTagContent('@example', reflection).map((tag) =>
function extractRawCode(
tag: `@${string}`,
reflection?: CommentHolder
): string[] {
return extractTagContent(tag, reflection).map((tag) =>
tag.replace(/^```ts\n/, '').replace(/\n```$/, '')
);
}

/**
* Extracts the default from the jsdocs without the surrounding md code block.
*
* @param reflection The reflection to extract the examples from.
*/
export function extractRawDefault(reflection?: CommentHolder): string {
return extractRawCode('@default', reflection)[0] ?? '';
}

/**
* Extracts the examples from the jsdocs without the surrounding md code block.
*
* @param reflection The reflection to extract the examples from.
*/
export function extractRawExamples(reflection?: CommentHolder): string[] {
return extractRawCode('@example', reflection);
}

/**
* Extracts all the `@see` references from the jsdocs separately.
*
* @param reflection The reflection to extract the see also references from.
*/
export function extractSeeAlsos(reflection?: Reflection): string[] {
export function extractSeeAlsos(reflection?: CommentHolder): string[] {
return extractTagContent('@see', reflection, (tag) =>
// If the @see tag contains code in backticks, the content is split into multiple parts.
// So we join together, split on newlines and filter out empty tags.
Expand Down Expand Up @@ -249,7 +279,9 @@ export function joinTagParts(parts?: CommentDisplayPart[]): string | undefined {
*
* @returns The message explaining the deprecation if deprecated, otherwise `undefined`.
*/
export function extractDeprecated(reflection?: Reflection): string | undefined {
export function extractDeprecated(
reflection?: CommentHolder
): string | undefined {
const deprecated = extractTagContent('@deprecated', reflection).join().trim();
return deprecated.length === 0 ? undefined : deprecated;
}
Expand All @@ -261,6 +293,6 @@ export function extractDeprecated(reflection?: Reflection): string | undefined {
*
* @returns The contents of the `@since` tag.
*/
export function extractSince(reflection: Reflection): string {
export function extractSince(reflection: CommentHolder): string {
return extractTagContent('@since', reflection).join().trim();
}
Loading

0 comments on commit 5b689f9

Please sign in to comment.