1 | "use strict";
|
2 |
|
3 |
|
4 | Object.defineProperty(exports, "__esModule", { value: true });
|
5 | exports.ExperimentalYamlDocumenter = void 0;
|
6 | const tsdoc_1 = require("@microsoft/tsdoc");
|
7 | const api_extractor_model_1 = require("@microsoft/api-extractor-model");
|
8 | const YamlDocumenter_1 = require("./YamlDocumenter");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | class ExperimentalYamlDocumenter extends YamlDocumenter_1.YamlDocumenter {
|
14 | constructor(apiModel, documenterConfig) {
|
15 | super(apiModel, documenterConfig.configFile.newDocfxNamespaces);
|
16 | this._config = documenterConfig.configFile.tableOfContents;
|
17 | this._tocPointerMap = {};
|
18 | this._generateTocPointersMap(this._config.tocConfig);
|
19 | }
|
20 |
|
21 | buildYamlTocFile(apiItems) {
|
22 | this._buildTocItems2(apiItems);
|
23 | return this._config.tocConfig;
|
24 | }
|
25 | _buildTocItems2(apiItems) {
|
26 | const tocItems = [];
|
27 | for (const apiItem of apiItems) {
|
28 | let tocItem;
|
29 | if (apiItem.kind === api_extractor_model_1.ApiItemKind.Namespace && !this.newDocfxNamespaces) {
|
30 | tocItem = {
|
31 | name: this._getTocItemName(apiItem)
|
32 | };
|
33 | }
|
34 | else {
|
35 | if (this._shouldEmbed(apiItem.kind)) {
|
36 |
|
37 | continue;
|
38 | }
|
39 | tocItem = {
|
40 | name: this._getTocItemName(apiItem),
|
41 | uid: this._getUid(apiItem)
|
42 | };
|
43 | if (apiItem.kind !== api_extractor_model_1.ApiItemKind.Package) {
|
44 | this._filterItem(apiItem, tocItem);
|
45 | }
|
46 | }
|
47 | tocItems.push(tocItem);
|
48 | const children = this._getLogicalChildren(apiItem);
|
49 | const childItems = this._buildTocItems2(children);
|
50 | if (childItems.length > 0) {
|
51 | tocItem.items = childItems;
|
52 | }
|
53 | }
|
54 | return tocItems;
|
55 | }
|
56 |
|
57 | _generateTocPointersMap(tocConfig) {
|
58 | const { catchAllCategory } = this._config;
|
59 | if (tocConfig.items) {
|
60 | for (const tocItem of tocConfig.items) {
|
61 | if (tocItem.items && tocItem.items.length > 0 && this._shouldNotIncludeInPointersMap(tocItem)) {
|
62 | this._generateTocPointersMap(tocItem);
|
63 | }
|
64 | else {
|
65 |
|
66 | if (catchAllCategory && tocItem.name === catchAllCategory) {
|
67 | this._catchAllPointer = tocItem;
|
68 | }
|
69 | else {
|
70 | this._tocPointerMap[tocItem.name] = tocItem;
|
71 | }
|
72 | }
|
73 | }
|
74 | }
|
75 | }
|
76 | |
77 |
|
78 |
|
79 | _filterItem(apiItem, tocItem) {
|
80 | const { categoryInlineTag, categorizeByName } = this._config;
|
81 | const { name: itemName } = tocItem;
|
82 | let filtered = false;
|
83 |
|
84 | if (apiItem instanceof api_extractor_model_1.ApiDocumentedItem) {
|
85 | const docInlineTag = categoryInlineTag
|
86 | ? this._findInlineTagByName(categoryInlineTag, apiItem.tsdocComment)
|
87 | : undefined;
|
88 | const tagContent = docInlineTag && docInlineTag.tagContent && docInlineTag.tagContent.trim();
|
89 | if (tagContent && this._tocPointerMap[tagContent]) {
|
90 |
|
91 | this._tocPointerMap[tagContent].items.push(tocItem);
|
92 | filtered = true;
|
93 | }
|
94 | }
|
95 |
|
96 | if (!filtered && categorizeByName) {
|
97 | const pointers = Object.keys(this._tocPointerMap);
|
98 | for (let i = 0, length = pointers.length; i < length; i++) {
|
99 | if (itemName.indexOf(pointers[i]) !== -1) {
|
100 |
|
101 | this._tocPointerMap[pointers[i]].items.push(tocItem);
|
102 | filtered = true;
|
103 | break;
|
104 | }
|
105 | }
|
106 | }
|
107 |
|
108 | if (!filtered && this._catchAllPointer && this._catchAllPointer.items) {
|
109 | this._catchAllPointer.items.push(tocItem);
|
110 | }
|
111 | }
|
112 |
|
113 |
|
114 | _findInlineTagByName(tagName, docComment) {
|
115 | const tagNameToCheck = `@${tagName}`;
|
116 | if (docComment instanceof tsdoc_1.DocInlineTag) {
|
117 | if (docComment.tagName === tagNameToCheck) {
|
118 | return docComment;
|
119 | }
|
120 | }
|
121 | if (docComment) {
|
122 | for (const childNode of docComment.getChildNodes()) {
|
123 | const result = this._findInlineTagByName(tagName, childNode);
|
124 | if (result !== undefined) {
|
125 | return result;
|
126 | }
|
127 | }
|
128 | }
|
129 | return undefined;
|
130 | }
|
131 | _shouldNotIncludeInPointersMap(item) {
|
132 | const { nonEmptyCategoryNodeNames } = this._config;
|
133 | if (nonEmptyCategoryNodeNames && nonEmptyCategoryNodeNames.length) {
|
134 | return nonEmptyCategoryNodeNames.indexOf(item.name) === -1;
|
135 | }
|
136 | return true;
|
137 | }
|
138 | }
|
139 | exports.ExperimentalYamlDocumenter = ExperimentalYamlDocumenter;
|
140 |
|
\ | No newline at end of file |