Skip to content

Commit 664d69e

Browse files
devversiontinayuangao
authored andcommitted
build: show deletion target in docs (#9648)
* Surfaces the @deletion-target JSDoc information into the Dgeni HTML output. Currently it will add a title to the deprecation marker. Closes #9641
1 parent 7dbebfa commit 664d69e

File tree

7 files changed

+62
-13
lines changed

7 files changed

+62
-13
lines changed

tools/dgeni/common/decorators.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
77
import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
88
import {MemberDoc} from 'dgeni-packages/typescript/api-doc-types/MemberDoc';
9-
import {CategorizedClassDoc} from './dgeni-definitions';
9+
import {CategorizedClassDoc, DeprecationDoc, HasDecoratorsDoc} from './dgeni-definitions';
1010

1111
const SELECTOR_BLACKLIST = new Set([
1212
'[portal]',
@@ -76,16 +76,34 @@ export function hasClassDecorator(doc: ClassExportDoc, decoratorName: string) {
7676
return doc.docType == 'class' && hasDecorator(doc, decoratorName);
7777
}
7878

79-
export function hasDecorator(doc: {decorators?: {name: string}[]}, decoratorName: string) {
79+
export function hasDecorator(doc: HasDecoratorsDoc, decoratorName: string) {
8080
return !!doc.decorators &&
8181
doc.decorators.length > 0 &&
8282
doc.decorators.some(d => d.name == decoratorName);
8383
}
8484

85+
export function getDeletionTarget(doc: any): string | null {
86+
if (!doc.tags) {
87+
return null;
88+
}
89+
90+
const deletionTarget = doc.tags.tags.find((t: any) => t.tagName === 'deletion-target');
91+
92+
return deletionTarget ? deletionTarget.description : null;
93+
}
94+
8595
/**
8696
* Decorates public exposed docs. Creates a property on the doc that indicates whether
8797
* the item is deprecated or not.
8898
*/
89-
export function decorateDeprecatedDoc(doc: {isDeprecated: boolean}) {
99+
export function decorateDeprecatedDoc(doc: DeprecationDoc) {
90100
doc.isDeprecated = isDeprecatedDoc(doc);
101+
doc.deletionTarget = getDeletionTarget(doc);
102+
103+
if (doc.isDeprecated && !doc.deletionTarget) {
104+
console.warn('Warning: There is a deprecated item without a @deletion-target tag.', doc.id);
105+
} else if (doc.deletionTarget && !doc.isDeprecated) {
106+
console.warn('Warning: There is an item with a @deletion-target which is not deprecated.',
107+
doc.id);
108+
}
91109
}

tools/dgeni/common/dgeni-definitions.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1+
import {ApiDoc} from 'dgeni-packages/typescript/api-doc-types/ApiDoc';
12
import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
23
import {ClassLikeExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassLikeExportDoc';
34
import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
5+
import {ParsedDecorator} from 'dgeni-packages/typescript/services/TsParser/getDecorators';
46
import {NormalizedMethodMemberDoc} from './normalize-method-parameters';
57

8+
/** Interface that describes categorized docs that can be deprecated. */
9+
export interface DeprecationDoc extends ApiDoc {
10+
isDeprecated: boolean;
11+
deletionTarget: string | null;
12+
}
13+
14+
/** Interface that describes Dgeni documents that have decorators. */
15+
export interface HasDecoratorsDoc {
16+
decorators?: ParsedDecorator[] | undefined;
17+
}
18+
619
/** Extended Dgeni class-like document that includes separated class members. */
7-
export interface CategorizedClassLikeDoc extends ClassLikeExportDoc {
20+
export interface CategorizedClassLikeDoc extends ClassLikeExportDoc, DeprecationDoc {
821
methods: CategorizedMethodMemberDoc[];
922
properties: CategorizedPropertyMemberDoc[];
10-
isDeprecated: boolean;
1123
}
1224

1325
/** Extended Dgeni class document that includes extracted Angular metadata. */
@@ -22,17 +34,15 @@ export interface CategorizedClassDoc extends ClassExportDoc, CategorizedClassLik
2234
}
2335

2436
/** Extended Dgeni property-member document that includes extracted Angular metadata. */
25-
export interface CategorizedPropertyMemberDoc extends PropertyMemberDoc {
37+
export interface CategorizedPropertyMemberDoc extends PropertyMemberDoc, DeprecationDoc {
2638
description: string;
27-
isDeprecated: boolean;
2839
isDirectiveInput: boolean;
2940
isDirectiveOutput: boolean;
3041
directiveInputAlias: string;
3142
directiveOutputAlias: string;
3243
}
3344

3445
/** Extended Dgeni method-member document that simplifies logic for the Dgeni template. */
35-
export interface CategorizedMethodMemberDoc extends NormalizedMethodMemberDoc {
46+
export interface CategorizedMethodMemberDoc extends NormalizedMethodMemberDoc, DeprecationDoc {
3647
showReturns: boolean;
37-
isDeprecated: boolean;
3848
}

tools/dgeni/templates/class.template.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% import "macros.html" as macros %}
2+
13
<h4 id="{$ class.name $}" class="docs-header-link docs-api-h4 docs-api-class-name">
24
<span header-link="{$ class.name $}"></span>
35
<code>{$ class.name $}</code>
@@ -28,7 +30,9 @@ <h4 id="{$ class.name $}" class="docs-header-link docs-api-h4 docs-api-class-nam
2830
{%- endif -%}
2931

3032
{%- if class.isDeprecated -%}
31-
<div class="docs-api-class-deprecated-marker">Deprecated</div>
33+
<div class="docs-api-class-deprecated-marker" {$ macros.deprecationTitle(class) $}>
34+
Deprecated
35+
</div>
3236
{%- endif -%}
3337

3438
{$ propertyList(class.properties) $}

tools/dgeni/templates/interface.template.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% import "macros.html" as macros %}
2+
13
<h4 id="{$ interface.name $}" class="docs-header-link docs-api-h4 docs-api-interface-name">
24
<span header-link="{$ interface.name $}"></span>
35
<code>{$ interface.name $}</code>
@@ -8,7 +10,9 @@ <h4 id="{$ interface.name $}" class="docs-header-link docs-api-h4 docs-api-inter
810
{%- endif -%}
911

1012
{%- if interface.isDeprecated -%}
11-
<div class="docs-api-interface-deprecated-marker">Deprecated</div>
13+
<div class="docs-api-interface-deprecated-marker" {$ macros.deprecationTitle(interface) $}>
14+
Deprecated
15+
</div>
1216
{%- endif -%}
1317

1418
{$ propertyList(interface.properties) $}

tools/dgeni/templates/macros.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% macro deprecationTitle(doc) %}
2+
{%- if doc.deletionTarget -%}
3+
title="Will be deleted in v{$ doc.deletionTarget $}"
4+
{%- endif -%}
5+
{% endmacro %}

tools/dgeni/templates/method.template.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
{% import "macros.html" as macros %}
2+
13
<table class="docs-api-method-table">
24
<thead>
35
<tr class="docs-api-method-name-row">
46
<th colspan="2" class="docs-api-method-name-cell">
57
{%- if method.isDeprecated -%}
6-
<div class="docs-api-deprecated-marker">Deprecated</div>
8+
<div class="docs-api-deprecated-marker" {$ macros.deprecationTitle(method) $}>
9+
Deprecated
10+
</div>
711
{%- endif -%}
812
{$ method.name $}
913
</th>

tools/dgeni/templates/property.template.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% import "macros.html" as macros %}
2+
13
<tr class="docs-api-properties-row">
24
<td class="docs-api-properties-name-cell">
35
{%- if property.isDirectiveInput -%}
@@ -19,7 +21,9 @@
1921
</div>
2022
{%- endif -%}
2123
{%- if property.isDeprecated -%}
22-
<div class="docs-api-deprecated-marker">Deprecated</div>
24+
<div class="docs-api-deprecated-marker" {$ macros.deprecationTitle(property) $}>
25+
Deprecated
26+
</div>
2327
{%- endif -%}
2428

2529
<p class="docs-api-property-name">

0 commit comments

Comments
 (0)