Skip to content

Commit

Permalink
docs: show deprecation message (#1889)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Mayer authored Mar 4, 2023
1 parent 8a97cac commit 8592928
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/components/api-docs/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface Method {
readonly parameters: MethodParameter[];
readonly returns: string;
readonly examples: string; // HTML
readonly deprecated: boolean;
readonly deprecated?: string; // HTML
readonly since: string;
readonly sourcePath: string; // URL-Suffix
readonly seeAlsos: string[];
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/components/api-docs/method.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function seeAlsoToUrl(see: string): string {
<div v-if="props.method.deprecated" class="warning custom-block">
<p class="custom-block-title">Deprecated</p>
<p>This method is deprecated and will be removed in a future version.</p>
<span v-html="props.method.deprecated" />
</div>

<div v-html="props.method.description"></div>
Expand Down
9 changes: 6 additions & 3 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 { faker } from '../../src';
import { formatTypescript } from './format';
import {
extractDeprecated,
extractRawExamples,
extractSeeAlsos,
extractSince,
extractSourcePath,
isDeprecated,
joinTagParts,
} from './typedoc';
import { pathOutputDir } from './utils';
Expand Down Expand Up @@ -178,7 +178,10 @@ export function analyzeSignature(
const seeAlsos = extractSeeAlsos(signature).map((seeAlso) =>
mdToHtml(seeAlso, true)
);

const deprecatedMessage = extractDeprecated(signature);
const deprecated = deprecatedMessage
? mdToHtml(deprecatedMessage)
: undefined;
return {
name: methodName,
title: prettifyMethodName(methodName),
Expand All @@ -188,7 +191,7 @@ export function analyzeSignature(
sourcePath: extractSourcePath(signature),
returns: typeToText(signature.type),
examples: mdToHtml(`${code}ts\n${examples}${code}`),
deprecated: isDeprecated(signature),
deprecated,
seeAlsos,
};
}
Expand Down
9 changes: 6 additions & 3 deletions scripts/apidoc/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,13 @@ export function joinTagParts(parts?: CommentDisplayPart[]): string | undefined {
*
* @param signature The signature to check.
*
* @returns `true` if it is deprecated, otherwise `false`.
* @returns The message explaining the deprecation if deprecated, otherwise `undefined`.
*/
export function isDeprecated(signature: SignatureReflection): boolean {
return extractTagContent('@deprecated', signature).length > 0;
export function extractDeprecated(
signature: SignatureReflection
): string | undefined {
const deprecated = extractTagContent('@deprecated', signature).join().trim();
return deprecated.length === 0 ? undefined : deprecated;
}

/**
Expand Down
37 changes: 19 additions & 18 deletions test/scripts/apidoc/__snapshots__/signature.spec.ts.snap

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/scripts/apidoc/examplesAndDeprecations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
initMarkdownRenderer,
} from '../../../scripts/apidoc/signature';
import {
extractDeprecated,
extractRawExamples,
extractSeeAlsos,
extractSince,
extractTagContent,
isDeprecated,
} from '../../../scripts/apidoc/typedoc';
import { faker } from '../../../src';
import { loadProjectModules } from './utils';
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('examples and deprecations', () => {
await import(path);

// Verify logging
const deprecatedFlag = isDeprecated(signature);
const deprecatedFlag = extractDeprecated(signature) !== undefined;
if (deprecatedFlag) {
expect(consoleSpies[1]).toHaveBeenCalled();
expect(
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/apidoc/signature.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class SignatureTest {
*
* @see test.apidoc.methodWithExample()
*
* @deprecated
* @deprecated do something else
*/
methodWithDeprecated(): number {
return 0;
Expand Down

0 comments on commit 8592928

Please sign in to comment.