Skip to content

Commit

Permalink
feat: Support for @packageDocumentation
Browse files Browse the repository at this point in the history
Closes #1080

Also removes the grunt task, we mention the third-party grunt plugin on the website, and the built in one has been broken since 2015 without anyone complaining.
  • Loading branch information
Gerrit0 committed Dec 26, 2019
1 parent 03987a0 commit ef9ef6c
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 67 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@
"keywords": [
"typescript",
"documentation",
"generator",
"gruntplugin"
"generator"
],
"nyc": {
"extension": [
Expand Down
17 changes: 15 additions & 2 deletions src/lib/converter/factories/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,26 @@ export function getRawComment(node: ts.Node): string | undefined {
const comments = getJSDocCommentRanges(node, sourceFile.text);
if (comments.length) {
let comment: ts.CommentRange;
const explicitPackageComment = comments.find(comment =>
sourceFile.text.substring(comment.pos, comment.end).includes('@packageDocumentation'));
if (node.kind === ts.SyntaxKind.SourceFile) {
if (comments.length === 1) {
if (explicitPackageComment) {
comment = explicitPackageComment;
} else if (comments.length > 1) {
// Legacy behavior, require more than one comment and use the first comment.
// TODO: GH#1083, follow deprecation process to phase this out.
comment = comments[0];
} else {
// Single comment that may be a license comment, bail.
return;
}
comment = comments[0];
} else {
comment = comments[comments.length - 1];
// If a non-SourceFile node comment has this tag, it should not be attached to the node
// as it documents the whole file by convention.
if (sourceFile.text.substring(comment.pos, comment.end).includes('@packageDocumentation')) {
return;
}
}

return sourceFile.text.substring(comment.pos, comment.end);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/converter/plugins/CommentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ export class CommentPlugin extends ConverterComponent {
}
this.hidden.push(reflection);
}

if (reflection.kindOf(ReflectionKind.ExternalModule)) {
CommentPlugin.removeTags(comment, 'packageDocumentation');
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/test/converter/comment/comment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* This is a module doc comment with legacy behavior.
*/
/** dummy comment */
import './comment2';

/**
* A Comment for a class
*
Expand Down
10 changes: 10 additions & 0 deletions src/test/converter/comment/comment2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This is a module doc with the packageDocumentation tag to mark it as documentation
* for the whole module. It is *not* documentation for the `multiply` function.
*
* @packageDocumentation
*/

export function multiply(a: number, b: number) {
return a * b;
}
108 changes: 101 additions & 7 deletions src/test/converter/comment/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
"flags": {},
"children": [
{
"id": 1,
"id": 6,
"name": "\"comment\"",
"kind": 1,
"kindString": "External module",
"flags": {
"isExported": true
},
"originalName": "%BASE%/comment/comment.ts",
"comment": {
"shortText": "This is a module doc comment with legacy behavior."
},
"children": [
{
"id": 2,
"id": 7,
"name": "CommentedClass",
"kind": 128,
"kindString": "Class",
Expand All @@ -38,7 +41,7 @@
},
"children": [
{
"id": 3,
"id": 8,
"name": "prop",
"kind": 1024,
"kindString": "Property",
Expand All @@ -51,7 +54,7 @@
"sources": [
{
"fileName": "comment.ts",
"line": 28,
"line": 34,
"character": 6
}
],
Expand All @@ -66,14 +69,14 @@
"title": "Properties",
"kind": 1024,
"children": [
3
8
]
}
],
"sources": [
{
"fileName": "comment.ts",
"line": 24,
"line": 30,
"character": 27
}
]
Expand All @@ -84,7 +87,7 @@
"title": "Classes",
"kind": 128,
"children": [
2
7
]
}
],
Expand All @@ -95,13 +98,104 @@
"character": 0
}
]
},
{
"id": 1,
"name": "\"comment2\"",
"kind": 1,
"kindString": "External module",
"flags": {
"isExported": true
},
"originalName": "%BASE%/comment/comment2.ts",
"comment": {
"shortText": "This is a module doc with the packageDocumentation tag to mark it as documentation\nfor the whole module. It is *not* documentation for the `multiply` function.",
"tags": [
{
"tag": "packagedocumentation",
"text": "\n"
}
]
},
"children": [
{
"id": 2,
"name": "multiply",
"kind": 64,
"kindString": "Function",
"flags": {
"isExported": true
},
"signatures": [
{
"id": 3,
"name": "multiply",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"parameters": [
{
"id": 4,
"name": "a",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
},
{
"id": 5,
"name": "b",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"sources": [
{
"fileName": "comment2.ts",
"line": 8,
"character": 24
}
]
}
],
"groups": [
{
"title": "Functions",
"kind": 64,
"children": [
2
]
}
],
"sources": [
{
"fileName": "comment2.ts",
"line": 1,
"character": 0
}
]
}
],
"groups": [
{
"title": "External modules",
"kind": 1,
"children": [
6,
1
]
}
Expand Down
56 changes: 0 additions & 56 deletions tasks/typedoc.js

This file was deleted.

0 comments on commit ef9ef6c

Please sign in to comment.