@textmode/docs 0.4.2 → 0.5.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 (207) hide show
  1. package/LICENSE +21 -121
  2. package/README.md +24 -25
  3. package/dist/cli/textmode-docs.d.ts +3 -0
  4. package/dist/cli/textmode-docs.d.ts.map +1 -0
  5. package/dist/cli/textmode-docs.js +227 -0
  6. package/dist/cli/textmode-docs.js.map +1 -0
  7. package/dist/example-quality.d.ts +59 -0
  8. package/dist/example-quality.d.ts.map +1 -0
  9. package/dist/example-quality.js +256 -0
  10. package/dist/example-quality.js.map +1 -0
  11. package/dist/index.d.ts +33 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +43 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/internal/check-api-documentation.d.ts +5 -0
  16. package/dist/internal/check-api-documentation.d.ts.map +1 -0
  17. package/dist/internal/check-api-documentation.js +74 -0
  18. package/dist/internal/check-api-documentation.js.map +1 -0
  19. package/dist/internal/check-example-sketches.d.ts +3 -0
  20. package/dist/internal/check-example-sketches.d.ts.map +1 -0
  21. package/dist/internal/check-example-sketches.js +76 -0
  22. package/dist/internal/check-example-sketches.js.map +1 -0
  23. package/dist/internal/config.d.ts +104 -0
  24. package/dist/internal/config.d.ts.map +1 -0
  25. package/dist/internal/config.js +324 -0
  26. package/dist/internal/config.js.map +1 -0
  27. package/dist/internal/documentation-commands.d.ts +24 -0
  28. package/dist/internal/documentation-commands.d.ts.map +1 -0
  29. package/dist/internal/documentation-commands.js +43 -0
  30. package/dist/internal/documentation-commands.js.map +1 -0
  31. package/dist/internal/lib/api-doc-checks.d.ts +46 -0
  32. package/dist/internal/lib/api-doc-checks.d.ts.map +1 -0
  33. package/dist/internal/lib/api-doc-checks.js +111 -0
  34. package/dist/internal/lib/api-doc-checks.js.map +1 -0
  35. package/dist/internal/lib/api-doc-routes.d.ts +7 -0
  36. package/dist/internal/lib/api-doc-routes.d.ts.map +1 -0
  37. package/dist/internal/lib/api-doc-routes.js +74 -0
  38. package/dist/internal/lib/api-doc-routes.js.map +1 -0
  39. package/dist/internal/lib/example-checks.d.ts +58 -0
  40. package/dist/internal/lib/example-checks.d.ts.map +1 -0
  41. package/dist/internal/lib/example-checks.js +230 -0
  42. package/dist/internal/lib/example-checks.js.map +1 -0
  43. package/dist/internal/lib/jsdoc-comments.d.ts +8 -0
  44. package/dist/internal/lib/jsdoc-comments.d.ts.map +1 -0
  45. package/dist/internal/lib/jsdoc-comments.js +67 -0
  46. package/dist/internal/lib/jsdoc-comments.js.map +1 -0
  47. package/dist/internal/lib/label-schema.d.ts +18 -0
  48. package/dist/internal/lib/label-schema.d.ts.map +1 -0
  49. package/dist/internal/lib/label-schema.js +17 -0
  50. package/dist/internal/lib/label-schema.js.map +1 -0
  51. package/dist/internal/lib/reflection-policy.d.ts +21 -0
  52. package/dist/internal/lib/reflection-policy.d.ts.map +1 -0
  53. package/dist/internal/lib/reflection-policy.js +96 -0
  54. package/dist/internal/lib/reflection-policy.js.map +1 -0
  55. package/dist/internal/lib/reporting.d.ts +8 -0
  56. package/dist/internal/lib/reporting.d.ts.map +1 -0
  57. package/dist/internal/lib/reporting.js +21 -0
  58. package/dist/internal/lib/reporting.js.map +1 -0
  59. package/dist/internal/lib/sketch-title.d.ts +14 -0
  60. package/dist/internal/lib/sketch-title.d.ts.map +1 -0
  61. package/dist/internal/lib/sketch-title.js +13 -0
  62. package/dist/internal/lib/sketch-title.js.map +1 -0
  63. package/dist/internal/reconcile-dates.d.ts +19 -0
  64. package/dist/internal/reconcile-dates.d.ts.map +1 -0
  65. package/dist/internal/reconcile-dates.js +77 -0
  66. package/dist/internal/reconcile-dates.js.map +1 -0
  67. package/dist/internal/reflection-kinds.d.ts +12 -0
  68. package/dist/internal/reflection-kinds.d.ts.map +1 -0
  69. package/dist/internal/reflection-kinds.js +19 -0
  70. package/dist/internal/reflection-kinds.js.map +1 -0
  71. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/accessor-comments.d.ts +10 -0
  72. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/accessor-comments.d.ts.map +1 -0
  73. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/accessor-comments.js +31 -0
  74. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/accessor-comments.js.map +1 -0
  75. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/index.d.ts +3 -0
  76. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/index.d.ts.map +1 -0
  77. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/index.js +16 -0
  78. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/index.js.map +1 -0
  79. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/render-accessor.d.ts +9 -0
  80. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/render-accessor.d.ts.map +1 -0
  81. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/render-accessor.js +85 -0
  82. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/render-accessor.js.map +1 -0
  83. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/theme-patch.d.ts +7 -0
  84. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/theme-patch.d.ts.map +1 -0
  85. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/theme-patch.js +16 -0
  86. package/dist/internal/typedoc-plugins/accessor-docs-normalizer/theme-patch.js.map +1 -0
  87. package/dist/internal/typedoc-plugins/all-member-pages-router/child-pages.d.ts +16 -0
  88. package/dist/internal/typedoc-plugins/all-member-pages-router/child-pages.d.ts.map +1 -0
  89. package/dist/internal/typedoc-plugins/all-member-pages-router/child-pages.js +33 -0
  90. package/dist/internal/typedoc-plugins/all-member-pages-router/child-pages.js.map +1 -0
  91. package/dist/internal/typedoc-plugins/all-member-pages-router/constants.d.ts +9 -0
  92. package/dist/internal/typedoc-plugins/all-member-pages-router/constants.d.ts.map +1 -0
  93. package/dist/internal/typedoc-plugins/all-member-pages-router/constants.js +44 -0
  94. package/dist/internal/typedoc-plugins/all-member-pages-router/constants.js.map +1 -0
  95. package/dist/internal/typedoc-plugins/all-member-pages-router/index.d.ts +2 -0
  96. package/dist/internal/typedoc-plugins/all-member-pages-router/index.d.ts.map +1 -0
  97. package/dist/internal/typedoc-plugins/all-member-pages-router/index.js +2 -0
  98. package/dist/internal/typedoc-plugins/all-member-pages-router/index.js.map +1 -0
  99. package/dist/internal/typedoc-plugins/all-member-pages-router/member-paths.d.ts +11 -0
  100. package/dist/internal/typedoc-plugins/all-member-pages-router/member-paths.d.ts.map +1 -0
  101. package/dist/internal/typedoc-plugins/all-member-pages-router/member-paths.js +12 -0
  102. package/dist/internal/typedoc-plugins/all-member-pages-router/member-paths.js.map +1 -0
  103. package/dist/internal/typedoc-plugins/all-member-pages-router/member-reflections.d.ts +8 -0
  104. package/dist/internal/typedoc-plugins/all-member-pages-router/member-reflections.d.ts.map +1 -0
  105. package/dist/internal/typedoc-plugins/all-member-pages-router/member-reflections.js +78 -0
  106. package/dist/internal/typedoc-plugins/all-member-pages-router/member-reflections.js.map +1 -0
  107. package/dist/internal/typedoc-plugins/all-member-pages-router/namespace-paths.d.ts +8 -0
  108. package/dist/internal/typedoc-plugins/all-member-pages-router/namespace-paths.d.ts.map +1 -0
  109. package/dist/internal/typedoc-plugins/all-member-pages-router/namespace-paths.js +22 -0
  110. package/dist/internal/typedoc-plugins/all-member-pages-router/namespace-paths.js.map +1 -0
  111. package/dist/internal/typedoc-plugins/all-member-pages-router/router.d.ts +22 -0
  112. package/dist/internal/typedoc-plugins/all-member-pages-router/router.d.ts.map +1 -0
  113. package/dist/internal/typedoc-plugins/all-member-pages-router/router.js +44 -0
  114. package/dist/internal/typedoc-plugins/all-member-pages-router/router.js.map +1 -0
  115. package/dist/internal/typedoc-plugins/api-frontmatter/constants.d.ts +11 -0
  116. package/dist/internal/typedoc-plugins/api-frontmatter/constants.d.ts.map +1 -0
  117. package/dist/internal/typedoc-plugins/api-frontmatter/constants.js +38 -0
  118. package/dist/internal/typedoc-plugins/api-frontmatter/constants.js.map +1 -0
  119. package/dist/internal/typedoc-plugins/api-frontmatter/descriptions.d.ts +18 -0
  120. package/dist/internal/typedoc-plugins/api-frontmatter/descriptions.d.ts.map +1 -0
  121. package/dist/internal/typedoc-plugins/api-frontmatter/descriptions.js +43 -0
  122. package/dist/internal/typedoc-plugins/api-frontmatter/descriptions.js.map +1 -0
  123. package/dist/internal/typedoc-plugins/api-frontmatter/frontmatter.d.ts +5 -0
  124. package/dist/internal/typedoc-plugins/api-frontmatter/frontmatter.d.ts.map +1 -0
  125. package/dist/internal/typedoc-plugins/api-frontmatter/frontmatter.js +29 -0
  126. package/dist/internal/typedoc-plugins/api-frontmatter/frontmatter.js.map +1 -0
  127. package/dist/internal/typedoc-plugins/api-frontmatter/index.d.ts +6 -0
  128. package/dist/internal/typedoc-plugins/api-frontmatter/index.d.ts.map +1 -0
  129. package/dist/internal/typedoc-plugins/api-frontmatter/index.js +19 -0
  130. package/dist/internal/typedoc-plugins/api-frontmatter/index.js.map +1 -0
  131. package/dist/internal/typedoc-plugins/api-frontmatter/library-context.d.ts +9 -0
  132. package/dist/internal/typedoc-plugins/api-frontmatter/library-context.d.ts.map +1 -0
  133. package/dist/internal/typedoc-plugins/api-frontmatter/library-context.js +11 -0
  134. package/dist/internal/typedoc-plugins/api-frontmatter/library-context.js.map +1 -0
  135. package/dist/internal/typedoc-plugins/api-frontmatter/reflection-metadata.d.ts +15 -0
  136. package/dist/internal/typedoc-plugins/api-frontmatter/reflection-metadata.d.ts.map +1 -0
  137. package/dist/internal/typedoc-plugins/api-frontmatter/reflection-metadata.js +46 -0
  138. package/dist/internal/typedoc-plugins/api-frontmatter/reflection-metadata.js.map +1 -0
  139. package/dist/internal/typedoc-plugins/include-code-examples/code-fences.d.ts +7 -0
  140. package/dist/internal/typedoc-plugins/include-code-examples/code-fences.d.ts.map +1 -0
  141. package/dist/internal/typedoc-plugins/include-code-examples/code-fences.js +23 -0
  142. package/dist/internal/typedoc-plugins/include-code-examples/code-fences.js.map +1 -0
  143. package/dist/internal/typedoc-plugins/include-code-examples/example-metadata.d.ts +7 -0
  144. package/dist/internal/typedoc-plugins/include-code-examples/example-metadata.d.ts.map +1 -0
  145. package/dist/internal/typedoc-plugins/include-code-examples/example-metadata.js +18 -0
  146. package/dist/internal/typedoc-plugins/include-code-examples/example-metadata.js.map +1 -0
  147. package/dist/internal/typedoc-plugins/include-code-examples/index.d.ts +4 -0
  148. package/dist/internal/typedoc-plugins/include-code-examples/index.d.ts.map +1 -0
  149. package/dist/internal/typedoc-plugins/include-code-examples/index.js +12 -0
  150. package/dist/internal/typedoc-plugins/include-code-examples/index.js.map +1 -0
  151. package/dist/internal/typedoc-plugins/include-code-examples/transform-markdown.d.ts +2 -0
  152. package/dist/internal/typedoc-plugins/include-code-examples/transform-markdown.d.ts.map +1 -0
  153. package/dist/internal/typedoc-plugins/include-code-examples/transform-markdown.js +17 -0
  154. package/dist/internal/typedoc-plugins/include-code-examples/transform-markdown.js.map +1 -0
  155. package/dist/internal/typedoc-plugins/strip-api-self-links/index.d.ts +8 -0
  156. package/dist/internal/typedoc-plugins/strip-api-self-links/index.d.ts.map +1 -0
  157. package/dist/internal/typedoc-plugins/strip-api-self-links/index.js +62 -0
  158. package/dist/internal/typedoc-plugins/strip-api-self-links/index.js.map +1 -0
  159. package/dist/internal/typedoc-runner.d.ts +31 -0
  160. package/dist/internal/typedoc-runner.d.ts.map +1 -0
  161. package/dist/internal/typedoc-runner.js +179 -0
  162. package/dist/internal/typedoc-runner.js.map +1 -0
  163. package/dist/internal/update-api-links.d.ts +7 -0
  164. package/dist/internal/update-api-links.d.ts.map +1 -0
  165. package/dist/internal/update-api-links.js +65 -0
  166. package/dist/internal/update-api-links.js.map +1 -0
  167. package/package.json +57 -59
  168. package/index.d.ts +0 -37
  169. package/src/cli/textmode-docs.mjs +0 -219
  170. package/src/index.js +0 -23
  171. package/src/internal/config.js +0 -387
  172. package/src/internal/lib/api-doc-checks.mjs +0 -147
  173. package/src/internal/lib/api-doc-routes.mjs +0 -93
  174. package/src/internal/lib/example-checks.mjs +0 -405
  175. package/src/internal/lib/jsdoc-comments.mjs +0 -78
  176. package/src/internal/lib/reflection-policy.mjs +0 -113
  177. package/src/internal/lib/reporting.mjs +0 -23
  178. package/src/internal/operations.js +0 -275
  179. package/src/internal/reconcile-dates.js +0 -72
  180. package/src/internal/reflection-kinds.js +0 -21
  181. package/src/internal/typedoc-plugins/accessor-docs-normalizer/README.md +0 -45
  182. package/src/internal/typedoc-plugins/accessor-docs-normalizer/accessor-comments.js +0 -53
  183. package/src/internal/typedoc-plugins/accessor-docs-normalizer/index.js +0 -32
  184. package/src/internal/typedoc-plugins/accessor-docs-normalizer/render-accessor.js +0 -144
  185. package/src/internal/typedoc-plugins/accessor-docs-normalizer/theme-patch.js +0 -28
  186. package/src/internal/typedoc-plugins/all-member-pages-router/README.md +0 -57
  187. package/src/internal/typedoc-plugins/all-member-pages-router/child-pages.js +0 -65
  188. package/src/internal/typedoc-plugins/all-member-pages-router/constants.js +0 -58
  189. package/src/internal/typedoc-plugins/all-member-pages-router/index.js +0 -18
  190. package/src/internal/typedoc-plugins/all-member-pages-router/member-paths.js +0 -48
  191. package/src/internal/typedoc-plugins/all-member-pages-router/member-reflections.js +0 -164
  192. package/src/internal/typedoc-plugins/all-member-pages-router/namespace-paths.js +0 -44
  193. package/src/internal/typedoc-plugins/all-member-pages-router/router.js +0 -58
  194. package/src/internal/typedoc-plugins/api-frontmatter/README.md +0 -66
  195. package/src/internal/typedoc-plugins/api-frontmatter/constants.js +0 -52
  196. package/src/internal/typedoc-plugins/api-frontmatter/descriptions.js +0 -87
  197. package/src/internal/typedoc-plugins/api-frontmatter/frontmatter.js +0 -57
  198. package/src/internal/typedoc-plugins/api-frontmatter/index.js +0 -39
  199. package/src/internal/typedoc-plugins/api-frontmatter/library-context.js +0 -38
  200. package/src/internal/typedoc-plugins/api-frontmatter/reflection-metadata.js +0 -95
  201. package/src/internal/typedoc-plugins/include-code-examples/README.md +0 -40
  202. package/src/internal/typedoc-plugins/include-code-examples/code-fences.js +0 -55
  203. package/src/internal/typedoc-plugins/include-code-examples/example-metadata.js +0 -41
  204. package/src/internal/typedoc-plugins/include-code-examples/index.js +0 -23
  205. package/src/internal/typedoc-plugins/include-code-examples/transform-markdown.js +0 -33
  206. package/src/internal/typedoc-plugins/strip-api-self-links/index.js +0 -117
  207. package/src/internal/typedoc-runner.js +0 -200
@@ -1,275 +0,0 @@
1
- import fs from 'node:fs';
2
- import os from 'node:os';
3
- import path from 'node:path';
4
-
5
- import { ReflectionKind } from 'typedoc';
6
-
7
- import { collectApiDocIssues, countApiDocIssues, createApiLinkTargets } from './lib/api-doc-checks.mjs';
8
- import { readMarkdownRoutes } from './lib/api-doc-routes.mjs';
9
- import {
10
- checkSketch,
11
- getManifestExamples,
12
- readExamplesIndex,
13
- readExamplesManifest,
14
- validateExamplesGallery,
15
- validateExamplesManifest,
16
- } from './lib/example-checks.mjs';
17
- import { findJsdocBeforeLine, getLineStartOffsets, upsertSeeLine } from './lib/jsdoc-comments.mjs';
18
- import {
19
- getIncludedReflections,
20
- shouldProcessEntryPointReflection,
21
- sourceIsInRoots,
22
- } from './lib/reflection-policy.mjs';
23
- import { renderIssueSection, renderList } from './lib/reporting.mjs';
24
- import { reflectionKindsMask, withAccessorKind } from './reflection-kinds.js';
25
- import { buildDocs, loadEntryPointProject, watchDocs } from './typedoc-runner.js';
26
-
27
- async function withTemporaryDocs(config, { strict = false } = {}, callback) {
28
- const outputDir = fs.mkdtempSync(path.join(os.tmpdir(), 'textmode-docs-'));
29
- try {
30
- const result = await buildDocs(config, { outputDir, strict });
31
- if (!result.ok) {
32
- return { ok: false, reason: 'typedoc' };
33
- }
34
- return await callback({ outputDir });
35
- } finally {
36
- fs.rmSync(outputDir, { recursive: true, force: true });
37
- }
38
- }
39
-
40
- function checkKinds(config, includeAccessors) {
41
- const docstrings = includeAccessors ? withAccessorKind(config.checks.docstrings) : config.checks.docstrings;
42
- const examples = includeAccessors ? withAccessorKind(config.checks.examples) : config.checks.examples;
43
- return {
44
- apiLinks: reflectionKindsMask(config.checks.apiLinks),
45
- docstrings: reflectionKindsMask(docstrings),
46
- examples: reflectionKindsMask(examples),
47
- };
48
- }
49
-
50
- function exampleScopeLabel(targetKinds) {
51
- return targetKinds & ReflectionKind.Accessor
52
- ? 'exported functions, methods, and accessors'
53
- : 'exported functions and methods';
54
- }
55
-
56
- async function loadCheckProjects(config) {
57
- const entryPoints = config.linkEntryPoints.length
58
- ? config.linkEntryPoints
59
- : [{ path: config.entryPoints[0], tsconfig: config.tsconfig }];
60
- return Promise.all(
61
- entryPoints.map((entryPoint) =>
62
- loadEntryPointProject({
63
- entryPoint: entryPoint.path,
64
- tsconfig: entryPoint.tsconfig,
65
- packageName: config.packageName,
66
- projectRoot: config.projectRoot,
67
- })
68
- )
69
- );
70
- }
71
-
72
- export async function apiCheck(config, routes, { includeAccessors = false } = {}) {
73
- const projects = await loadCheckProjects(config);
74
- const kinds = checkKinds(config, includeAccessors);
75
- const apiLinkReflections = projects.flatMap((project) => getIncludedReflections(project, kinds.apiLinks));
76
- const docstringReflections = projects.flatMap((project) => getIncludedReflections(project, kinds.docstrings));
77
- const exampleReflections = projects.flatMap((project) => getIncludedReflections(project, kinds.examples));
78
- const issues = collectApiDocIssues({
79
- apiBaseUrl: config.apiBaseUrl,
80
- apiLinkReflections,
81
- docstringReflections,
82
- exampleReflections,
83
- routes,
84
- });
85
- const issueCount = countApiDocIssues(issues);
86
- const entryPoints = config.linkEntryPoints.map((entryPoint) => path.relative(config.projectRoot, entryPoint.path));
87
- const entryPointLabel = entryPoints.join(', ');
88
- const scopeLabel = exampleScopeLabel(kinds.examples);
89
-
90
- if (issueCount === 0) {
91
- console.log('Public API documentation check passed.');
92
- console.log(
93
- `Scanned ${docstringReflections.length} documented public API reflections from ${entryPointLabel}.`
94
- );
95
- console.log('Policy: skip private/protected/inherited members and any API path segment starting with "_".');
96
- console.log('Every included API item has a JSDoc docstring and a valid code.textmode.art API link.');
97
- console.log(`Every included ${scopeLabel} has at least one @example tag.`);
98
- if (!includeAccessors && !config.checks.examples.includes('accessor')) {
99
- console.log('Accessors are excluded by default. Re-run with --include-accessors to check them too.');
100
- }
101
- return true;
102
- }
103
-
104
- console.error('Public API documentation check failed.');
105
- console.error(`Scanned ${docstringReflections.length} documented public API reflections from ${entryPointLabel}.`);
106
- console.error('Policy: skip private/protected/inherited members and any API path segment starting with "_".');
107
- console.error(
108
- `Found ${issueCount} issue(s): ${issues.missingDocstrings.length} missing docstring, ${issues.missingExamples.length} missing @example, ${issues.missingApiLinks.length} missing API link, ${issues.invalidApiLinks.length} invalid API link.`
109
- );
110
- if (!includeAccessors && !config.checks.examples.includes('accessor')) {
111
- console.error('Accessors are excluded by default. Re-run with --include-accessors to check them too.');
112
- }
113
- renderIssueSection('Missing JSDoc docstring', issues.missingDocstrings, console.error);
114
- renderIssueSection('Missing @example tag', issues.missingExamples, console.error);
115
- renderIssueSection('Missing code.textmode.art API link', issues.missingApiLinks, console.error);
116
- renderIssueSection('Invalid code.textmode.art API link', issues.invalidApiLinks, console.error);
117
- return false;
118
- }
119
-
120
- export function examplesCheck(config) {
121
- if (config.examples === false) {
122
- console.log('Example checks are disabled for this package.');
123
- return true;
124
- }
125
-
126
- console.log(`Checking ${config.packageName} example sketches...`);
127
- const examplesIndex = path.join(config.projectRoot, 'examples/index.html');
128
- const examplesManifest = path.join(config.projectRoot, 'examples/manifest.json');
129
- const sourceDir = path.join(config.projectRoot, 'src');
130
- const indexContent = readExamplesIndex(examplesIndex);
131
- const manifest = readExamplesManifest(examplesManifest);
132
- const galleryIssues = validateExamplesGallery(indexContent, {
133
- examplesIndex: 'examples/index.html',
134
- examplesManifest: 'examples/manifest.json',
135
- forbidGallerySourceBase: config.examples.forbidGallerySourceBase,
136
- });
137
- const manifestIssues = validateExamplesManifest(manifest, {
138
- projectRoot: config.projectRoot,
139
- examplesDir: 'examples',
140
- examplesManifest: 'examples/manifest.json',
141
- sourceDir,
142
- });
143
- const validationIssues = [...galleryIssues, ...manifestIssues];
144
- if (validationIssues.length > 0) {
145
- renderList('Examples validation failed:', validationIssues);
146
- return false;
147
- }
148
-
149
- const files = getManifestExamples(manifest).map((example) => example.sourceFile);
150
- console.log(`Found ${files.length} manifest examples from examples/manifest.json.`);
151
-
152
- let passedCount = 0;
153
- let failedCount = 0;
154
- let skippedCount = 0;
155
- const failures = [];
156
- for (const file of files) {
157
- const { skipped, issues } = checkSketch(path.join(config.projectRoot, file));
158
- if (skipped) {
159
- skippedCount += 1;
160
- } else if (issues.length === 0) {
161
- passedCount += 1;
162
- } else {
163
- failedCount += 1;
164
- failures.push({ file, issues });
165
- }
166
- }
167
-
168
- console.log(`\nResults: ${passedCount} passed, ${failedCount} failed, ${skippedCount} skipped.\n`);
169
- if (failures.length === 0) {
170
- console.log('All checked sketches meet the requirements successfully.');
171
- return true;
172
- }
173
-
174
- console.error('Validation failed for the following sketches:');
175
- for (const failure of failures) {
176
- console.error(`\n- ${failure.file}:`);
177
- for (const issue of failure.issues) {
178
- console.error(` * ${issue}`);
179
- }
180
- }
181
- return false;
182
- }
183
-
184
- async function collectPendingEdits(config, routes) {
185
- const pendingByFile = new Map();
186
- const targetKinds = reflectionKindsMask(config.checks.apiLinks);
187
-
188
- for (const entryPoint of config.linkEntryPoints) {
189
- const project = await loadEntryPointProject({
190
- entryPoint: entryPoint.path,
191
- tsconfig: entryPoint.tsconfig,
192
- packageName: config.packageName,
193
- projectRoot: config.projectRoot,
194
- });
195
- const reflections = getIncludedReflections(project, targetKinds);
196
-
197
- for (const reflection of reflections) {
198
- if (!shouldProcessEntryPointReflection(entryPoint, reflection)) {
199
- continue;
200
- }
201
- for (const target of createApiLinkTargets(reflection, routes, config.apiBaseUrl)) {
202
- if (!target.source?.line || !sourceIsInRoots(target.source, config.sourceRoots)) {
203
- continue;
204
- }
205
- const entries = pendingByFile.get(target.source.fullFileName) ?? [];
206
- entries.push({ line: target.source.line, seeLine: target.seeLine });
207
- pendingByFile.set(target.source.fullFileName, entries);
208
- }
209
- }
210
- }
211
- return pendingByFile;
212
- }
213
-
214
- function applyPendingEdits(config, pendingByFile) {
215
- let changedFiles = 0;
216
- let insertedLinks = 0;
217
-
218
- for (const [fileName, entries] of pendingByFile) {
219
- const originalText = fs.readFileSync(fileName, 'utf8');
220
- let text = originalText;
221
- const uniqueEntries = Array.from(
222
- new Map(entries.map((entry) => [`${entry.line}\0${entry.seeLine}`, entry])).values()
223
- );
224
- for (const entry of uniqueEntries.sort((left, right) => right.line - left.line)) {
225
- const before = text;
226
- const lineStarts = getLineStartOffsets(text);
227
- const comment = findJsdocBeforeLine(text, lineStarts, entry.line);
228
- if (!comment) {
229
- continue;
230
- }
231
- text = upsertSeeLine(text, comment, entry.seeLine, config.apiBaseUrl);
232
- if (text !== before) {
233
- insertedLinks += 1;
234
- }
235
- }
236
- if (text !== originalText) {
237
- fs.writeFileSync(fileName, text);
238
- changedFiles += 1;
239
- }
240
- }
241
- return { changedFiles, insertedLinks };
242
- }
243
-
244
- export async function checkDocumentation(config) {
245
- return withTemporaryDocs(config, { strict: true }, async ({ outputDir }) => {
246
- const routes = readMarkdownRoutes(outputDir);
247
- const apiOk = await apiCheck(config, routes);
248
- const examplesOk = examplesCheck(config);
249
- return { ok: apiOk && examplesOk };
250
- });
251
- }
252
-
253
- export async function checkApiDocumentation(config, options = {}) {
254
- return withTemporaryDocs(config, {}, async ({ outputDir }) => ({
255
- ok: await apiCheck(config, readMarkdownRoutes(outputDir), options),
256
- }));
257
- }
258
-
259
- export async function addApiLinks(config) {
260
- return withTemporaryDocs(config, {}, async ({ outputDir }) => {
261
- const routes = readMarkdownRoutes(outputDir);
262
- const pendingByFile = await collectPendingEdits(config, routes);
263
- const result = applyPendingEdits(config, pendingByFile);
264
- console.log(`Inserted ${result.insertedLinks} API reference link(s) in ${result.changedFiles} file(s).`);
265
- return { ok: true, ...result };
266
- });
267
- }
268
-
269
- export async function generateDocumentation(config) {
270
- return buildDocs(config, { outputDir: config.outputDir });
271
- }
272
-
273
- export async function watchDocumentation(config) {
274
- return watchDocs(config, { outputDir: config.outputDir });
275
- }
@@ -1,72 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
-
4
- // Work on the YAML block as text so other fields and the page body stay byte-for-byte intact.
5
- function splitDate(markdown) {
6
- const match = /^(---\r?\n)([\s\S]*?)(^---[ \t]*\r?\n|^---[ \t]*$)/m.exec(markdown);
7
- if (!match || match.index !== 0) throw new Error('Markdown page is missing YAML frontmatter.');
8
- let date;
9
- const fields = match[2].replace(/^lastModified:[ \t]*([^\r\n]*)\r?\n/gm, (_, value) => {
10
- if (date !== undefined) throw new Error('Duplicate lastModified field.');
11
- date = value.trim().replace(/^['"]|['"]$/g, '');
12
- return '';
13
- });
14
- return { date, content: match[1] + fields + match[3] + markdown.slice(match[0].length) };
15
- }
16
-
17
- async function markdownFiles(directory, prefix = '') {
18
- const entries = await fs.readdir(path.join(directory, prefix), { withFileTypes: true });
19
- const files = [];
20
- for (const entry of entries) {
21
- const relative = path.join(prefix, entry.name);
22
- if (entry.isDirectory()) files.push(...(await markdownFiles(directory, relative)));
23
- else if (entry.isFile() && entry.name.endsWith('.md')) files.push(relative);
24
- }
25
- return files.sort();
26
- }
27
-
28
- export async function reconcileDates({ baseline, target, date = new Date().toISOString().slice(0, 10) }) {
29
- baseline = path.resolve(baseline);
30
- target = path.resolve(target);
31
- if (baseline === target || baseline.startsWith(target + path.sep) || target.startsWith(baseline + path.sep)) {
32
- throw new Error('Baseline and target must be separate directories.');
33
- }
34
- const timestamp = Date.parse(`${date}T00:00:00Z`);
35
- if (
36
- !/^\d{4}-\d{2}-\d{2}$/.test(date) ||
37
- Number.isNaN(timestamp) ||
38
- new Date(timestamp).toISOString().slice(0, 10) !== date
39
- ) {
40
- throw new Error('Date must be in YYYY-MM-DD format.');
41
- }
42
- await fs.access(baseline);
43
- const files = await markdownFiles(target);
44
- for (const file of files) {
45
- const targetPath = path.join(target, file);
46
- const current = splitDate(await fs.readFile(targetPath, 'utf8'));
47
- let previous;
48
- try {
49
- previous = splitDate(await fs.readFile(path.join(baseline, file), 'utf8'));
50
- } catch (error) {
51
- if (error.code !== 'ENOENT') throw error;
52
- }
53
- const lastModified = previous && previous.content === current.content && previous.date ? previous.date : date;
54
- const output = current.content.replace(
55
- /^(---\r?\n)([\s\S]*?)(^---[ \t]*\r?\n|^---[ \t]*$)/m,
56
- (_, opening, fields, closing) => {
57
- const marker = /^(?:hasConstructor|isInterface):/m.exec(fields);
58
- const position = marker ? marker.index : fields.length;
59
- const newline = opening.endsWith('\r\n') ? '\r\n' : '\n';
60
- return (
61
- opening +
62
- fields.slice(0, position) +
63
- `lastModified: ${lastModified}${newline}` +
64
- fields.slice(position) +
65
- closing
66
- );
67
- }
68
- );
69
- await fs.writeFile(targetPath, output);
70
- }
71
- return files.length;
72
- }
@@ -1,21 +0,0 @@
1
- import { ReflectionKind } from 'typedoc';
2
-
3
- const REFLECTION_KIND_BY_NAME = new Map([
4
- ['class', ReflectionKind.Class],
5
- ['interface', ReflectionKind.Interface],
6
- ['typeAlias', ReflectionKind.TypeAlias],
7
- ['enum', ReflectionKind.Enum],
8
- ['variable', ReflectionKind.Variable],
9
- ['function', ReflectionKind.Function],
10
- ['method', ReflectionKind.Method],
11
- ['accessor', ReflectionKind.Accessor],
12
- ['property', ReflectionKind.Property],
13
- ]);
14
-
15
- export function reflectionKindsMask(kindNames) {
16
- return kindNames.reduce((mask, kindName) => mask | REFLECTION_KIND_BY_NAME.get(kindName), 0);
17
- }
18
-
19
- export function withAccessorKind(kindNames) {
20
- return kindNames.includes('accessor') ? kindNames : [...kindNames, 'accessor'];
21
- }
@@ -1,45 +0,0 @@
1
- # Accessor Docs Normalizer
2
-
3
- ## Purpose
4
-
5
- TypeDoc stores comments for TypeScript accessors on the getter and setter signatures. `typedoc-plugin-markdown`
6
- overview tables read descriptions from the accessor reflection itself. When the reflection has no direct comment,
7
- the generated table falls back to `-` even though the getter or setter is documented in source.
8
-
9
- This plugin normalizes that shape for the textmode.js API docs:
10
-
11
- - Copies the first getter or setter signature comment onto an accessor reflection when the accessor has no comment.
12
- - Tracks copied comments so the accessor page does not render the same summary twice.
13
- - Replaces the markdown accessor partial so getter documentation appears before setter documentation.
14
- - Keeps getter return sections, setter parameter sections, inheritance sections, and `disableSources` behavior intact.
15
-
16
- The plugin does not change runtime library behavior, the public TypeScript API, source JSDoc ownership, or TypeDoc
17
- reflection conversion. It only adjusts markdown rendering after TypeDoc has built the reflection model.
18
-
19
- This exists to avoid source-level documentation stubs or declaration-merging boilerplate for accessor descriptions.
20
- Accessor docs should stay in the source declarations that own the getter and setter behavior.
21
-
22
- ## Preserved Output Contract
23
-
24
- - Accessor overview tables show the first available getter or setter summary.
25
- - Accessor pages do not render copied comments twice.
26
- - Getter content renders before setter content.
27
- - Getter return sections, setter parameter sections, inheritance sections, and `disableSources` behavior match
28
- `typedoc-plugin-markdown`.
29
-
30
- ## Contributor Notes
31
-
32
- - Safe to edit: helper names, tests, README wording, and the local comment-normalization traversal.
33
- - Be careful with: `theme-patch.js`, because it monkey-patches `MarkdownTheme.prototype.getRenderContext`.
34
- - Do not casually change: accessor partial output order, copied-comment tracking, or source-display conditions.
35
-
36
- ## Maintenance
37
-
38
- This plugin depends on `typedoc-plugin-markdown` theme internals, especially `MarkdownTheme.getRenderContext` and the
39
- `partials.accessor` contract. Re-check this plugin after upgrading `typedoc-plugin-markdown`.
40
-
41
- Upgrade checklist:
42
-
43
- - Compare `render-accessor.js` against the current upstream accessor partial.
44
- - Confirm `MarkdownTheme.getRenderContext` still exists and returns a mutable partials object.
45
- - Run `npm run test:tooling` and inspect generated accessor pages for duplicate summaries.
@@ -1,53 +0,0 @@
1
- // @ts-check
2
-
3
- import { ReflectionKind } from 'typedoc';
4
-
5
- const syntheticAccessorComments = new WeakSet();
6
-
7
- /**
8
- * Get the first signature-level comment available for an accessor reflection.
9
- * TypeDoc currently keeps getter/setter comments on their signatures, while
10
- * overview tables read from the accessor declaration itself.
11
- *
12
- * @param {import('typedoc').DeclarationReflection} accessor
13
- * @returns {import('typedoc').Comment | undefined}
14
- */
15
- function getAccessorSignatureComment(accessor) {
16
- return accessor.getSignature?.comment ?? accessor.setSignature?.comment;
17
- }
18
-
19
- /**
20
- * Copy signature comments onto accessor declarations when needed so markdown
21
- * overview tables can render descriptions instead of falling back to "-".
22
- *
23
- * @param {import('typedoc').Reflection | undefined} model
24
- * @returns {void}
25
- */
26
- export function normalizeAccessorComments(model) {
27
- if (!model) {
28
- return;
29
- }
30
-
31
- if (model.kind === ReflectionKind.Accessor && 'comment' in model && !model.comment) {
32
- const signatureComment = getAccessorSignatureComment(model);
33
- if (signatureComment) {
34
- model.comment = signatureComment;
35
- syntheticAccessorComments.add(model);
36
- }
37
- }
38
-
39
- model.traverse?.((child) => {
40
- normalizeAccessorComments(child);
41
- return true;
42
- });
43
- }
44
-
45
- /**
46
- * Check whether a comment was copied onto an accessor by this plugin.
47
- *
48
- * @param {import('typedoc').DeclarationReflection} accessor
49
- * @returns {boolean}
50
- */
51
- export function hasSyntheticAccessorComment(accessor) {
52
- return syntheticAccessorComments.has(accessor);
53
- }
@@ -1,32 +0,0 @@
1
- // @ts-check
2
-
3
- import { MarkdownTheme, MarkdownThemeContext } from 'typedoc-plugin-markdown';
4
-
5
- import { normalizeAccessorComments } from './accessor-comments.js';
6
- import { renderAccessorDocs } from './render-accessor.js';
7
- import { patchMarkdownThemeRenderContext } from './theme-patch.js';
8
-
9
- class AccessorDocsMarkdownThemeContext extends MarkdownThemeContext {
10
- /**
11
- * @param {MarkdownTheme} theme
12
- * @param {import('typedoc-plugin-markdown').MarkdownPageEvent<import('typedoc').Reflection>} page
13
- * @param {import('typedoc').Options} options
14
- */
15
- constructor(theme, page, options) {
16
- super(theme, page, options);
17
- normalizeAccessorComments(page.model);
18
- this.partials.accessor = (accessor, partialOptions) => renderAccessorDocs(this, accessor, partialOptions);
19
- }
20
- }
21
-
22
- /**
23
- * @param {import('typedoc').Application} app
24
- * @returns {void}
25
- */
26
- export function load(app) {
27
- patchMarkdownThemeRenderContext(
28
- (theme, page) => new AccessorDocsMarkdownThemeContext(theme, page, theme.application.options)
29
- );
30
-
31
- app.logger.verbose('[typedoc] Registered accessor docs normalizer');
32
- }
@@ -1,144 +0,0 @@
1
- // @ts-check
2
-
3
- import { i18n, ReflectionKind } from 'typedoc';
4
-
5
- import { hasSyntheticAccessorComment } from './accessor-comments.js';
6
-
7
- /**
8
- * @param {number} level
9
- * @param {string} text
10
- * @returns {string}
11
- */
12
- function heading(level, text) {
13
- return `${'#'.repeat(level)} ${text}`;
14
- }
15
-
16
- /**
17
- * Render one getter or setter signature.
18
- *
19
- * @param {import('typedoc-plugin-markdown').MarkdownThemeContext} context
20
- * @param {import('typedoc').SignatureReflection} signature
21
- * @param {{
22
- * accessor: 'get' | 'set';
23
- * headingLevel: number;
24
- * includeParameters: boolean;
25
- * showSources: boolean;
26
- * title: string;
27
- * }} options
28
- * @returns {string}
29
- */
30
- function renderAccessorSignature(context, signature, options) {
31
- const md = [];
32
-
33
- md.push(heading(options.headingLevel, options.title));
34
- md.push(
35
- context.partials.signatureTitle(signature, {
36
- accessor: options.accessor,
37
- })
38
- );
39
-
40
- if (options.showSources && !context.options.getValue('disableSources') && signature.sources) {
41
- md.push(context.partials.sources(signature));
42
- }
43
-
44
- if (signature.comment) {
45
- md.push(
46
- context.partials.comment(signature.comment, {
47
- headingLevel: options.headingLevel + 1,
48
- showTags: false,
49
- showSummary: true,
50
- })
51
- );
52
- }
53
-
54
- if (options.includeParameters && signature.parameters?.length) {
55
- md.push(heading(options.headingLevel + 1, ReflectionKind.pluralString(ReflectionKind.Parameter)));
56
- if (context.helpers.useTableFormat('parameters')) {
57
- md.push(context.partials.parametersTable(signature.parameters));
58
- } else {
59
- md.push(
60
- context.partials.parametersList(signature.parameters, {
61
- headingLevel: options.headingLevel + 1,
62
- })
63
- );
64
- }
65
- }
66
-
67
- if (signature.type) {
68
- md.push(
69
- context.partials.signatureReturns(signature, {
70
- headingLevel: options.headingLevel + 1,
71
- })
72
- );
73
- }
74
-
75
- if (signature.comment) {
76
- md.push(
77
- context.partials.comment(signature.comment, {
78
- headingLevel: options.headingLevel + 1,
79
- showTags: true,
80
- showSummary: false,
81
- })
82
- );
83
- }
84
-
85
- return md.filter(Boolean).join('\n\n');
86
- }
87
-
88
- /**
89
- * Render accessor documentation with getter content before setter content.
90
- *
91
- * @param {import('typedoc-plugin-markdown').MarkdownThemeContext} context
92
- * @param {import('typedoc').DeclarationReflection} accessor
93
- * @param {{ headingLevel: number }} options
94
- * @returns {string}
95
- */
96
- export function renderAccessorDocs(context, accessor, options) {
97
- const md = [];
98
- const showSources = accessor.parent?.kind !== ReflectionKind.TypeLiteral;
99
-
100
- if (accessor.getSignature) {
101
- md.push(
102
- renderAccessorSignature(context, accessor.getSignature, {
103
- accessor: 'get',
104
- headingLevel: options.headingLevel,
105
- includeParameters: false,
106
- showSources,
107
- title: i18n.kind_get_signature(),
108
- })
109
- );
110
- }
111
-
112
- if (accessor.setSignature) {
113
- md.push(
114
- renderAccessorSignature(context, accessor.setSignature, {
115
- accessor: 'set',
116
- headingLevel: options.headingLevel,
117
- includeParameters: true,
118
- showSources,
119
- title: i18n.kind_set_signature(),
120
- })
121
- );
122
- }
123
-
124
- if (
125
- showSources &&
126
- !context.options.getValue('disableSources') &&
127
- !accessor.getSignature &&
128
- !accessor.setSignature
129
- ) {
130
- md.push(context.partials.sources(accessor));
131
- }
132
-
133
- if (accessor.comment && !hasSyntheticAccessorComment(accessor)) {
134
- md.push(
135
- context.partials.comment(accessor.comment, {
136
- headingLevel: options.headingLevel,
137
- })
138
- );
139
- }
140
-
141
- md.push(context.partials.inheritance(accessor, { headingLevel: options.headingLevel }));
142
-
143
- return md.filter(Boolean).join('\n\n');
144
- }
@@ -1,28 +0,0 @@
1
- // @ts-check
2
-
3
- import { MarkdownTheme } from 'typedoc-plugin-markdown';
4
-
5
- let isPatched = false;
6
-
7
- /**
8
- * Patch typedoc-plugin-markdown's theme render-context factory once.
9
- *
10
- * This is the only place this plugin reaches into markdown theme internals.
11
- * Keep the patch idempotent because TypeDoc can load plugins repeatedly in
12
- * watch mode and tests can import the plugin more than once.
13
- *
14
- * @param {(theme: MarkdownTheme, page: import('typedoc-plugin-markdown').MarkdownPageEvent<import('typedoc').Reflection>) => import('typedoc-plugin-markdown').MarkdownThemeContext} createContext
15
- * @returns {boolean} True when this call installed the patch.
16
- */
17
- export function patchMarkdownThemeRenderContext(createContext) {
18
- if (isPatched) {
19
- return false;
20
- }
21
-
22
- MarkdownTheme.prototype.getRenderContext = function (page) {
23
- return createContext(this, page);
24
- };
25
- isPatched = true;
26
-
27
- return true;
28
- }