@astryxdesign/cli 0.6.3-canary.1f30d4e → 0.6.3-canary.1ffe66d

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 (181) hide show
  1. package/README.md +19 -17
  2. package/api/component/_adapter.d.mts +6 -12
  3. package/api/component/_adapter.mjs +20 -10
  4. package/api/component/component.mjs +60 -12
  5. package/api/component/list/list.mjs +3 -2
  6. package/api/docs/_adapter.d.mts +209 -28
  7. package/api/docs/_adapter.mjs +667 -35
  8. package/api/docs/detail/detail.mjs +11 -3
  9. package/api/docs/detail/section/section.mjs +20 -3
  10. package/api/docs/docs.d.mts +5 -3
  11. package/api/docs/docs.doc.mjs +35 -15
  12. package/api/docs/docs.mjs +44 -8
  13. package/api/docs/docs.test.mjs +158 -4
  14. package/api/docs/docs.type.d.mts +165 -2
  15. package/api/docs/docs.type.mjs +101 -3
  16. package/api/docs/index/index.mjs +11 -3
  17. package/api/docs/index/index.test.mjs +1 -1
  18. package/api/docs/integration-tree.test.mjs +547 -0
  19. package/api/docs/integrationDocs.test.mjs +14 -14
  20. package/api/docs/list/list.mjs +25 -5
  21. package/api/docs/node/node.d.mts +43 -0
  22. package/api/docs/node/node.mjs +192 -0
  23. package/api/doctor/doctor.d.mts +30 -2
  24. package/api/doctor/doctor.mjs +146 -7
  25. package/api/doctor/doctor.test.mjs +89 -1
  26. package/api/index.d.mts +1 -1
  27. package/api/index.mjs +1 -0
  28. package/api/init/init.doc.mjs +1 -1
  29. package/api/integration/add-contribution.d.mts +2 -1
  30. package/api/integration/add-contribution.mjs +107 -5
  31. package/api/integration/add-contribution.test.mjs +137 -0
  32. package/api/integration/authoring-checks.mjs +125 -28
  33. package/api/integration/authoring-checks.test.mjs +171 -3
  34. package/api/integration/authoring-checks.type.mjs +6 -1
  35. package/api/integration/integration-authoring.type.d.mts +2 -0
  36. package/api/integration/integration-authoring.type.mjs +2 -0
  37. package/api/integration/integrationAdd.doc.mjs +6 -0
  38. package/api/integration/integrationAddDoc.doc.mjs +7 -1
  39. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  40. package/api/integration/integrationPackCheck.doc.mjs +1 -1
  41. package/api/integration/integrationTemplateConflicts.doc.d.mts +3 -0
  42. package/api/integration/integrationTemplateConflicts.doc.mjs +3 -0
  43. package/api/integration/pack-check.mjs +34 -0
  44. package/api/integration/pack-check.test.mjs +121 -0
  45. package/api/integration/pack-check.type.d.mts +26 -2
  46. package/api/integration/pack-check.type.mjs +14 -1
  47. package/api/integration/template-conflict-compatibility.test.mjs +73 -0
  48. package/api/integration/validate-integration.test.mjs +3 -3
  49. package/api/integration/validateIntegration.doc.mjs +1 -1
  50. package/api/json/index.ts +2 -0
  51. package/api/layout/_adapter.mjs +20 -5
  52. package/api/search/search.d.mts +26 -1
  53. package/api/search/search.doc.mjs +4 -3
  54. package/api/search/search.mjs +308 -29
  55. package/api/search/search.test.mjs +91 -2
  56. package/api/search/search.type.d.mts +13 -1
  57. package/api/search/search.type.mjs +4 -1
  58. package/api/template/list/list.mjs +1 -0
  59. package/api/template/template-integration.test.mjs +1022 -3
  60. package/api/template/template.doc.mjs +27 -7
  61. package/api/template/template.mjs +45 -8
  62. package/api/template/template.type.d.mts +6 -8
  63. package/api/template/template.type.mjs +3 -2
  64. package/api/theme/template/template.test.mjs +5 -0
  65. package/api/theme/themeTemplate.doc.mjs +1 -1
  66. package/assets/docs/getting-started.doc.mjs +2 -2
  67. package/assets/docs/principles.doc.mjs +6 -6
  68. package/assets/docs/styling-libraries.doc.mjs +2 -2
  69. package/assets/docs/styling.doc.mjs +4 -4
  70. package/assets/docs/theme.doc.mjs +3 -3
  71. package/assets/docs/tokens.doc.mjs +1 -1
  72. package/assets/docs/tree/api.doc.mjs +30 -0
  73. package/assets/docs/tree/cli.doc.mjs +23 -0
  74. package/assets/docs/tree/commands.doc.mjs +25 -0
  75. package/assets/docs/{cli-integrations.doc.mjs → tree/integrations.doc.mjs} +37 -9
  76. package/assets/docs/tree/integrations.test.mjs +62 -0
  77. package/assets/docs/tree/writing-docs.doc.mjs +286 -0
  78. package/authoring/debug/parse.d.mts +3 -3
  79. package/authoring/doctypes/base/graph-fields.doc.mjs +7 -5
  80. package/authoring/doctypes/base/type.ts +6 -5
  81. package/authoring/doctypes/command/command.doc.mjs +1 -1
  82. package/authoring/doctypes/command/type.ts +2 -2
  83. package/authoring/doctypes/enum/enum.doc.mjs +1 -1
  84. package/authoring/doctypes/enum/type.ts +1 -1
  85. package/authoring/doctypes/function/function.doc.mjs +3 -2
  86. package/authoring/doctypes/function/type.ts +3 -2
  87. package/authoring/doctypes/namespace/namespace.doc.mjs +5 -9
  88. package/authoring/doctypes/reference/reference.doc.mjs +3 -3
  89. package/authoring/doctypes/reference/type.ts +3 -0
  90. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  91. package/authoring/doctypes/schema/type.ts +1 -1
  92. package/authoring/doctypes/template/parse.d.mts +2 -0
  93. package/authoring/doctypes/template/parse.mjs +4 -0
  94. package/authoring/doctypes/template/parse.test.mjs +18 -0
  95. package/authoring/doctypes/template/template.doc.mjs +6 -0
  96. package/authoring/doctypes/template/type.ts +8 -0
  97. package/authoring/identity/identity.doc.mjs +2 -2
  98. package/authoring/integration/type.ts +1 -1
  99. package/clients/cli/commands/build-theme.mjs +1 -1
  100. package/clients/cli/commands/build.mjs +5 -2
  101. package/clients/cli/commands/component/index.mjs +1 -1
  102. package/clients/cli/commands/component-ownership.test.mjs +3 -3
  103. package/clients/cli/commands/discover.broken-integration.test.mjs +7 -8
  104. package/clients/cli/commands/discover.mjs +1 -1
  105. package/clients/cli/commands/docs.doc.mjs +20 -8
  106. package/clients/cli/commands/docs.mjs +175 -18
  107. package/clients/cli/commands/docs.test.mjs +114 -7
  108. package/clients/cli/commands/doctor-integration-docs.doc.mjs +2 -2
  109. package/clients/cli/commands/doctor-integration-templates.doc.mjs +14 -7
  110. package/clients/cli/commands/doctor-integration.test.mjs +75 -1
  111. package/clients/cli/commands/doctor.mjs +53 -16
  112. package/clients/cli/commands/integration-add.doc.mjs +10 -0
  113. package/clients/cli/commands/integration.mjs +1 -0
  114. package/clients/cli/commands/search.mjs +11 -2
  115. package/clients/cli/commands/setup-nudge.test.mjs +6 -0
  116. package/clients/cli/commands/template.doc.mjs +23 -6
  117. package/clients/cli/commands/template.mjs +4 -91
  118. package/clients/cli/commands/text-json-parity.test.mjs +2 -1
  119. package/clients/cli/index.mjs +8 -0
  120. package/clients/cli/lib/manifest.mjs +9 -2
  121. package/foundation/agent-docs/agent-docs.mjs +1 -0
  122. package/foundation/agent-docs/agent-docs.test.mjs +10 -1
  123. package/foundation/config/project.d.mts +12 -11
  124. package/foundation/config/project.mjs +73 -59
  125. package/foundation/config/project.test.mjs +141 -5
  126. package/foundation/discovery/authoring-self-docs.test.mjs +17 -7
  127. package/foundation/discovery/cli-self-docs.d.mts +40 -34
  128. package/foundation/discovery/cli-self-docs.mjs +91 -115
  129. package/foundation/discovery/cli-self-docs.test.mjs +104 -166
  130. package/foundation/discovery/component-discovery.d.mts +38 -0
  131. package/foundation/discovery/component-discovery.mjs +48 -0
  132. package/foundation/discovery/docs-discovery.d.mts +105 -8
  133. package/foundation/discovery/docs-discovery.mjs +177 -13
  134. package/foundation/discovery/docs-discovery.test.mjs +56 -17
  135. package/foundation/discovery/docs-output-budget.d.mts +2 -2
  136. package/foundation/discovery/docs-output-budget.mjs +1 -1
  137. package/foundation/discovery/docs-section-key.d.mts +9 -2
  138. package/foundation/discovery/docs-section-key.mjs +15 -1
  139. package/foundation/discovery/template-adapter.d.mts +92 -6
  140. package/foundation/discovery/template-adapter.mjs +453 -17
  141. package/foundation/discovery/template-adapter.test.mjs +42 -0
  142. package/foundation/discovery/template-conflict-release.d.mts +13 -0
  143. package/foundation/discovery/template-conflict-release.mjs +40 -0
  144. package/foundation/discovery/template-conflict-release.test.mjs +40 -0
  145. package/foundation/doc-compiler/bundle.mjs +61 -1
  146. package/foundation/doc-compiler/bundle.test.mjs +21 -10
  147. package/foundation/doc-compiler/compile.d.mts +113 -132
  148. package/foundation/doc-compiler/compile.mjs +52 -6
  149. package/foundation/doc-compiler/diagnostics.mjs +28 -0
  150. package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
  151. package/foundation/doc-compiler/inputs.d.mts +2 -2
  152. package/foundation/doc-compiler/inputs.mjs +6 -1
  153. package/foundation/doc-compiler/ir.mjs +7 -0
  154. package/foundation/doc-compiler/lenses.d.mts +3 -2
  155. package/foundation/doc-compiler/lenses.mjs +2 -1
  156. package/foundation/doc-compiler/links.d.mts +135 -0
  157. package/foundation/doc-compiler/links.mjs +253 -0
  158. package/foundation/doc-compiler/links.test.mjs +139 -0
  159. package/foundation/doc-compiler/lower-doc.test.mjs +5 -2
  160. package/foundation/doc-compiler/read.d.mts +3 -2
  161. package/foundation/doc-compiler/read.mjs +6 -1
  162. package/foundation/doc-compiler/tree.d.mts +288 -0
  163. package/foundation/doc-compiler/tree.mjs +876 -0
  164. package/foundation/doc-compiler/tree.test.mjs +598 -0
  165. package/foundation/integrations/autolink.test.mjs +1 -1
  166. package/foundation/integrations/cli-requirement.d.mts +45 -0
  167. package/foundation/integrations/cli-requirement.mjs +154 -0
  168. package/foundation/integrations/cli-requirement.test.mjs +109 -0
  169. package/foundation/integrations/contribution-inventory.d.mts +2 -1
  170. package/foundation/integrations/contribution-inventory.mjs +10 -4
  171. package/foundation/integrations/contribution-inventory.test.mjs +19 -0
  172. package/foundation/integrations/integration-warnings.d.mts +9 -2
  173. package/foundation/integrations/integration-warnings.mjs +51 -26
  174. package/foundation/integrations/integration-warnings.test.mjs +74 -1
  175. package/foundation/integrations/validate-contributions.mjs +25 -27
  176. package/foundation/response/response-types.doc.d.mts +5 -1
  177. package/foundation/response/response-types.doc.mjs +18 -9
  178. package/foundation/xle/expand.mjs +1 -1
  179. package/foundation/xle/xle.test.mjs +13 -0
  180. package/package.json +9 -9
  181. package/assets/docs/cli.doc.mjs +0 -15
@@ -1,17 +1,18 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file The CLI's own docs, read by their `namespace`: every command, API
5
- * function, schema, and enum doc the CLI ships says which `astryx docs` topic
6
- * reads it, and the `cli` topic is built from the ones that name it.
4
+ * @file The CLI's own typed docs, read by their `namespace`: every command,
5
+ * API function, schema, and enum doc the CLI ships names the group that reads
6
+ * it. The docs tree adopts `cli/commands` and `cli/api` (spec:AST-046); the
7
+ * authoring topic reads `authoring` from its own list.
7
8
  *
8
9
  * @input The command, function, schema, and enum docs under
9
10
  * clients/cli/commands, api, authoring, and foundation.
10
- * @output {@link buildCliTopic} for `astryx docs cli`, and
11
+ * @output {@link loadCliSelfDocs} for the docs tree, {@link cliDocSection} for
12
+ * what `astryx docs <route>` prints for one of them, and
11
13
  * {@link auditCliSelfDocs}, which `astryx doctor` runs.
12
- * @position foundation/discovery — the reader for docs whose namespace starts
13
- * with `cli/`. The authoring topic reads the `authoring` namespace from its
14
- * own list (authoring-self-docs.mjs).
14
+ * @position foundation/discovery. The tree (doc-compiler/tree.mjs) gives each
15
+ * doc its route; this module only loads the docs and renders one.
15
16
  */
16
17
 
17
18
  import * as fs from 'node:fs';
@@ -23,7 +24,7 @@ import {
23
24
  DOC_OUTPUT_BUDGET_BYTES,
24
25
  oversizedDocSections,
25
26
  } from './docs-output-budget.mjs';
26
- import {sectionKeyProblems} from './docs-section-key.mjs';
27
+ import {routeSegment} from './docs-section-key.mjs';
27
28
 
28
29
  /** The directories, relative to the CLI root, that hold the CLI's own docs. */
29
30
  export const CLI_SELF_DOC_DIRS = [
@@ -37,23 +38,20 @@ export const CLI_SELF_DOC_DIRS = [
37
38
  const NAMESPACED_KINDS = new Set(['command', 'function', 'schema', 'enum']);
38
39
 
39
40
  /**
40
- * Every namespace a CLI doc may declare, and the topic that reads it. A doc in
41
- * a `cli/` namespace is the section `<key prefix>-<name>` of `astryx docs cli`;
42
- * a doc in `authoring` is a section of `astryx docs authoring`.
43
- * @type {Record<string, {topic: string, keyPrefix?: string}>}
41
+ * Every namespace a CLI doc may declare, and what reads it. The docs tree
42
+ * adopts `cli/commands` (under `cli/commands`) and `cli/api` (under
43
+ * `cli/api/<kind>s`); `astryx docs authoring` reads `authoring` from its list.
44
+ * @type {Record<string, {reader: 'tree' | 'authoring'}>}
44
45
  */
45
46
  export const CLI_DOC_NAMESPACES = {
46
- 'cli/commands': {topic: 'cli', keyPrefix: 'commands'},
47
- 'cli/api': {topic: 'cli', keyPrefix: 'api'},
48
- authoring: {topic: 'authoring'},
47
+ 'cli/commands': {reader: 'tree'},
48
+ 'cli/api': {reader: 'tree'},
49
+ authoring: {reader: 'authoring'},
49
50
  };
50
51
 
51
52
  /** Blocks a doc's notes may carry that a topic section can render. */
52
53
  const TOPIC_BLOCKS = new Set(['prose', 'list', 'code', 'heading', 'table']);
53
54
 
54
- /** Section order within the `cli` topic: commands, then the API by kind. */
55
- const KIND_ORDER = ['command', 'function', 'schema', 'enum'];
56
-
57
55
  /**
58
56
  * Every `*.doc.mjs` under the CLI's doc directories, relative to `root` and
59
57
  * sorted. Fixture, test, and dependency directories are skipped.
@@ -121,29 +119,27 @@ export async function loadCliSelfDocs(
121
119
  }
122
120
 
123
121
  /**
124
- * A name as a section-key segment: lowercase words joined by hyphens.
125
- * `integrationPackCheck` and `integration pack` both read naturally.
126
- * @param {string} name
127
- * @returns {string}
122
+ * What cross-links need: the loaded function docs by name, the command names,
123
+ * and the route the docs tree gave a doc, if it gave one.
124
+ * @typedef {object} CliDocIndex
125
+ * @property {Map<string, any>} functions
126
+ * @property {Set<string>} commands
127
+ * @property {(kind: string, name: string) => string | null} route
128
128
  */
129
- export function keySegment(name) {
130
- return name
131
- .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
132
- .toLowerCase()
133
- .replace(/[^a-z0-9]+/g, '-')
134
- .replace(/^-+|-+$/g, '');
135
- }
136
129
 
137
130
  /**
138
- * The section key a doc is read by in `astryx docs cli`, or null when its
139
- * namespace is not one of the topic's.
140
- * @param {any} doc
141
- * @returns {string | null}
131
+ * @param {any[]} docs every loaded CLI typed doc
132
+ * @param {(kind: string, name: string) => string | null} [route]
133
+ * @returns {CliDocIndex}
142
134
  */
143
- export function cliSectionKey(doc) {
144
- const prefix = CLI_DOC_NAMESPACES[doc?.namespace]?.keyPrefix;
145
- if (prefix == null) return null;
146
- return `${prefix}-${keySegment(String(doc.name))}`;
135
+ export function cliDocIndex(docs, route = () => null) {
136
+ return {
137
+ functions: new Map(
138
+ docs.filter(d => d.type === 'function').map(d => [d.name, d]),
139
+ ),
140
+ commands: new Set(docs.filter(d => d.type === 'command').map(d => d.name)),
141
+ route,
142
+ };
147
143
  }
148
144
 
149
145
  /** @param {unknown} value */
@@ -197,9 +193,9 @@ function noteBlocks(notes) {
197
193
  }
198
194
 
199
195
  /**
200
- * One command doc as a section of `astryx docs cli`.
196
+ * What `astryx docs <route>` prints for one command doc.
201
197
  * @param {any} cmd
202
- * @param {{functions: Map<string, any>, commands: Set<string>}} index
198
+ * @param {CliDocIndex} index
203
199
  */
204
200
  function commandSection(cmd, index) {
205
201
  const fn = cmd.fn == null ? undefined : index.functions.get(cmd.fn);
@@ -255,6 +251,8 @@ function commandSection(cmd, index) {
255
251
  rows: exitCodes.map((/** @type {any} */ e) => [String(e.code), e.when]),
256
252
  });
257
253
  }
254
+ // Links name docs by identity; the route in each command is derived when
255
+ // the doc is read (spec:AST-047 FR9).
258
256
  const subcommands = (cmd.subcommands ?? []).filter(
259
257
  (/** @type {string} */ sub) => index.commands.has(`${cmd.name} ${sub}`),
260
258
  );
@@ -264,28 +262,44 @@ function commandSection(cmd, index) {
264
262
  style: 'unordered',
265
263
  items: subcommands.map(
266
264
  (/** @type {string} */ sub) =>
267
- `\`astryx ${cmd.name} ${sub}\`: \`astryx docs cli commands-${keySegment(`${cmd.name} ${sub}`)}\``,
265
+ `\`astryx ${cmd.name} ${sub}\`: {@link command:${cmd.name} ${sub}}`,
268
266
  ),
269
267
  });
270
268
  }
271
269
  if (fn != null) {
272
270
  content.push({
273
271
  type: 'prose',
274
- text: `It runs \`${fn.name}()\` from \`${fn.importPath}\`. Read it with \`astryx docs cli ${cliSectionKey(fn)}\`.`,
272
+ text: `It runs \`${fn.name}()\` from \`${fn.importPath}\`. Read it with {@link function:${fn.name}}.`,
275
273
  });
276
274
  }
277
275
  content.push(...noteBlocks(cmd.notes));
278
276
  return {
279
- id: cliSectionKey(cmd),
277
+ id: routeSegment(cmd.name),
280
278
  title: cmd.displayName ?? `astryx ${cmd.name}`,
281
279
  content,
282
280
  };
283
281
  }
284
282
 
285
283
  /**
286
- * One API function doc as a section of `astryx docs cli`.
284
+ * The command doc a command line belongs to: its longest leading words that
285
+ * name one (`integration add theme` is the `integration add` command).
286
+ * @param {string} line
287
+ * @param {Set<string>} commands
288
+ * @returns {string | null}
289
+ */
290
+ function commandDocName(line, commands) {
291
+ const words = line.trim().split(/\s+/);
292
+ for (let n = words.length; n > 0; n--) {
293
+ const name = words.slice(0, n).join(' ');
294
+ if (commands.has(name)) return name;
295
+ }
296
+ return null;
297
+ }
298
+
299
+ /**
300
+ * What `astryx docs <route>` prints for one API function doc.
287
301
  * @param {any} fn
288
- * @param {{functions: Map<string, any>, commands: Set<string>}} index
302
+ * @param {CliDocIndex} index
289
303
  */
290
304
  function functionSection(fn, index) {
291
305
  /** @type {any[]} */
@@ -341,26 +355,28 @@ function functionSection(fn, index) {
341
355
  code: example.code,
342
356
  });
343
357
  }
344
- if (fn.command != null && index.commands.has(fn.command)) {
358
+ const commandDoc =
359
+ fn.command == null ? null : commandDocName(fn.command, index.commands);
360
+ if (commandDoc != null) {
345
361
  content.push({
346
362
  type: 'prose',
347
- text: `\`astryx ${fn.command}\` runs it. Read it with \`astryx docs cli commands-${keySegment(fn.command)}\`.`,
363
+ text: `\`astryx ${fn.command}\` runs it. Read it with {@link command:${commandDoc}}.`,
348
364
  });
349
365
  }
350
366
  return {
351
- id: cliSectionKey(fn),
367
+ id: routeSegment(fn.name),
352
368
  title: fn.displayName ?? `${fn.name}()`,
353
369
  content,
354
370
  };
355
371
  }
356
372
 
357
373
  /**
358
- * One enum doc as a section of `astryx docs cli`.
374
+ * What `astryx docs <route>` prints for one enum doc.
359
375
  * @param {any} doc
360
376
  */
361
377
  function enumSection(doc) {
362
378
  return {
363
- id: cliSectionKey(doc),
379
+ id: routeSegment(doc.name),
364
380
  title: doc.displayName ?? doc.name,
365
381
  content: [
366
382
  {type: 'prose', text: doc.description},
@@ -379,79 +395,33 @@ function enumSection(doc) {
379
395
  }
380
396
 
381
397
  /**
382
- * The docs a `cli/` namespace names, in reading order: commands by name (a
383
- * group before its subcommands), then API functions, schemas, and enums.
384
- * @param {any[]} docs
385
- * @returns {any[]}
386
- */
387
- function cliDocsInOrder(docs) {
388
- return docs
389
- .filter(doc => CLI_DOC_NAMESPACES[doc.namespace]?.topic === 'cli')
390
- .sort(
391
- (a, b) =>
392
- KIND_ORDER.indexOf(a.type) - KIND_ORDER.indexOf(b.type) ||
393
- (a.name < b.name ? -1 : a.name > b.name ? 1 : 0),
394
- );
395
- }
396
-
397
- /**
398
- * The `cli` topic: one section per doc whose namespace is `cli/…`.
399
- * @param {any[]} docs every loaded CLI doc; the ones in other namespaces are
400
- * left out
401
- * @returns {import('../../authoring/doctypes/reference/type').ReferenceDoc}
402
- */
403
- export function buildCliReferenceDoc(docs) {
404
- const ordered = cliDocsInOrder(docs);
405
- const index = {
406
- functions: new Map(
407
- ordered.filter(d => d.type === 'function').map(d => [d.name, d]),
408
- ),
409
- commands: new Set(
410
- ordered.filter(d => d.type === 'command').map(d => d.name),
411
- ),
412
- };
413
- return /** @type {any} */ ({
414
- name: 'cli',
415
- title: 'CLI Reference',
416
- category: 'guide',
417
- description:
418
- 'Every command and API function of the CLI, with the JSON output envelope, error codes, and response types, read from the docs the CLI ships.',
419
- sections: ordered.map(doc =>
420
- doc.type === 'command'
421
- ? commandSection(doc, index)
422
- : doc.type === 'function'
423
- ? functionSection(doc, index)
424
- : doc.type === 'enum'
425
- ? enumSection(doc)
426
- : {...selfDocSection(doc), id: cliSectionKey(doc)},
427
- ),
428
- });
429
- }
430
-
431
- /**
432
- * The `cli` topic from every CLI doc that loads. One that fails is left out
433
- * here and reported by {@link auditCliSelfDocs}.
434
- * @returns {Promise<import('../../authoring/doctypes/reference/type').ReferenceDoc>}
398
+ * What `astryx docs <route>` prints for one CLI typed doc: its title and the
399
+ * blocks of its content, with cross-links to the routes the tree gave.
400
+ * @param {any} doc
401
+ * @param {CliDocIndex} index
402
+ * @returns {{id: string, title: string, content: any[]}}
435
403
  */
436
- export async function buildCliTopic() {
437
- const {loaded} = await loadCliSelfDocs();
438
- return buildCliReferenceDoc(loaded.map(entry => entry.doc));
404
+ export function cliDocSection(doc, index) {
405
+ if (doc.type === 'command') return commandSection(doc, index);
406
+ if (doc.type === 'function') return functionSection(doc, index);
407
+ if (doc.type === 'enum') return enumSection(doc);
408
+ return {...selfDocSection(doc), id: routeSegment(doc.name)};
439
409
  }
440
410
 
441
411
  /**
442
- * What stands between a CLI doc and a reader: a missing namespace, one no
443
- * topic reads, one that disagrees with the authoring topic's list, a doc that
444
- * fails to load, and a `cli` section that clashes or is too large.
412
+ * What stands between a CLI doc and a reader: a missing namespace, one nothing
413
+ * reads, one that disagrees with the authoring topic's list, a doc that fails
414
+ * to load, and a tree leaf too large for one read. Whether the tree gives
415
+ * every `cli/...` doc a route is the docs-tree check's job.
445
416
  * @param {{root?: string, sources?: string[], budget?: number, authoringSources?: string[]}} [options]
446
417
  * @returns {Promise<{
447
418
  * docs: number,
448
- * sections: number,
419
+ * tree: number,
449
420
  * authoring: number,
450
421
  * missing: string[],
451
422
  * unknown: {source: string, namespace: string}[],
452
423
  * misfiled: {source: string, message: string}[],
453
424
  * failed: {source: string, error: string}[],
454
- * keyProblems: string[],
455
425
  * oversized: {key: string, title: string, bytes: number}[],
456
426
  * }>}
457
427
  */
@@ -472,6 +442,8 @@ export async function auditCliSelfDocs({
472
442
  const unknown = [];
473
443
  /** @type {{source: string, message: string}[]} */
474
444
  const misfiled = [];
445
+ /** @type {any[]} */
446
+ const treeDocs = [];
475
447
  let authoring = 0;
476
448
  for (const {source, doc} of loaded) {
477
449
  const namespace = doc.namespace;
@@ -484,7 +456,7 @@ export async function auditCliSelfDocs({
484
456
  continue;
485
457
  }
486
458
  const inAuthoring = listed.has(source);
487
- if (namespace === 'authoring') {
459
+ if (CLI_DOC_NAMESPACES[namespace].reader === 'authoring') {
488
460
  if (inAuthoring) authoring++;
489
461
  else {
490
462
  misfiled.push({
@@ -497,18 +469,22 @@ export async function auditCliSelfDocs({
497
469
  source,
498
470
  message: `${source} is read in \`astryx docs authoring\`, but its namespace is "${namespace}"`,
499
471
  });
472
+ } else {
473
+ treeDocs.push(doc);
500
474
  }
501
475
  }
502
- const topic = buildCliReferenceDoc(loaded.map(entry => entry.doc));
476
+ const index = cliDocIndex(loaded.map(entry => entry.doc));
503
477
  return {
504
478
  docs: loaded.length,
505
- sections: topic.sections.length,
479
+ tree: treeDocs.length,
506
480
  authoring,
507
481
  missing,
508
482
  unknown,
509
483
  misfiled,
510
484
  failed,
511
- keyProblems: sectionKeyProblems(topic.sections),
512
- oversized: oversizedDocSections(topic.sections, budget),
485
+ oversized: oversizedDocSections(
486
+ treeDocs.map(doc => cliDocSection(doc, index)),
487
+ budget,
488
+ ),
513
489
  };
514
490
  }