@microsoft/api-documenter 7.28.8 → 7.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/CHANGELOG.json +41 -0
  2. package/CHANGELOG.md +13 -1
  3. package/bin/api-documenter +1 -1
  4. package/dist/tsdoc-metadata.json +1 -1
  5. package/lib-esm/cli/ApiDocumenterCommandLine.js +22 -0
  6. package/lib-esm/cli/ApiDocumenterCommandLine.js.map +1 -0
  7. package/lib-esm/cli/BaseAction.js +93 -0
  8. package/lib-esm/cli/BaseAction.js.map +1 -0
  9. package/lib-esm/cli/GenerateAction.js +45 -0
  10. package/lib-esm/cli/GenerateAction.js.map +1 -0
  11. package/lib-esm/cli/MarkdownAction.js +24 -0
  12. package/lib-esm/cli/MarkdownAction.js.map +1 -0
  13. package/lib-esm/cli/YamlAction.js +43 -0
  14. package/lib-esm/cli/YamlAction.js.map +1 -0
  15. package/lib-esm/documenters/DocumenterConfig.js +43 -0
  16. package/lib-esm/documenters/DocumenterConfig.js.map +1 -0
  17. package/lib-esm/documenters/ExperimentalYamlDocumenter.js +136 -0
  18. package/lib-esm/documenters/ExperimentalYamlDocumenter.js.map +1 -0
  19. package/lib-esm/documenters/IConfigFile.js +4 -0
  20. package/lib-esm/documenters/IConfigFile.js.map +1 -0
  21. package/lib-esm/documenters/MarkdownDocumenter.js +987 -0
  22. package/lib-esm/documenters/MarkdownDocumenter.js.map +1 -0
  23. package/lib-esm/documenters/OfficeYamlDocumenter.js +101 -0
  24. package/lib-esm/documenters/OfficeYamlDocumenter.js.map +1 -0
  25. package/lib-esm/documenters/YamlDocumenter.js +804 -0
  26. package/lib-esm/documenters/YamlDocumenter.js.map +1 -0
  27. package/lib-esm/index.js +6 -0
  28. package/lib-esm/index.js.map +1 -0
  29. package/lib-esm/markdown/CustomMarkdownEmitter.js +146 -0
  30. package/lib-esm/markdown/CustomMarkdownEmitter.js.map +1 -0
  31. package/lib-esm/markdown/MarkdownEmitter.js +190 -0
  32. package/lib-esm/markdown/MarkdownEmitter.js.map +1 -0
  33. package/lib-esm/nodes/CustomDocNodeKind.js +51 -0
  34. package/lib-esm/nodes/CustomDocNodeKind.js.map +1 -0
  35. package/lib-esm/nodes/DocEmphasisSpan.js +20 -0
  36. package/lib-esm/nodes/DocEmphasisSpan.js.map +1 -0
  37. package/lib-esm/nodes/DocHeading.js +26 -0
  38. package/lib-esm/nodes/DocHeading.js.map +1 -0
  39. package/lib-esm/nodes/DocNoteBox.js +22 -0
  40. package/lib-esm/nodes/DocNoteBox.js.map +1 -0
  41. package/lib-esm/nodes/DocTable.js +56 -0
  42. package/lib-esm/nodes/DocTable.js.map +1 -0
  43. package/lib-esm/nodes/DocTableCell.js +18 -0
  44. package/lib-esm/nodes/DocTableCell.js.map +1 -0
  45. package/lib-esm/nodes/DocTableRow.js +47 -0
  46. package/lib-esm/nodes/DocTableRow.js.map +1 -0
  47. package/lib-esm/plugin/IApiDocumenterPluginManifest.js +4 -0
  48. package/lib-esm/plugin/IApiDocumenterPluginManifest.js.map +1 -0
  49. package/lib-esm/plugin/MarkdownDocumenterAccessor.js +26 -0
  50. package/lib-esm/plugin/MarkdownDocumenterAccessor.js.map +1 -0
  51. package/lib-esm/plugin/MarkdownDocumenterFeature.js +47 -0
  52. package/lib-esm/plugin/MarkdownDocumenterFeature.js.map +1 -0
  53. package/lib-esm/plugin/PluginFeature.js +54 -0
  54. package/lib-esm/plugin/PluginFeature.js.map +1 -0
  55. package/lib-esm/plugin/PluginLoader.js +78 -0
  56. package/lib-esm/plugin/PluginLoader.js.map +1 -0
  57. package/lib-esm/schemas/api-documenter-template.json +99 -0
  58. package/lib-esm/schemas/api-documenter.schema.json +47 -0
  59. package/lib-esm/start.js +12 -0
  60. package/lib-esm/start.js.map +1 -0
  61. package/lib-esm/utils/IndentedWriter.js +235 -0
  62. package/lib-esm/utils/IndentedWriter.js.map +1 -0
  63. package/lib-esm/utils/ToSdpConvertHelper.js +338 -0
  64. package/lib-esm/utils/ToSdpConvertHelper.js.map +1 -0
  65. package/lib-esm/utils/Utilities.js +24 -0
  66. package/lib-esm/utils/Utilities.js.map +1 -0
  67. package/lib-esm/yaml/ISDPYamlFile.js +4 -0
  68. package/lib-esm/yaml/ISDPYamlFile.js.map +1 -0
  69. package/lib-esm/yaml/IYamlApiFile.js +4 -0
  70. package/lib-esm/yaml/IYamlApiFile.js.map +1 -0
  71. package/lib-esm/yaml/IYamlTocFile.js +4 -0
  72. package/lib-esm/yaml/IYamlTocFile.js.map +1 -0
  73. package/lib-esm/yaml/typescript.schema.json +643 -0
  74. package/package.json +35 -9
  75. /package/{lib → lib-commonjs}/cli/ApiDocumenterCommandLine.js +0 -0
  76. /package/{lib → lib-commonjs}/cli/ApiDocumenterCommandLine.js.map +0 -0
  77. /package/{lib → lib-commonjs}/cli/BaseAction.js +0 -0
  78. /package/{lib → lib-commonjs}/cli/BaseAction.js.map +0 -0
  79. /package/{lib → lib-commonjs}/cli/GenerateAction.js +0 -0
  80. /package/{lib → lib-commonjs}/cli/GenerateAction.js.map +0 -0
  81. /package/{lib → lib-commonjs}/cli/MarkdownAction.js +0 -0
  82. /package/{lib → lib-commonjs}/cli/MarkdownAction.js.map +0 -0
  83. /package/{lib → lib-commonjs}/cli/YamlAction.js +0 -0
  84. /package/{lib → lib-commonjs}/cli/YamlAction.js.map +0 -0
  85. /package/{lib → lib-commonjs}/documenters/DocumenterConfig.js +0 -0
  86. /package/{lib → lib-commonjs}/documenters/DocumenterConfig.js.map +0 -0
  87. /package/{lib → lib-commonjs}/documenters/ExperimentalYamlDocumenter.js +0 -0
  88. /package/{lib → lib-commonjs}/documenters/ExperimentalYamlDocumenter.js.map +0 -0
  89. /package/{lib → lib-commonjs}/documenters/IConfigFile.js +0 -0
  90. /package/{lib → lib-commonjs}/documenters/IConfigFile.js.map +0 -0
  91. /package/{lib → lib-commonjs}/documenters/MarkdownDocumenter.js +0 -0
  92. /package/{lib → lib-commonjs}/documenters/MarkdownDocumenter.js.map +0 -0
  93. /package/{lib → lib-commonjs}/documenters/OfficeYamlDocumenter.js +0 -0
  94. /package/{lib → lib-commonjs}/documenters/OfficeYamlDocumenter.js.map +0 -0
  95. /package/{lib → lib-commonjs}/documenters/YamlDocumenter.js +0 -0
  96. /package/{lib → lib-commonjs}/documenters/YamlDocumenter.js.map +0 -0
  97. /package/{lib → lib-commonjs}/index.js +0 -0
  98. /package/{lib → lib-commonjs}/index.js.map +0 -0
  99. /package/{lib → lib-commonjs}/markdown/CustomMarkdownEmitter.js +0 -0
  100. /package/{lib → lib-commonjs}/markdown/CustomMarkdownEmitter.js.map +0 -0
  101. /package/{lib → lib-commonjs}/markdown/MarkdownEmitter.js +0 -0
  102. /package/{lib → lib-commonjs}/markdown/MarkdownEmitter.js.map +0 -0
  103. /package/{lib → lib-commonjs}/nodes/CustomDocNodeKind.js +0 -0
  104. /package/{lib → lib-commonjs}/nodes/CustomDocNodeKind.js.map +0 -0
  105. /package/{lib → lib-commonjs}/nodes/DocEmphasisSpan.js +0 -0
  106. /package/{lib → lib-commonjs}/nodes/DocEmphasisSpan.js.map +0 -0
  107. /package/{lib → lib-commonjs}/nodes/DocHeading.js +0 -0
  108. /package/{lib → lib-commonjs}/nodes/DocHeading.js.map +0 -0
  109. /package/{lib → lib-commonjs}/nodes/DocNoteBox.js +0 -0
  110. /package/{lib → lib-commonjs}/nodes/DocNoteBox.js.map +0 -0
  111. /package/{lib → lib-commonjs}/nodes/DocTable.js +0 -0
  112. /package/{lib → lib-commonjs}/nodes/DocTable.js.map +0 -0
  113. /package/{lib → lib-commonjs}/nodes/DocTableCell.js +0 -0
  114. /package/{lib → lib-commonjs}/nodes/DocTableCell.js.map +0 -0
  115. /package/{lib → lib-commonjs}/nodes/DocTableRow.js +0 -0
  116. /package/{lib → lib-commonjs}/nodes/DocTableRow.js.map +0 -0
  117. /package/{lib → lib-commonjs}/plugin/IApiDocumenterPluginManifest.js +0 -0
  118. /package/{lib → lib-commonjs}/plugin/IApiDocumenterPluginManifest.js.map +0 -0
  119. /package/{lib → lib-commonjs}/plugin/MarkdownDocumenterAccessor.js +0 -0
  120. /package/{lib → lib-commonjs}/plugin/MarkdownDocumenterAccessor.js.map +0 -0
  121. /package/{lib → lib-commonjs}/plugin/MarkdownDocumenterFeature.js +0 -0
  122. /package/{lib → lib-commonjs}/plugin/MarkdownDocumenterFeature.js.map +0 -0
  123. /package/{lib → lib-commonjs}/plugin/PluginFeature.js +0 -0
  124. /package/{lib → lib-commonjs}/plugin/PluginFeature.js.map +0 -0
  125. /package/{lib → lib-commonjs}/plugin/PluginLoader.js +0 -0
  126. /package/{lib → lib-commonjs}/plugin/PluginLoader.js.map +0 -0
  127. /package/{lib → lib-commonjs}/schemas/api-documenter-template.json +0 -0
  128. /package/{lib → lib-commonjs}/schemas/api-documenter.schema.json +0 -0
  129. /package/{lib → lib-commonjs}/start.js +0 -0
  130. /package/{lib → lib-commonjs}/start.js.map +0 -0
  131. /package/{lib → lib-commonjs}/utils/IndentedWriter.js +0 -0
  132. /package/{lib → lib-commonjs}/utils/IndentedWriter.js.map +0 -0
  133. /package/{lib → lib-commonjs}/utils/ToSdpConvertHelper.js +0 -0
  134. /package/{lib → lib-commonjs}/utils/ToSdpConvertHelper.js.map +0 -0
  135. /package/{lib → lib-commonjs}/utils/Utilities.js +0 -0
  136. /package/{lib → lib-commonjs}/utils/Utilities.js.map +0 -0
  137. /package/{lib → lib-commonjs}/yaml/ISDPYamlFile.js +0 -0
  138. /package/{lib → lib-commonjs}/yaml/ISDPYamlFile.js.map +0 -0
  139. /package/{lib → lib-commonjs}/yaml/IYamlApiFile.js +0 -0
  140. /package/{lib → lib-commonjs}/yaml/IYamlApiFile.js.map +0 -0
  141. /package/{lib → lib-commonjs}/yaml/IYamlTocFile.js +0 -0
  142. /package/{lib → lib-commonjs}/yaml/IYamlTocFile.js.map +0 -0
  143. /package/{lib → lib-commonjs}/yaml/typescript.schema.json +0 -0
  144. /package/{lib → lib-dts}/cli/ApiDocumenterCommandLine.d.ts +0 -0
  145. /package/{lib → lib-dts}/cli/ApiDocumenterCommandLine.d.ts.map +0 -0
  146. /package/{lib → lib-dts}/cli/BaseAction.d.ts +0 -0
  147. /package/{lib → lib-dts}/cli/BaseAction.d.ts.map +0 -0
  148. /package/{lib → lib-dts}/cli/GenerateAction.d.ts +0 -0
  149. /package/{lib → lib-dts}/cli/GenerateAction.d.ts.map +0 -0
  150. /package/{lib → lib-dts}/cli/MarkdownAction.d.ts +0 -0
  151. /package/{lib → lib-dts}/cli/MarkdownAction.d.ts.map +0 -0
  152. /package/{lib → lib-dts}/cli/YamlAction.d.ts +0 -0
  153. /package/{lib → lib-dts}/cli/YamlAction.d.ts.map +0 -0
  154. /package/{lib → lib-dts}/documenters/DocumenterConfig.d.ts +0 -0
  155. /package/{lib → lib-dts}/documenters/DocumenterConfig.d.ts.map +0 -0
  156. /package/{lib → lib-dts}/documenters/ExperimentalYamlDocumenter.d.ts +0 -0
  157. /package/{lib → lib-dts}/documenters/ExperimentalYamlDocumenter.d.ts.map +0 -0
  158. /package/{lib → lib-dts}/documenters/IConfigFile.d.ts +0 -0
  159. /package/{lib → lib-dts}/documenters/IConfigFile.d.ts.map +0 -0
  160. /package/{lib → lib-dts}/documenters/MarkdownDocumenter.d.ts +0 -0
  161. /package/{lib → lib-dts}/documenters/MarkdownDocumenter.d.ts.map +0 -0
  162. /package/{lib → lib-dts}/documenters/OfficeYamlDocumenter.d.ts +0 -0
  163. /package/{lib → lib-dts}/documenters/OfficeYamlDocumenter.d.ts.map +0 -0
  164. /package/{lib → lib-dts}/documenters/YamlDocumenter.d.ts +0 -0
  165. /package/{lib → lib-dts}/documenters/YamlDocumenter.d.ts.map +0 -0
  166. /package/{lib → lib-dts}/index.d.ts +0 -0
  167. /package/{lib → lib-dts}/index.d.ts.map +0 -0
  168. /package/{lib → lib-dts}/markdown/CustomMarkdownEmitter.d.ts +0 -0
  169. /package/{lib → lib-dts}/markdown/CustomMarkdownEmitter.d.ts.map +0 -0
  170. /package/{lib → lib-dts}/markdown/MarkdownEmitter.d.ts +0 -0
  171. /package/{lib → lib-dts}/markdown/MarkdownEmitter.d.ts.map +0 -0
  172. /package/{lib → lib-dts}/nodes/CustomDocNodeKind.d.ts +0 -0
  173. /package/{lib → lib-dts}/nodes/CustomDocNodeKind.d.ts.map +0 -0
  174. /package/{lib → lib-dts}/nodes/DocEmphasisSpan.d.ts +0 -0
  175. /package/{lib → lib-dts}/nodes/DocEmphasisSpan.d.ts.map +0 -0
  176. /package/{lib → lib-dts}/nodes/DocHeading.d.ts +0 -0
  177. /package/{lib → lib-dts}/nodes/DocHeading.d.ts.map +0 -0
  178. /package/{lib → lib-dts}/nodes/DocNoteBox.d.ts +0 -0
  179. /package/{lib → lib-dts}/nodes/DocNoteBox.d.ts.map +0 -0
  180. /package/{lib → lib-dts}/nodes/DocTable.d.ts +0 -0
  181. /package/{lib → lib-dts}/nodes/DocTable.d.ts.map +0 -0
  182. /package/{lib → lib-dts}/nodes/DocTableCell.d.ts +0 -0
  183. /package/{lib → lib-dts}/nodes/DocTableCell.d.ts.map +0 -0
  184. /package/{lib → lib-dts}/nodes/DocTableRow.d.ts +0 -0
  185. /package/{lib → lib-dts}/nodes/DocTableRow.d.ts.map +0 -0
  186. /package/{lib → lib-dts}/plugin/IApiDocumenterPluginManifest.d.ts +0 -0
  187. /package/{lib → lib-dts}/plugin/IApiDocumenterPluginManifest.d.ts.map +0 -0
  188. /package/{lib → lib-dts}/plugin/MarkdownDocumenterAccessor.d.ts +0 -0
  189. /package/{lib → lib-dts}/plugin/MarkdownDocumenterAccessor.d.ts.map +0 -0
  190. /package/{lib → lib-dts}/plugin/MarkdownDocumenterFeature.d.ts +0 -0
  191. /package/{lib → lib-dts}/plugin/MarkdownDocumenterFeature.d.ts.map +0 -0
  192. /package/{lib → lib-dts}/plugin/PluginFeature.d.ts +0 -0
  193. /package/{lib → lib-dts}/plugin/PluginFeature.d.ts.map +0 -0
  194. /package/{lib → lib-dts}/plugin/PluginLoader.d.ts +0 -0
  195. /package/{lib → lib-dts}/plugin/PluginLoader.d.ts.map +0 -0
  196. /package/{lib → lib-dts}/start.d.ts +0 -0
  197. /package/{lib → lib-dts}/start.d.ts.map +0 -0
  198. /package/{lib → lib-dts}/utils/IndentedWriter.d.ts +0 -0
  199. /package/{lib → lib-dts}/utils/IndentedWriter.d.ts.map +0 -0
  200. /package/{lib → lib-dts}/utils/ToSdpConvertHelper.d.ts +0 -0
  201. /package/{lib → lib-dts}/utils/ToSdpConvertHelper.d.ts.map +0 -0
  202. /package/{lib → lib-dts}/utils/Utilities.d.ts +0 -0
  203. /package/{lib → lib-dts}/utils/Utilities.d.ts.map +0 -0
  204. /package/{lib → lib-dts}/yaml/ISDPYamlFile.d.ts +0 -0
  205. /package/{lib → lib-dts}/yaml/ISDPYamlFile.d.ts.map +0 -0
  206. /package/{lib → lib-dts}/yaml/IYamlApiFile.d.ts +0 -0
  207. /package/{lib → lib-dts}/yaml/IYamlApiFile.d.ts.map +0 -0
  208. /package/{lib → lib-dts}/yaml/IYamlTocFile.d.ts +0 -0
  209. /package/{lib → lib-dts}/yaml/IYamlTocFile.d.ts.map +0 -0
@@ -0,0 +1,804 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
+ // See LICENSE in the project root for license information.
3
+ import * as path from 'node:path';
4
+ import { JsonFile, JsonSchema, PackageName, FileSystem, NewlineKind, InternalError } from '@rushstack/node-core-library';
5
+ import { StringBuilder, StandardTags } from '@microsoft/tsdoc';
6
+ import { ApiItemKind, ApiDocumentedItem, ApiReleaseTagMixin, ReleaseTag, ApiItemContainerMixin, ApiClass, ApiInterface, ApiReturnTypeMixin, ApiTypeParameterListMixin, ExcerptTokenKind } from '@microsoft/api-extractor-model';
7
+ import { Navigation, Meaning } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';
8
+ import { Utilities } from '../utils/Utilities';
9
+ import { CustomMarkdownEmitter } from '../markdown/CustomMarkdownEmitter';
10
+ import { convertUDPYamlToSDP } from '../utils/ToSdpConvertHelper';
11
+ import typescriptSchema from '../yaml/typescript.schema.json';
12
+ const yamlApiSchema = JsonSchema.fromLoadedObject(typescriptSchema);
13
+ var FlattenMode;
14
+ (function (FlattenMode) {
15
+ /** Include entries for nested namespaces and non-namespace children. */
16
+ FlattenMode[FlattenMode["NestedNamespacesAndChildren"] = 0] = "NestedNamespacesAndChildren";
17
+ /** Include entries for nested namespaces only. */
18
+ FlattenMode[FlattenMode["NestedNamespacesOnly"] = 1] = "NestedNamespacesOnly";
19
+ /** Include entries for non-namespace immediate children. */
20
+ FlattenMode[FlattenMode["ImmediateChildren"] = 2] = "ImmediateChildren";
21
+ /** Include entries for nested non-namespace children. */
22
+ FlattenMode[FlattenMode["NestedChildren"] = 3] = "NestedChildren";
23
+ })(FlattenMode || (FlattenMode = {}));
24
+ /**
25
+ * Writes documentation in the Universal Reference YAML file format, as defined by typescript.schema.json.
26
+ */
27
+ export class YamlDocumenter {
28
+ constructor(apiModel, newDocfxNamespaces = false, yamlFormat = 'sdp') {
29
+ this._apiModel = apiModel;
30
+ this.newDocfxNamespaces = newDocfxNamespaces;
31
+ this._yamlFormat = yamlFormat;
32
+ this._markdownEmitter = new CustomMarkdownEmitter(this._apiModel);
33
+ this._apiItemsByCanonicalReference = new Map();
34
+ this._initApiItems();
35
+ }
36
+ /** @virtual */
37
+ generateFiles(outputFolder) {
38
+ console.log();
39
+ this._deleteOldOutputFiles(outputFolder);
40
+ for (const apiPackage of this._apiModel.packages) {
41
+ console.log(`Writing ${apiPackage.name} package`);
42
+ this._visitApiItems(outputFolder, apiPackage, undefined);
43
+ }
44
+ if (this._yamlFormat === 'sdp') {
45
+ convertUDPYamlToSDP(outputFolder);
46
+ }
47
+ this._writeTocFile(outputFolder, this._apiModel.packages);
48
+ }
49
+ /** @virtual */
50
+ onGetTocRoot() {
51
+ return {
52
+ name: 'SharePoint Framework reference',
53
+ href: '~/overview/sharepoint.md',
54
+ items: []
55
+ };
56
+ }
57
+ /** @virtual */
58
+ onCustomizeYamlItem(yamlItem) {
59
+ // virtual
60
+ // (overridden by child class)
61
+ }
62
+ _visitApiItems(outputFolder, apiItem, parentYamlFile) {
63
+ let savedYamlReferences;
64
+ if (!this._shouldEmbed(apiItem.kind)) {
65
+ savedYamlReferences = this._yamlReferences;
66
+ this._yamlReferences = undefined;
67
+ }
68
+ const yamlItem = this._generateYamlItem(apiItem);
69
+ if (!yamlItem) {
70
+ return false;
71
+ }
72
+ this.onCustomizeYamlItem(yamlItem);
73
+ if (this._shouldEmbed(apiItem.kind)) {
74
+ if (!parentYamlFile) {
75
+ throw new InternalError('Missing file context');
76
+ }
77
+ parentYamlFile.items.push(yamlItem);
78
+ }
79
+ else {
80
+ const newYamlFile = {
81
+ items: []
82
+ };
83
+ newYamlFile.items.push(yamlItem);
84
+ const children = this._getLogicalChildren(apiItem);
85
+ for (const child of children) {
86
+ if (child instanceof ApiDocumentedItem) {
87
+ if (this._visitApiItems(outputFolder, child, newYamlFile)) {
88
+ if (!yamlItem.children) {
89
+ yamlItem.children = [];
90
+ }
91
+ yamlItem.children.push(this._getUid(child));
92
+ }
93
+ }
94
+ }
95
+ if (this._yamlReferences && this._yamlReferences.references.length > 0) {
96
+ newYamlFile.references = this._yamlReferences.references;
97
+ }
98
+ this._yamlReferences = savedYamlReferences;
99
+ const yamlFilePath = this._getYamlFilePath(outputFolder, apiItem);
100
+ if (apiItem.kind === ApiItemKind.Package) {
101
+ console.log('Writing ' + yamlFilePath);
102
+ }
103
+ this._writeYamlFile(newYamlFile, yamlFilePath, 'UniversalReference', yamlApiSchema);
104
+ if (parentYamlFile) {
105
+ // References should be recorded in the parent YAML file with the local name of the embedded item.
106
+ // This avoids unnecessary repetition when listing items inside of a namespace.
107
+ this._recordYamlReference(this._ensureYamlReferences(), this._getUid(apiItem), this._getYamlItemName(apiItem, {
108
+ includeNamespace: !this.newDocfxNamespaces,
109
+ includeSignature: true
110
+ }), this._getYamlItemName(apiItem, { includeNamespace: true, includeSignature: true }));
111
+ }
112
+ }
113
+ return true;
114
+ }
115
+ _getLogicalChildren(apiItem) {
116
+ const children = [];
117
+ if (apiItem.kind === ApiItemKind.Package) {
118
+ // Skip over the entry point, since it's not part of the documentation hierarchy
119
+ this._flattenNamespaces(apiItem.members[0].members, children, this.newDocfxNamespaces ? FlattenMode.NestedNamespacesAndChildren : FlattenMode.NestedChildren);
120
+ }
121
+ else {
122
+ this._flattenNamespaces(apiItem.members, children, this.newDocfxNamespaces ? FlattenMode.ImmediateChildren : FlattenMode.NestedChildren);
123
+ }
124
+ return children;
125
+ }
126
+ // Flattens nested namespaces into top level entries so that the following:
127
+ // namespace X { export namespace Y { export namespace Z { } }
128
+ // Is represented as:
129
+ // - X
130
+ // - X.Y
131
+ // - X.Y.Z
132
+ _flattenNamespaces(items, childrenOut, mode) {
133
+ let hasNonNamespaceChildren = false;
134
+ for (const item of items) {
135
+ if (item.kind === ApiItemKind.Namespace) {
136
+ switch (mode) {
137
+ case FlattenMode.NestedChildren:
138
+ // Include children of namespaces, but not the namespaces themselves. This matches existing legacy behavior.
139
+ this._flattenNamespaces(item.members, childrenOut, FlattenMode.NestedChildren);
140
+ break;
141
+ case FlattenMode.NestedNamespacesOnly:
142
+ case FlattenMode.NestedNamespacesAndChildren:
143
+ // At any level, always include a nested namespace if it has non-namespace children, but do not include its
144
+ // non-namespace children in the result.
145
+ // Record the offset at which the namespace is added in case we need to remove it later.
146
+ const index = childrenOut.length;
147
+ childrenOut.push(item);
148
+ if (!this._flattenNamespaces(item.members, childrenOut, FlattenMode.NestedNamespacesOnly)) {
149
+ // This namespace had no non-namespace children, remove it.
150
+ childrenOut.splice(index, 1);
151
+ }
152
+ break;
153
+ }
154
+ }
155
+ else if (this._shouldInclude(item.kind)) {
156
+ switch (mode) {
157
+ case FlattenMode.NestedChildren:
158
+ case FlattenMode.NestedNamespacesAndChildren:
159
+ case FlattenMode.ImmediateChildren:
160
+ // At the top level, include non-namespace children as well.
161
+ childrenOut.push(item);
162
+ break;
163
+ }
164
+ hasNonNamespaceChildren = true;
165
+ }
166
+ }
167
+ return hasNonNamespaceChildren;
168
+ }
169
+ /**
170
+ * Write the table of contents
171
+ */
172
+ _writeTocFile(outputFolder, apiItems) {
173
+ const tocFile = this.buildYamlTocFile(apiItems);
174
+ const tocFilePath = path.join(outputFolder, 'toc.yml');
175
+ console.log('Writing ' + tocFilePath);
176
+ this._writeYamlFile(tocFile, tocFilePath, '', undefined);
177
+ }
178
+ /** @virtual */
179
+ buildYamlTocFile(apiItems) {
180
+ const tocFile = {
181
+ items: []
182
+ };
183
+ const rootItem = this.onGetTocRoot();
184
+ tocFile.items.push(rootItem);
185
+ rootItem.items.push(...this._buildTocItems(apiItems));
186
+ return tocFile;
187
+ }
188
+ _buildTocItems(apiItems) {
189
+ const tocItems = [];
190
+ for (const apiItem of apiItems) {
191
+ let tocItem;
192
+ if (apiItem.kind === ApiItemKind.Namespace && !this.newDocfxNamespaces) {
193
+ tocItem = {
194
+ name: this._getTocItemName(apiItem)
195
+ };
196
+ }
197
+ else {
198
+ if (this._shouldEmbed(apiItem.kind)) {
199
+ // Don't generate table of contents items for embedded definitions
200
+ continue;
201
+ }
202
+ tocItem = {
203
+ name: this._getTocItemName(apiItem),
204
+ uid: this._getUid(apiItem)
205
+ };
206
+ }
207
+ tocItems.push(tocItem);
208
+ const children = this._getLogicalChildren(apiItem);
209
+ const childItems = this._buildTocItems(children);
210
+ if (childItems.length > 0) {
211
+ tocItem.items = childItems;
212
+ }
213
+ }
214
+ return tocItems;
215
+ }
216
+ /** @virtual */
217
+ _getTocItemName(apiItem) {
218
+ let name;
219
+ if (apiItem.kind === ApiItemKind.Package) {
220
+ name = PackageName.getUnscopedName(apiItem.displayName);
221
+ }
222
+ else {
223
+ name = this._getYamlItemName(apiItem);
224
+ }
225
+ if (name === apiItem.displayName && apiItem.getMergedSiblings().length > 1) {
226
+ name += ` (${apiItem.kind})`;
227
+ }
228
+ return name;
229
+ }
230
+ _shouldEmbed(apiItemKind) {
231
+ switch (apiItemKind) {
232
+ case ApiItemKind.Class:
233
+ case ApiItemKind.Package:
234
+ case ApiItemKind.Interface:
235
+ case ApiItemKind.Enum:
236
+ case ApiItemKind.TypeAlias:
237
+ return false;
238
+ case ApiItemKind.Namespace:
239
+ return !this.newDocfxNamespaces;
240
+ }
241
+ return true;
242
+ }
243
+ _shouldInclude(apiItemKind) {
244
+ // Filter out known items that are not yet supported
245
+ switch (apiItemKind) {
246
+ case ApiItemKind.CallSignature:
247
+ case ApiItemKind.ConstructSignature:
248
+ case ApiItemKind.IndexSignature:
249
+ return false;
250
+ }
251
+ return true;
252
+ }
253
+ _generateYamlItem(apiItem) {
254
+ // Filter out known items that are not yet supported
255
+ if (!this._shouldInclude(apiItem.kind)) {
256
+ return undefined;
257
+ }
258
+ const uid = this._getUidObject(apiItem);
259
+ const yamlItem = {
260
+ uid: uid.toString()
261
+ };
262
+ if (apiItem.tsdocComment) {
263
+ const tsdocComment = apiItem.tsdocComment;
264
+ if (tsdocComment.summarySection) {
265
+ const summary = this._renderMarkdown(tsdocComment.summarySection, apiItem);
266
+ if (summary) {
267
+ yamlItem.summary = summary;
268
+ }
269
+ }
270
+ if (tsdocComment.remarksBlock) {
271
+ const remarks = this._renderMarkdown(tsdocComment.remarksBlock.content, apiItem);
272
+ if (remarks) {
273
+ yamlItem.remarks = remarks;
274
+ }
275
+ }
276
+ if (tsdocComment) {
277
+ // Write the @example blocks
278
+ const exampleBlocks = tsdocComment.customBlocks.filter((x) => x.blockTag.tagNameWithUpperCase === StandardTags.example.tagNameWithUpperCase);
279
+ for (const exampleBlock of exampleBlocks) {
280
+ const example = this._renderMarkdown(exampleBlock.content, apiItem);
281
+ if (example) {
282
+ yamlItem.example = [...(yamlItem.example || []), example];
283
+ }
284
+ }
285
+ }
286
+ if (tsdocComment.deprecatedBlock) {
287
+ const deprecatedMessage = this._renderMarkdown(tsdocComment.deprecatedBlock.content, apiItem);
288
+ if (deprecatedMessage.length > 0) {
289
+ yamlItem.deprecated = { content: deprecatedMessage };
290
+ }
291
+ }
292
+ }
293
+ if (ApiReleaseTagMixin.isBaseClassOf(apiItem)) {
294
+ if (apiItem.releaseTag === ReleaseTag.Alpha || apiItem.releaseTag === ReleaseTag.Beta) {
295
+ yamlItem.isPreview = true;
296
+ }
297
+ }
298
+ yamlItem.name = this._getYamlItemName(apiItem, {
299
+ includeSignature: true,
300
+ includeNamespace: !this.newDocfxNamespaces
301
+ });
302
+ yamlItem.fullName = this._getYamlItemName(apiItem, { includeSignature: true, includeNamespace: true });
303
+ yamlItem.langs = ['typeScript'];
304
+ // Add the namespace of the item if it is contained in one.
305
+ // Do not add the namespace parent of a namespace as they are flattened in the documentation.
306
+ if (apiItem.kind !== ApiItemKind.Namespace &&
307
+ apiItem.parent &&
308
+ apiItem.parent.kind === ApiItemKind.Namespace &&
309
+ this.newDocfxNamespaces) {
310
+ yamlItem.namespace = apiItem.parent.canonicalReference.toString();
311
+ }
312
+ switch (apiItem.kind) {
313
+ case ApiItemKind.Enum:
314
+ yamlItem.type = 'enum';
315
+ break;
316
+ case ApiItemKind.EnumMember:
317
+ yamlItem.type = 'field';
318
+ const enumMember = apiItem;
319
+ if (enumMember.initializerExcerpt && enumMember.initializerExcerpt.text.length > 0) {
320
+ yamlItem.numericValue = enumMember.initializerExcerpt.text;
321
+ }
322
+ break;
323
+ case ApiItemKind.Class:
324
+ yamlItem.type = 'class';
325
+ this._populateYamlClassOrInterface(uid, yamlItem, apiItem);
326
+ break;
327
+ case ApiItemKind.Interface:
328
+ yamlItem.type = 'interface';
329
+ this._populateYamlClassOrInterface(uid, yamlItem, apiItem);
330
+ break;
331
+ case ApiItemKind.Method:
332
+ case ApiItemKind.MethodSignature:
333
+ yamlItem.type = 'method';
334
+ this._populateYamlFunctionLike(uid, yamlItem, apiItem);
335
+ break;
336
+ case ApiItemKind.Constructor:
337
+ yamlItem.type = 'constructor';
338
+ this._populateYamlFunctionLike(uid, yamlItem, apiItem);
339
+ break;
340
+ case ApiItemKind.Package:
341
+ yamlItem.type = 'package';
342
+ break;
343
+ case ApiItemKind.Namespace:
344
+ yamlItem.type = 'namespace';
345
+ break;
346
+ case ApiItemKind.Property:
347
+ case ApiItemKind.PropertySignature:
348
+ const apiProperty = apiItem;
349
+ if (apiProperty.isEventProperty) {
350
+ yamlItem.type = 'event';
351
+ }
352
+ else {
353
+ yamlItem.type = 'property';
354
+ }
355
+ this._populateYamlProperty(uid, yamlItem, apiProperty);
356
+ break;
357
+ case ApiItemKind.Function:
358
+ yamlItem.type = 'function';
359
+ this._populateYamlFunctionLike(uid, yamlItem, apiItem);
360
+ break;
361
+ case ApiItemKind.Variable:
362
+ yamlItem.type = 'variable';
363
+ this._populateYamlVariable(uid, yamlItem, apiItem);
364
+ break;
365
+ case ApiItemKind.TypeAlias:
366
+ yamlItem.type = 'typealias';
367
+ this._populateYamlTypeAlias(uid, yamlItem, apiItem);
368
+ break;
369
+ default:
370
+ throw new Error('Unimplemented item kind: ' + apiItem.kind);
371
+ }
372
+ if (apiItem.kind !== ApiItemKind.Package && !this._shouldEmbed(apiItem.kind)) {
373
+ const associatedPackage = apiItem.getAssociatedPackage();
374
+ if (!associatedPackage) {
375
+ throw new Error('Unable to determine associated package for ' + apiItem.displayName);
376
+ }
377
+ yamlItem.package = this._getUid(associatedPackage);
378
+ }
379
+ return yamlItem;
380
+ }
381
+ _populateYamlTypeParameters(contextUid, apiItem) {
382
+ const typeParameters = [];
383
+ for (const apiTypeParameter of apiItem.typeParameters) {
384
+ const typeParameter = {
385
+ id: apiTypeParameter.name
386
+ };
387
+ if (apiTypeParameter.tsdocTypeParamBlock) {
388
+ typeParameter.description = this._renderMarkdown(apiTypeParameter.tsdocTypeParamBlock.content, apiItem);
389
+ }
390
+ if (!apiTypeParameter.constraintExcerpt.isEmpty) {
391
+ typeParameter.type = [this._renderType(contextUid, apiTypeParameter.constraintExcerpt)];
392
+ }
393
+ typeParameters.push(typeParameter);
394
+ }
395
+ return typeParameters;
396
+ }
397
+ _populateYamlClassOrInterface(uid, yamlItem, apiItem) {
398
+ if (apiItem instanceof ApiClass) {
399
+ if (apiItem.extendsType) {
400
+ yamlItem.extends = [this._renderType(uid, apiItem.extendsType.excerpt)];
401
+ yamlItem.inheritance = this._renderInheritance(uid, [apiItem.extendsType]);
402
+ }
403
+ if (apiItem.implementsTypes.length > 0) {
404
+ yamlItem.implements = [];
405
+ for (const implementsType of apiItem.implementsTypes) {
406
+ yamlItem.implements.push(this._renderType(uid, implementsType.excerpt));
407
+ }
408
+ }
409
+ }
410
+ else if (apiItem instanceof ApiInterface) {
411
+ if (apiItem.extendsTypes.length > 0) {
412
+ yamlItem.extends = [];
413
+ for (const extendsType of apiItem.extendsTypes) {
414
+ yamlItem.extends.push(this._renderType(uid, extendsType.excerpt));
415
+ }
416
+ yamlItem.inheritance = this._renderInheritance(uid, apiItem.extendsTypes);
417
+ }
418
+ const typeParameters = this._populateYamlTypeParameters(uid, apiItem);
419
+ if (typeParameters.length) {
420
+ yamlItem.syntax = { typeParameters };
421
+ }
422
+ }
423
+ if (apiItem.tsdocComment) {
424
+ if (apiItem.tsdocComment.modifierTagSet.isSealed()) {
425
+ let sealedMessage;
426
+ if (apiItem.kind === ApiItemKind.Class) {
427
+ sealedMessage = 'This class is marked as `@sealed`. Subclasses should not extend it.';
428
+ }
429
+ else {
430
+ sealedMessage = 'This interface is marked as `@sealed`. Other interfaces should not extend it.';
431
+ }
432
+ if (!yamlItem.remarks) {
433
+ yamlItem.remarks = sealedMessage;
434
+ }
435
+ else {
436
+ yamlItem.remarks = sealedMessage + '\n\n' + yamlItem.remarks;
437
+ }
438
+ }
439
+ }
440
+ }
441
+ _populateYamlFunctionLike(uid, yamlItem, apiItem) {
442
+ const syntax = {
443
+ content: apiItem.getExcerptWithModifiers()
444
+ };
445
+ yamlItem.syntax = syntax;
446
+ if (ApiReturnTypeMixin.isBaseClassOf(apiItem)) {
447
+ const returnType = this._renderType(uid, apiItem.returnTypeExcerpt);
448
+ let returnDescription = '';
449
+ if (apiItem.tsdocComment && apiItem.tsdocComment.returnsBlock) {
450
+ returnDescription = this._renderMarkdown(apiItem.tsdocComment.returnsBlock.content, apiItem);
451
+ // temporary workaround for people who mistakenly add a hyphen, e.g. "@returns - blah"
452
+ returnDescription = returnDescription.replace(/^\s*-\s+/, '');
453
+ }
454
+ if (returnType || returnDescription) {
455
+ syntax.return = {
456
+ type: [returnType],
457
+ description: returnDescription
458
+ };
459
+ }
460
+ }
461
+ const parameters = [];
462
+ for (const apiParameter of apiItem.parameters) {
463
+ let parameterDescription = '';
464
+ if (apiParameter.tsdocParamBlock) {
465
+ parameterDescription = this._renderMarkdown(apiParameter.tsdocParamBlock.content, apiItem);
466
+ }
467
+ parameters.push({
468
+ id: apiParameter.name,
469
+ description: parameterDescription,
470
+ type: [this._renderType(uid, apiParameter.parameterTypeExcerpt)],
471
+ optional: apiParameter.isOptional
472
+ });
473
+ }
474
+ if (parameters.length) {
475
+ syntax.parameters = parameters;
476
+ }
477
+ if (ApiTypeParameterListMixin.isBaseClassOf(apiItem)) {
478
+ const typeParameters = this._populateYamlTypeParameters(uid, apiItem);
479
+ if (typeParameters.length) {
480
+ syntax.typeParameters = typeParameters;
481
+ }
482
+ }
483
+ }
484
+ _populateYamlProperty(uid, yamlItem, apiItem) {
485
+ const syntax = {
486
+ content: apiItem.getExcerptWithModifiers()
487
+ };
488
+ yamlItem.syntax = syntax;
489
+ if (apiItem.propertyTypeExcerpt.text) {
490
+ syntax.return = {
491
+ type: [this._renderType(uid, apiItem.propertyTypeExcerpt)]
492
+ };
493
+ }
494
+ }
495
+ _populateYamlVariable(uid, yamlItem, apiItem) {
496
+ const syntax = {
497
+ content: apiItem.getExcerptWithModifiers()
498
+ };
499
+ yamlItem.syntax = syntax;
500
+ if (apiItem.variableTypeExcerpt.text) {
501
+ syntax.return = {
502
+ type: [this._renderType(uid, apiItem.variableTypeExcerpt)]
503
+ };
504
+ }
505
+ }
506
+ _populateYamlTypeAlias(uid, yamlItem, apiItem) {
507
+ const syntax = {
508
+ content: apiItem.getExcerptWithModifiers()
509
+ };
510
+ yamlItem.syntax = syntax;
511
+ const typeParameters = this._populateYamlTypeParameters(uid, apiItem);
512
+ if (typeParameters.length) {
513
+ syntax.typeParameters = typeParameters;
514
+ }
515
+ if (apiItem.typeExcerpt.text) {
516
+ syntax.return = {
517
+ type: [this._renderType(uid, apiItem.typeExcerpt)]
518
+ };
519
+ }
520
+ }
521
+ _renderMarkdown(docSection, contextApiItem) {
522
+ const stringBuilder = new StringBuilder();
523
+ this._markdownEmitter.emit(stringBuilder, docSection, {
524
+ contextApiItem,
525
+ onGetFilenameForApiItem: (apiItem) => {
526
+ // NOTE: GitHub's markdown renderer does not resolve relative hyperlinks correctly
527
+ // unless they start with "./" or "../".
528
+ // To ensure the xref is properly escaped, we first encode the entire xref
529
+ // to handle escaping of reserved characters. Then we must replace '#' and '?'
530
+ // characters so that they are not interpreted as a querystring or hash.
531
+ // We must also backslash-escape unbalanced `(` and `)` characters as the
532
+ // markdown spec insists that they are only valid when balanced. To reduce
533
+ // the overhead we only support balanced parenthesis with a depth of 1.
534
+ return encodeURI(`xref:${this._getUid(apiItem)}`)
535
+ .replace(/[#?]/g, (s) => encodeURIComponent(s))
536
+ .replace(/(\([^(]*\))|[()]/g, (s, balanced) => balanced || '\\' + s);
537
+ }
538
+ });
539
+ return stringBuilder.toString().trim();
540
+ }
541
+ _writeYamlFile(dataObject, filePath, yamlMimeType, schema) {
542
+ JsonFile.validateNoUndefinedMembers(dataObject);
543
+ let stringified = yaml.dump(dataObject, {
544
+ lineWidth: 120
545
+ });
546
+ if (yamlMimeType) {
547
+ stringified = `### YamlMime:${yamlMimeType}\n` + stringified;
548
+ }
549
+ FileSystem.writeFile(filePath, stringified, {
550
+ convertLineEndings: NewlineKind.CrLf,
551
+ ensureFolderExists: true
552
+ });
553
+ if (schema) {
554
+ schema.validateObject(dataObject, filePath);
555
+ }
556
+ }
557
+ /**
558
+ * Calculate the DocFX "uid" for the ApiItem
559
+ * Example: `node-core-library!JsonFile#load`
560
+ */
561
+ _getUid(apiItem) {
562
+ return this._getUidObject(apiItem).toString();
563
+ }
564
+ _getUidObject(apiItem) {
565
+ return apiItem.canonicalReference;
566
+ }
567
+ /**
568
+ * Initialize the _apiItemsByCanonicalReference data structure.
569
+ */
570
+ _initApiItems() {
571
+ this._initApiItemsRecursive(this._apiModel);
572
+ }
573
+ /**
574
+ * Helper for _initApiItems()
575
+ */
576
+ _initApiItemsRecursive(apiItem) {
577
+ if (apiItem.canonicalReference && !apiItem.canonicalReference.isEmpty) {
578
+ this._apiItemsByCanonicalReference.set(apiItem.canonicalReference.toString(), apiItem);
579
+ }
580
+ // Recurse container members
581
+ if (ApiItemContainerMixin.isBaseClassOf(apiItem)) {
582
+ for (const apiMember of apiItem.members) {
583
+ this._initApiItemsRecursive(apiMember);
584
+ }
585
+ }
586
+ }
587
+ _ensureYamlReferences() {
588
+ if (!this._yamlReferences) {
589
+ this._yamlReferences = {
590
+ references: [],
591
+ typeNameToUid: new Map(),
592
+ uidTypeReferenceCounters: new Map()
593
+ };
594
+ }
595
+ return this._yamlReferences;
596
+ }
597
+ _renderInheritance(contextUid, heritageTypes) {
598
+ const result = [];
599
+ for (const heritageType of heritageTypes) {
600
+ const type = this._renderType(contextUid, heritageType.excerpt);
601
+ const yamlInheritance = { type };
602
+ const apiItem = this._apiItemsByCanonicalReference.get(type);
603
+ if (apiItem) {
604
+ if (apiItem instanceof ApiClass) {
605
+ if (apiItem.extendsType) {
606
+ yamlInheritance.inheritance = this._renderInheritance(this._getUidObject(apiItem), [
607
+ apiItem.extendsType
608
+ ]);
609
+ }
610
+ }
611
+ else if (apiItem instanceof ApiInterface) {
612
+ if (apiItem.extendsTypes.length > 0) {
613
+ yamlInheritance.inheritance = this._renderInheritance(this._getUidObject(apiItem), apiItem.extendsTypes);
614
+ }
615
+ }
616
+ }
617
+ result.push(yamlInheritance);
618
+ }
619
+ return result;
620
+ }
621
+ _renderType(contextUid, typeExcerpt) {
622
+ const excerptTokens = [...typeExcerpt.spannedTokens]; // copy the read-only array
623
+ if (excerptTokens.length === 0) {
624
+ return '';
625
+ }
626
+ // Remove the last token if it consists only of whitespace
627
+ const lastToken = excerptTokens[excerptTokens.length - 1];
628
+ if (lastToken.kind === ExcerptTokenKind.Content && !lastToken.text.trim()) {
629
+ excerptTokens.pop();
630
+ if (excerptTokens.length === 0) {
631
+ return '';
632
+ }
633
+ }
634
+ const typeName = typeExcerpt.text.trim();
635
+ // If there are no references to be used for a complex type, return the type name.
636
+ if (!excerptTokens.some((tok) => tok.kind === ExcerptTokenKind.Reference && !!tok.canonicalReference)) {
637
+ return typeName;
638
+ }
639
+ const yamlReferences = this._ensureYamlReferences();
640
+ const existingUid = yamlReferences.typeNameToUid.get(typeName);
641
+ // If this type has already been referenced for the current file, return its uid.
642
+ if (existingUid) {
643
+ return existingUid;
644
+ }
645
+ // If the excerpt consists of a single reference token, record the reference.
646
+ if (excerptTokens.length === 1 &&
647
+ excerptTokens[0].kind === ExcerptTokenKind.Reference &&
648
+ excerptTokens[0].canonicalReference) {
649
+ const excerptRef = excerptTokens[0].canonicalReference.toString();
650
+ const apiItem = this._apiItemsByCanonicalReference.get(excerptRef);
651
+ return this._recordYamlReference(yamlReferences, excerptTokens[0].canonicalReference.toString(), apiItem ? this._getYamlItemName(apiItem) : typeName, apiItem ? this._getYamlItemName(apiItem, { includeNamespace: true }) : typeName);
652
+ }
653
+ // Otherwise, the type is complex and consists of one or more reference tokens. Record a reference
654
+ // and return its uid.
655
+ const baseUid = contextUid.withMeaning(undefined).withOverloadIndex(undefined).toString();
656
+ // Keep track of the count for the base uid (without meaning or overload index) to ensure
657
+ // that each complex type reference is unique.
658
+ const counter = yamlReferences.uidTypeReferenceCounters.get(baseUid) || 0;
659
+ yamlReferences.uidTypeReferenceCounters.set(baseUid, counter + 1);
660
+ const uid = contextUid
661
+ .addNavigationStep(Navigation.Locals, `${counter}`)
662
+ .withMeaning(Meaning.ComplexType)
663
+ .withOverloadIndex(undefined)
664
+ .toString();
665
+ return this._recordYamlReference(yamlReferences, uid, typeName, typeName, excerptTokens);
666
+ }
667
+ _recordYamlReference(yamlReferences, uid, name, fullName, excerptTokens) {
668
+ if (yamlReferences.references.some((ref) => ref.uid === uid)) {
669
+ return uid;
670
+ }
671
+ // Fill in the reference spec from the excerpt.
672
+ const specs = [];
673
+ if (excerptTokens) {
674
+ for (const token of excerptTokens) {
675
+ if (token.kind === ExcerptTokenKind.Reference) {
676
+ const spec = {};
677
+ const specUid = token.canonicalReference && token.canonicalReference.toString();
678
+ const apiItem = specUid
679
+ ? this._apiItemsByCanonicalReference.get(specUid)
680
+ : undefined;
681
+ if (specUid) {
682
+ spec.uid = specUid;
683
+ }
684
+ spec.name = token.text;
685
+ spec.fullName = apiItem
686
+ ? apiItem.getScopedNameWithinPackage()
687
+ : token.canonicalReference
688
+ ? token.canonicalReference
689
+ .withSource(undefined)
690
+ .withMeaning(undefined)
691
+ .withOverloadIndex(undefined)
692
+ .toString()
693
+ : token.text;
694
+ specs.push(spec);
695
+ }
696
+ else {
697
+ specs.push({
698
+ name: token.text,
699
+ fullName: token.text
700
+ });
701
+ }
702
+ }
703
+ }
704
+ const yamlReference = { uid };
705
+ if (specs.length > 0) {
706
+ yamlReference.name = specs
707
+ .map((s) => s.name)
708
+ .join('')
709
+ .trim();
710
+ yamlReference.fullName = specs
711
+ .map((s) => s.fullName || s.name)
712
+ .join('')
713
+ .trim();
714
+ yamlReference['spec.typeScript'] = specs;
715
+ }
716
+ else {
717
+ if (name !== uid) {
718
+ yamlReference.name = name;
719
+ }
720
+ if (fullName !== uid && fullName !== name) {
721
+ yamlReference.fullName = fullName;
722
+ }
723
+ }
724
+ yamlReferences.references.push(yamlReference);
725
+ return uid;
726
+ }
727
+ _getYamlItemName(apiItem, options = {}) {
728
+ const { includeSignature, includeNamespace } = options;
729
+ const baseName = includeSignature ? Utilities.getConciseSignature(apiItem) : apiItem.displayName;
730
+ if ((includeNamespace || apiItem.kind === ApiItemKind.Namespace) &&
731
+ apiItem.parent &&
732
+ apiItem.parent.kind === ApiItemKind.Namespace) {
733
+ // If the immediate parent is a namespace, then add the namespaces to the name. For example:
734
+ //
735
+ // // Name: "N1"
736
+ // export namespace N1 {
737
+ // // Name: "N1.N2"
738
+ // export namespace N2 {
739
+ // // Name: "N1.N2.f(x,y)"
740
+ // export function f(x: string, y: string): string {
741
+ // return x + y;
742
+ // }
743
+ //
744
+ //
745
+ // // Name: "N1.N2.C"
746
+ // export class C {
747
+ // // Name: "member(x,y)" <===========
748
+ // public member(x: string, y: string): string {
749
+ // return x + y;
750
+ // }
751
+ // }
752
+ // }
753
+ // }
754
+ //
755
+ // In the above example, "member(x, y)" does not appear as "N1.N2.C.member(x,y)" because YamlDocumenter
756
+ // embeds this entry in the web page for "N1.N2.C", so the container is obvious. Whereas "N1.N2.f(x,y)"
757
+ // needs to be qualified because the DocFX template doesn't make pages for namespaces. Instead, they get
758
+ // flattened into the package's page.
759
+ const nameParts = [baseName];
760
+ for (let current = apiItem.parent; current; current = current.parent) {
761
+ if (current.kind !== ApiItemKind.Namespace) {
762
+ break;
763
+ }
764
+ nameParts.unshift(current.displayName);
765
+ }
766
+ return nameParts.join('.');
767
+ }
768
+ else {
769
+ return baseName;
770
+ }
771
+ }
772
+ _getYamlFilePath(outputFolder, apiItem) {
773
+ let result = '';
774
+ for (const current of apiItem.getHierarchy()) {
775
+ switch (current.kind) {
776
+ case ApiItemKind.Model:
777
+ case ApiItemKind.EntryPoint:
778
+ break;
779
+ case ApiItemKind.Package:
780
+ result += Utilities.getSafeFilenameForName(PackageName.getUnscopedName(current.displayName));
781
+ break;
782
+ default:
783
+ if (current.parent && current.parent.kind === ApiItemKind.EntryPoint) {
784
+ result += '/';
785
+ }
786
+ else {
787
+ result += '.';
788
+ }
789
+ result += Utilities.getSafeFilenameForName(current.displayName);
790
+ break;
791
+ }
792
+ }
793
+ let disambiguator = '';
794
+ if (apiItem.getMergedSiblings().length > 1) {
795
+ disambiguator = `-${apiItem.kind.toLowerCase()}`;
796
+ }
797
+ return path.join(outputFolder, result + disambiguator + '.yml');
798
+ }
799
+ _deleteOldOutputFiles(outputFolder) {
800
+ console.log('Deleting old output from ' + outputFolder);
801
+ FileSystem.ensureEmptyFolder(outputFolder);
802
+ }
803
+ }
804
+ //# sourceMappingURL=YamlDocumenter.js.map