Skip to content

Commit

Permalink
build: show deletion target in docs (#9648)
Browse files Browse the repository at this point in the history
* Surfaces the @deletion-target JSDoc information into the Dgeni HTML output. Currently it will add a title to the deprecation marker.

Closes #9641
  • Loading branch information
devversion authored and tinayuangao committed Jan 31, 2018
1 parent 7dbebfa commit 664d69e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 13 deletions.
24 changes: 21 additions & 3 deletions tools/dgeni/common/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
import {MemberDoc} from 'dgeni-packages/typescript/api-doc-types/MemberDoc';
import {CategorizedClassDoc} from './dgeni-definitions';
import {CategorizedClassDoc, DeprecationDoc, HasDecoratorsDoc} from './dgeni-definitions';

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

export function hasDecorator(doc: {decorators?: {name: string}[]}, decoratorName: string) {
export function hasDecorator(doc: HasDecoratorsDoc, decoratorName: string) {
return !!doc.decorators &&
doc.decorators.length > 0 &&
doc.decorators.some(d => d.name == decoratorName);
}

export function getDeletionTarget(doc: any): string | null {
if (!doc.tags) {
return null;
}

const deletionTarget = doc.tags.tags.find((t: any) => t.tagName === 'deletion-target');

return deletionTarget ? deletionTarget.description : null;
}

/**
* Decorates public exposed docs. Creates a property on the doc that indicates whether
* the item is deprecated or not.
*/
export function decorateDeprecatedDoc(doc: {isDeprecated: boolean}) {
export function decorateDeprecatedDoc(doc: DeprecationDoc) {
doc.isDeprecated = isDeprecatedDoc(doc);
doc.deletionTarget = getDeletionTarget(doc);

if (doc.isDeprecated && !doc.deletionTarget) {
console.warn('Warning: There is a deprecated item without a @deletion-target tag.', doc.id);
} else if (doc.deletionTarget && !doc.isDeprecated) {
console.warn('Warning: There is an item with a @deletion-target which is not deprecated.',
doc.id);
}
}
22 changes: 16 additions & 6 deletions tools/dgeni/common/dgeni-definitions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import {ApiDoc} from 'dgeni-packages/typescript/api-doc-types/ApiDoc';
import {ClassExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassExportDoc';
import {ClassLikeExportDoc} from 'dgeni-packages/typescript/api-doc-types/ClassLikeExportDoc';
import {PropertyMemberDoc} from 'dgeni-packages/typescript/api-doc-types/PropertyMemberDoc';
import {ParsedDecorator} from 'dgeni-packages/typescript/services/TsParser/getDecorators';
import {NormalizedMethodMemberDoc} from './normalize-method-parameters';

/** Interface that describes categorized docs that can be deprecated. */
export interface DeprecationDoc extends ApiDoc {
isDeprecated: boolean;
deletionTarget: string | null;
}

/** Interface that describes Dgeni documents that have decorators. */
export interface HasDecoratorsDoc {
decorators?: ParsedDecorator[] | undefined;
}

/** Extended Dgeni class-like document that includes separated class members. */
export interface CategorizedClassLikeDoc extends ClassLikeExportDoc {
export interface CategorizedClassLikeDoc extends ClassLikeExportDoc, DeprecationDoc {
methods: CategorizedMethodMemberDoc[];
properties: CategorizedPropertyMemberDoc[];
isDeprecated: boolean;
}

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

/** Extended Dgeni property-member document that includes extracted Angular metadata. */
export interface CategorizedPropertyMemberDoc extends PropertyMemberDoc {
export interface CategorizedPropertyMemberDoc extends PropertyMemberDoc, DeprecationDoc {
description: string;
isDeprecated: boolean;
isDirectiveInput: boolean;
isDirectiveOutput: boolean;
directiveInputAlias: string;
directiveOutputAlias: string;
}

/** Extended Dgeni method-member document that simplifies logic for the Dgeni template. */
export interface CategorizedMethodMemberDoc extends NormalizedMethodMemberDoc {
export interface CategorizedMethodMemberDoc extends NormalizedMethodMemberDoc, DeprecationDoc {
showReturns: boolean;
isDeprecated: boolean;
}
6 changes: 5 additions & 1 deletion tools/dgeni/templates/class.template.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% import "macros.html" as macros %}

<h4 id="{$ class.name $}" class="docs-header-link docs-api-h4 docs-api-class-name">
<span header-link="{$ class.name $}"></span>
<code>{$ class.name $}</code>
Expand Down Expand Up @@ -28,7 +30,9 @@ <h4 id="{$ class.name $}" class="docs-header-link docs-api-h4 docs-api-class-nam
{%- endif -%}

{%- if class.isDeprecated -%}
<div class="docs-api-class-deprecated-marker">Deprecated</div>
<div class="docs-api-class-deprecated-marker" {$ macros.deprecationTitle(class) $}>
Deprecated
</div>
{%- endif -%}

{$ propertyList(class.properties) $}
Expand Down
6 changes: 5 additions & 1 deletion tools/dgeni/templates/interface.template.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% import "macros.html" as macros %}

<h4 id="{$ interface.name $}" class="docs-header-link docs-api-h4 docs-api-interface-name">
<span header-link="{$ interface.name $}"></span>
<code>{$ interface.name $}</code>
Expand All @@ -8,7 +10,9 @@ <h4 id="{$ interface.name $}" class="docs-header-link docs-api-h4 docs-api-inter
{%- endif -%}

{%- if interface.isDeprecated -%}
<div class="docs-api-interface-deprecated-marker">Deprecated</div>
<div class="docs-api-interface-deprecated-marker" {$ macros.deprecationTitle(interface) $}>
Deprecated
</div>
{%- endif -%}

{$ propertyList(interface.properties) $}
Expand Down
5 changes: 5 additions & 0 deletions tools/dgeni/templates/macros.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% macro deprecationTitle(doc) %}
{%- if doc.deletionTarget -%}
title="Will be deleted in v{$ doc.deletionTarget $}"
{%- endif -%}
{% endmacro %}
6 changes: 5 additions & 1 deletion tools/dgeni/templates/method.template.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{% import "macros.html" as macros %}

<table class="docs-api-method-table">
<thead>
<tr class="docs-api-method-name-row">
<th colspan="2" class="docs-api-method-name-cell">
{%- if method.isDeprecated -%}
<div class="docs-api-deprecated-marker">Deprecated</div>
<div class="docs-api-deprecated-marker" {$ macros.deprecationTitle(method) $}>
Deprecated
</div>
{%- endif -%}
{$ method.name $}
</th>
Expand Down
6 changes: 5 additions & 1 deletion tools/dgeni/templates/property.template.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% import "macros.html" as macros %}

<tr class="docs-api-properties-row">
<td class="docs-api-properties-name-cell">
{%- if property.isDirectiveInput -%}
Expand All @@ -19,7 +21,9 @@
</div>
{%- endif -%}
{%- if property.isDeprecated -%}
<div class="docs-api-deprecated-marker">Deprecated</div>
<div class="docs-api-deprecated-marker" {$ macros.deprecationTitle(property) $}>
Deprecated
</div>
{%- endif -%}

<p class="docs-api-property-name">
Expand Down

0 comments on commit 664d69e

Please sign in to comment.