@astryxdesign/cli 0.6.5-canary.67efe5b → 0.6.5-canary.69aa1cb

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.
@@ -10,10 +10,6 @@
10
10
  * @param {boolean} [options.dense]
11
11
  * @param {boolean} [options.index] return the topic's section index instead of
12
12
  * the whole doc
13
- * @param {number | 'all'} [options.depth] how many levels below a docs-tree
14
- * namespace to read; a doc with nothing below it reads the same at any depth
15
- * @param {'brief' | 'compact' | 'full'} [options.detail] how much of each doc
16
- * below the named one a depth read returns (brief by default)
17
13
  * @param {string} [options.cwd]
18
14
  * @returns {Promise<
19
15
  * import('./docs.type.mjs').DocsListResponse |
@@ -28,8 +24,6 @@ export function docs(topic?: string, section?: string, options?: {
28
24
  zh?: boolean | undefined;
29
25
  dense?: boolean | undefined;
30
26
  index?: boolean | undefined;
31
- depth?: number | "all" | undefined;
32
- detail?: "compact" | "full" | "brief" | undefined;
33
27
  cwd?: string | undefined;
34
28
  }): Promise<import("./docs.type.mjs").DocsListResponse | import("./docs.type.mjs").DocsIndexResponse | import("./docs.type.mjs").DocsDetailResponse | import("./docs.type.mjs").DocsDetailSectionResponse | import("./docs.type.mjs").DocsNodeResponse>;
35
29
  import { list } from './list/list.mjs';
@@ -25,8 +25,7 @@ export const doc = {
25
25
  'ones the project\'s configured integrations contribute, including any ' +
26
26
  'topic an integration replaces or extends, so it depends on the cwd. ' +
27
27
  'A route opens a node of the docs tree instead: a namespace such as ' +
28
- '`cli/api` returns its children one level down (`depth` reads as many ' +
29
- 'levels as asked, and `detail` how much of each doc below), a typed doc such as ' +
28
+ "`cli/api` returns its children one level down, a typed doc such as " +
30
29
  "`cli/api/functions/search` returns its content, and a guide the tree " +
31
30
  'places (`cli/integrations/quick-start`) reads like any topic. ' +
32
31
  'Every read but the list carries `links`, the commands that move from it: ' +
@@ -83,18 +82,6 @@ export const doc = {
83
82
  description:
84
83
  "Return the topic's section index (each section's key, title, and summary), even for a topic with one section.",
85
84
  },
86
- {
87
- name: 'options.depth',
88
- type: "number | 'all'",
89
- description:
90
- "How many levels below a docs-tree namespace to read: 0 for the namespace alone, 1 for its children (the default), 'all' for every level. Where a read stops, a child with docs below it carries childCount. A doc with nothing below it reads the same at any depth.",
91
- },
92
- {
93
- name: 'options.detail',
94
- type: "'brief' | 'compact' | 'full'",
95
- description:
96
- "How much of each doc below the named one a depth read returns: brief (the default) is its identity; compact and full add its text (a guide's sections, a namespace's or typed doc's content). Given alone, it reads one level down.",
97
- },
98
85
  {
99
86
  name: 'options.cwd',
100
87
  type: 'string',
@@ -126,18 +113,10 @@ export const doc = {
126
113
  {
127
114
  type: 'docs.node',
128
115
  description:
129
- "A namespace or typed doc in the docs tree, read by its route: {id, route, kind, package, title, summary, breadcrumb, slots, content}. A namespace lists each slot's children one level down, or as deep as depth asks, each child carrying its own slots, childCount where the read stops, and its text at compact or full detail; a typed doc carries its content.",
116
+ "A namespace or typed doc in the docs tree, read by its route: {id, route, kind, package, title, summary, breadcrumb, slots, content}. A namespace lists each slot's children one level down; a typed doc carries its content.",
130
117
  },
131
118
  ],
132
119
  throws: [
133
- {
134
- code: 'ERR_INVALID_ARGUMENT',
135
- when: "depth is not a whole number of levels or 'all'",
136
- },
137
- {
138
- code: 'ERR_INVALID_DETAIL',
139
- when: 'detail is not brief, compact, or full',
140
- },
141
120
  {
142
121
  code: 'ERR_UNKNOWN_TOPIC',
143
122
  when: 'the topic is not a string, or matches no topic and no docs-tree route',
@@ -155,14 +134,6 @@ export const doc = {
155
134
  code: "await docs('principles', undefined, {index: true});",
156
135
  },
157
136
  {label: 'A docs-tree namespace', code: "await docs('cli/api');"},
158
- {
159
- label: 'Every doc below a namespace, one entry each',
160
- code: "await docs('cli', undefined, {depth: 'all'});",
161
- },
162
- {
163
- label: 'A namespace and everything below it, in full',
164
- code: "await docs('cli/integrations', undefined, {depth: 'all', detail: 'full'});",
165
- },
166
137
  {label: 'One API function', code: "await docs('cli/api/functions/search');"},
167
138
  {
168
139
  label: 'A whole guide from the docs tree',
package/api/docs/docs.mjs CHANGED
@@ -11,7 +11,6 @@
11
11
  * docs(topic, undefined, {index: true}) -> index -> docs.index
12
12
  * docs(topic, section) -> section -> docs.detail.section
13
13
  * docs(route) -> node -> docs.node
14
- * docs(route, undefined, {depth: 2}) -> node -> docs.node, two levels
15
14
  *
16
15
  * A topic read returns the whole doc, as it always has; `index` returns its
17
16
  * sections, so a reader can open one by its key (spec:AST-047). The CLI's text
@@ -34,43 +33,6 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
34
33
 
35
34
  export {list, index, detail, sectionLeaf as section, nodeLeaf as node};
36
35
 
37
- const DETAILS = ['brief', 'compact', 'full'];
38
-
39
- /**
40
- * How far a docs-tree read goes, from the options: `depth` levels below the
41
- * node, or every level for `'all'`, and `detail` for each doc below it (brief
42
- * by default). `detail` alone reads one level down. Neither: the plain read.
43
- * @param {import('./docs.type.mjs').DocsOptions} options
44
- * @returns {import('./node/node.mjs').DepthRead | undefined}
45
- */
46
- function depthRead(options) {
47
- const {depth, detail} = options;
48
- if (detail != null && !DETAILS.includes(detail)) {
49
- throw new AstryxError(
50
- `detail is brief, compact, or full, not ${JSON.stringify(detail)}.`,
51
- undefined,
52
- ERROR_CODES.ERR_INVALID_DETAIL,
53
- );
54
- }
55
- if (
56
- depth != null &&
57
- depth !== 'all' &&
58
- !(Number.isInteger(depth) && /** @type {number} */ (depth) >= 0)
59
- ) {
60
- throw new AstryxError(
61
- `depth is a number of levels (0, 1, 2, ...) or "all", not ${JSON.stringify(depth)}.`,
62
- undefined,
63
- ERROR_CODES.ERR_INVALID_ARGUMENT,
64
- );
65
- }
66
- if (depth == null && detail == null) return undefined;
67
- return {
68
- depth: depth === 'all' ? Infinity : (depth ?? 1),
69
- detail: /** @type {'brief' | 'compact' | 'full'} */ (detail ?? 'brief'),
70
- lang: options.lang || (options.dense ? 'dense' : options.zh ? 'zh' : null),
71
- };
72
- }
73
-
74
36
  /**
75
37
  * @param {string} [topic]
76
38
  * @param {string} [section]
@@ -80,10 +42,6 @@ function depthRead(options) {
80
42
  * @param {boolean} [options.dense]
81
43
  * @param {boolean} [options.index] return the topic's section index instead of
82
44
  * the whole doc
83
- * @param {number | 'all'} [options.depth] how many levels below a docs-tree
84
- * namespace to read; a doc with nothing below it reads the same at any depth
85
- * @param {'brief' | 'compact' | 'full'} [options.detail] how much of each doc
86
- * below the named one a depth read returns (brief by default)
87
45
  * @param {string} [options.cwd]
88
46
  * @returns {Promise<
89
47
  * import('./docs.type.mjs').DocsListResponse |
@@ -94,7 +52,6 @@ function depthRead(options) {
94
52
  * >}
95
53
  */
96
54
  export async function docs(topic, section, options = {}) {
97
- const read = depthRead(options);
98
55
  if (!topic) return list(options);
99
56
  const found = await resolveDocsArgument(topic, options);
100
57
  if (found.kind === 'node') {
@@ -120,7 +77,7 @@ export async function docs(topic, section, options = {}) {
120
77
  }
121
78
  return {
122
79
  type: 'docs.node',
123
- data: await nodeView(found.catalog, found.tree, found.node, read),
80
+ data: await nodeView(found.catalog, found.tree, found.node),
124
81
  };
125
82
  }
126
83
  if (section) return sectionLeaf(topic, section, options);
@@ -205,14 +205,9 @@ export type DocsNode = {
205
205
  breadcrumb: DocsNodeLink[];
206
206
  /**
207
207
  * a namespace's slots that hold children, in
208
- * order; empty for a typed doc, and for a depth read of 0
208
+ * order; empty for a typed doc
209
209
  */
210
210
  slots: DocsNodeSlot[];
211
- /**
212
- * with a depth read of 0, how many docs sit
213
- * right below the namespace
214
- */
215
- childCount?: number | undefined;
216
211
  /**
217
212
  * a typed doc's content; empty for a namespace
218
213
  */
@@ -251,26 +246,6 @@ export type DocsNodeChild = {
251
246
  kind: string;
252
247
  title: string;
253
248
  summary: string;
254
- /**
255
- * with a depth read, its own slots, while
256
- * the read goes deeper
257
- */
258
- slots?: DocsNodeSlot[] | undefined;
259
- /**
260
- * with a depth read, how many docs sit right
261
- * below it where the read stops
262
- */
263
- childCount?: number | undefined;
264
- /**
265
- * with a depth read at compact or full detail: a namespace's intro or a typed
266
- * doc's content
267
- */
268
- content?: import("@astryxdesign/cli/authoring").ReferenceContentBlock[] | undefined;
269
- /**
270
- * with a depth read at compact or full
271
- * detail: a guide's sections
272
- */
273
- sections?: DocsReadSection[] | undefined;
274
249
  };
275
250
  /**
276
251
  * Options for `docs()`.
@@ -284,18 +259,6 @@ export type DocsOptions = {
284
259
  * whole doc
285
260
  */
286
261
  index?: boolean | undefined;
287
- /**
288
- * how many levels below a docs-tree
289
- * namespace to read: 0 for the namespace alone, 1 for its children (the
290
- * default), 'all' for every level
291
- */
292
- depth?: number | "all" | undefined;
293
- /**
294
- * how much of each doc below
295
- * the named one a depth read returns: brief (the default) is its identity,
296
- * compact and full add its text
297
- */
298
- detail?: "compact" | "full" | "brief" | undefined;
299
262
  /**
300
263
  * project directory whose configured integrations
301
264
  * contribute topics; defaults to process.cwd()
@@ -153,9 +153,7 @@
153
153
  * @property {string} summary
154
154
  * @property {DocsNodeLink[]} breadcrumb the namespaces above it, top first
155
155
  * @property {DocsNodeSlot[]} slots a namespace's slots that hold children, in
156
- * order; empty for a typed doc, and for a depth read of 0
157
- * @property {number} [childCount] with a depth read of 0, how many docs sit
158
- * right below the namespace
156
+ * order; empty for a typed doc
159
157
  * @property {import('@astryxdesign/cli/authoring').ReferenceContentBlock[]} content
160
158
  * a typed doc's content; empty for a namespace
161
159
  * @property {DocsLinks} links the moves from the node: up to its parent (the
@@ -183,15 +181,6 @@
183
181
  * @property {string} kind
184
182
  * @property {string} title
185
183
  * @property {string} summary
186
- * @property {DocsNodeSlot[]} [slots] with a depth read, its own slots, while
187
- * the read goes deeper
188
- * @property {number} [childCount] with a depth read, how many docs sit right
189
- * below it where the read stops
190
- * @property {import('@astryxdesign/cli/authoring').ReferenceContentBlock[]} [content]
191
- * with a depth read at compact or full detail: a namespace's intro or a typed
192
- * doc's content
193
- * @property {DocsReadSection[]} [sections] with a depth read at compact or full
194
- * detail: a guide's sections
195
184
  */
196
185
 
197
186
  /**
@@ -202,12 +191,6 @@
202
191
  * @property {boolean} [dense]
203
192
  * @property {boolean} [index] return a topic's section index instead of its
204
193
  * whole doc
205
- * @property {number | 'all'} [depth] how many levels below a docs-tree
206
- * namespace to read: 0 for the namespace alone, 1 for its children (the
207
- * default), 'all' for every level
208
- * @property {'brief' | 'compact' | 'full'} [detail] how much of each doc below
209
- * the named one a depth read returns: brief (the default) is its identity,
210
- * compact and full add its text
211
194
  * @property {string} [cwd] project directory whose configured integrations
212
195
  * contribute topics; defaults to process.cwd()
213
196
  */
@@ -4,28 +4,15 @@
4
4
  /**
5
5
  * @typedef {import('../../../foundation/doc-compiler/tree.mjs').DocsTree} DocsTree
6
6
  * @typedef {import('../../../foundation/doc-compiler/tree.mjs').TreeNode} TreeNode
7
- * @typedef {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} DocsCatalog
8
7
  */
9
8
  /**
10
- * How far a read goes below the node it names, and how much of each doc below
11
- * it shows: `depth` levels (Infinity for every level), and `detail` brief (its
12
- * identity), or compact or full (with its text: a namespace's intro, a guide's
13
- * sections, a typed doc's content). `lang` selects the guides' language.
14
- * @typedef {object} DepthRead
15
- * @property {number} depth
16
- * @property {'brief' | 'compact' | 'full'} detail
17
- * @property {string | null} lang
18
- */
19
- /**
20
- * The docs.node view of one tree node. Without a depth read, a namespace lists
21
- * its children one level down.
22
- * @param {DocsCatalog} catalog
9
+ * The docs.node view of one tree node.
10
+ * @param {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} catalog
23
11
  * @param {DocsTree} tree
24
12
  * @param {TreeNode} node
25
- * @param {DepthRead} [read] how far down to go, and how much of each doc below
26
13
  * @returns {Promise<import('../docs.type.mjs').DocsNode>}
27
14
  */
28
- export function nodeView(catalog: DocsCatalog, tree: DocsTree, node: TreeNode, read?: DepthRead): Promise<import("../docs.type.mjs").DocsNode>;
15
+ export function nodeView(catalog: import("../../../foundation/discovery/docs-discovery.mjs").DocsCatalog, tree: DocsTree, node: TreeNode): Promise<import("../docs.type.mjs").DocsNode>;
29
16
  /**
30
17
  * The typed edges a doc declares (spec:AST-047 FR5), resolved to routes: a
31
18
  * function doc's `command` and `related`, and a command doc's `fn` and
@@ -54,15 +41,3 @@ export function node(route: string, options?: {
54
41
  }): Promise<import("../docs.type.mjs").DocsNodeResponse>;
55
42
  export type DocsTree = import("../../../foundation/doc-compiler/tree.mjs").DocsTree;
56
43
  export type TreeNode = import("../../../foundation/doc-compiler/tree.mjs").TreeNode;
57
- export type DocsCatalog = import("../../../foundation/discovery/docs-discovery.mjs").DocsCatalog;
58
- /**
59
- * How far a read goes below the node it names, and how much of each doc below
60
- * it shows: `depth` levels (Infinity for every level), and `detail` brief (its
61
- * identity), or compact or full (with its text: a namespace's intro, a guide's
62
- * sections, a typed doc's content). `lang` selects the guides' language.
63
- */
64
- export type DepthRead = {
65
- depth: number;
66
- detail: "brief" | "compact" | "full";
67
- lang: string | null;
68
- };
@@ -7,18 +7,14 @@
7
7
  * typed doc such as `cli/api/functions/search`, plus {cwd}.
8
8
  * @output { type: 'docs.node', data: DocsNode } — the node's identity, title
9
9
  * and summary, the namespaces above it, and either its slots with their
10
- * children (a namespace) or its content (a typed doc). By default a
11
- * namespace lists its children one level down; a depth read goes as far
12
- * down as asked, with each doc below as its identity (brief) or with its
13
- * text (compact, full). Matches `astryx --json docs <route> [--depth <n>]`.
10
+ * children (a namespace) or its content (a typed doc). A namespace never
11
+ * lists its grandchildren, so a reader goes down one level at a time.
12
+ * Matches `astryx --json docs <route>`.
14
13
  * @position Leaf under api/docs, beside the topic leaves. A guide the tree
15
14
  * places is a topic: the detail leaf reads it by its route.
16
15
  */
17
16
 
18
- import {detailView} from '../../../foundation/doc-compiler/lenses.mjs';
19
17
  import {
20
- compileTopic,
21
- guideEntry,
22
18
  nodeContent,
23
19
  placeLinks,
24
20
  resolveDocsArgument,
@@ -28,34 +24,18 @@ import {
28
24
  /**
29
25
  * @typedef {import('../../../foundation/doc-compiler/tree.mjs').DocsTree} DocsTree
30
26
  * @typedef {import('../../../foundation/doc-compiler/tree.mjs').TreeNode} TreeNode
31
- * @typedef {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} DocsCatalog
32
27
  */
33
28
 
34
29
  /**
35
- * How far a read goes below the node it names, and how much of each doc below
36
- * it shows: `depth` levels (Infinity for every level), and `detail` brief (its
37
- * identity), or compact or full (with its text: a namespace's intro, a guide's
38
- * sections, a typed doc's content). `lang` selects the guides' language.
39
- * @typedef {object} DepthRead
40
- * @property {number} depth
41
- * @property {'brief' | 'compact' | 'full'} detail
42
- * @property {string | null} lang
43
- */
44
-
45
- /**
46
- * The docs.node view of one tree node. Without a depth read, a namespace lists
47
- * its children one level down.
48
- * @param {DocsCatalog} catalog
30
+ * The docs.node view of one tree node.
31
+ * @param {import('../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} catalog
49
32
  * @param {DocsTree} tree
50
33
  * @param {TreeNode} node
51
- * @param {DepthRead} [read] how far down to go, and how much of each doc below
52
34
  * @returns {Promise<import('../docs.type.mjs').DocsNode>}
53
35
  */
54
- export async function nodeView(catalog, tree, node, read) {
36
+ export async function nodeView(catalog, tree, node) {
55
37
  const {content} = await nodeContent(catalog, tree, node);
56
- const slots = node.slots.filter(slot => slot.children.length > 0);
57
- /** @type {import('../docs.type.mjs').DocsNode} */
58
- const view = {
38
+ return {
59
39
  id: node.id,
60
40
  route: node.route,
61
41
  kind: node.kind,
@@ -65,128 +45,25 @@ export async function nodeView(catalog, tree, node, read) {
65
45
  breadcrumb: tree
66
46
  .ancestors(node)
67
47
  .map(ancestor => ({route: ancestor.route, title: ancestor.title})),
68
- slots: !read
69
- ? slots.map(slot => ({
70
- name: slot.name,
71
- title: slot.title,
72
- children: slot.children.map(route =>
73
- childIdentity(/** @type {TreeNode} */ (tree.get(route))),
74
- ),
75
- }))
76
- : read.depth >= 1
77
- ? await slotsBelow(catalog, tree, slots, 1, read)
78
- : [],
48
+ slots: node.slots
49
+ .filter(slot => slot.children.length > 0)
50
+ .map(slot => ({
51
+ name: slot.name,
52
+ title: slot.title,
53
+ children: slot.children.map(route => {
54
+ const child = /** @type {TreeNode} */ (tree.get(route));
55
+ return {
56
+ route: child.route,
57
+ name: child.route.slice(child.route.lastIndexOf('/') + 1),
58
+ kind: child.kind,
59
+ title: child.title,
60
+ summary: child.summary,
61
+ };
62
+ }),
63
+ })),
79
64
  content,
80
65
  links: nodeLinks(tree, node),
81
66
  };
82
- if (read && read.depth < 1 && slots.length > 0) {
83
- view.childCount = countChildren(slots);
84
- }
85
- return view;
86
- }
87
-
88
- /**
89
- * The fields every child carries: what it is, and the route that opens it.
90
- * @param {TreeNode} child
91
- * @returns {import('../docs.type.mjs').DocsNodeChild}
92
- */
93
- function childIdentity(child) {
94
- return {
95
- route: child.route,
96
- name: child.route.slice(child.route.lastIndexOf('/') + 1),
97
- kind: child.kind,
98
- title: child.title,
99
- summary: child.summary,
100
- };
101
- }
102
-
103
- /**
104
- * @param {TreeNode['slots']} slots
105
- * @returns {number}
106
- */
107
- function countChildren(slots) {
108
- return slots.reduce((count, slot) => count + slot.children.length, 0);
109
- }
110
-
111
- /**
112
- * Slots read `level` levels below the named node: each child at the read's
113
- * detail, and its own slots while the read goes deeper.
114
- * @param {DocsCatalog} catalog
115
- * @param {DocsTree} tree
116
- * @param {TreeNode['slots']} slots
117
- * @param {number} level
118
- * @param {DepthRead} read
119
- * @returns {Promise<import('../docs.type.mjs').DocsNodeSlot[]>}
120
- */
121
- async function slotsBelow(catalog, tree, slots, level, read) {
122
- return Promise.all(
123
- slots.map(async slot => ({
124
- name: slot.name,
125
- title: slot.title,
126
- children: await Promise.all(
127
- slot.children.map(route =>
128
- childBelow(
129
- catalog,
130
- tree,
131
- /** @type {TreeNode} */ (tree.get(route)),
132
- level,
133
- read,
134
- ),
135
- ),
136
- ),
137
- })),
138
- );
139
- }
140
-
141
- /**
142
- * One child of a depth read. Where the read stops, a child with docs below it
143
- * says how many, so a reader knows to go deeper.
144
- * @param {DocsCatalog} catalog
145
- * @param {DocsTree} tree
146
- * @param {TreeNode} child
147
- * @param {number} level
148
- * @param {DepthRead} read
149
- * @returns {Promise<import('../docs.type.mjs').DocsNodeChild>}
150
- */
151
- async function childBelow(catalog, tree, child, level, read) {
152
- const view = childIdentity(child);
153
- if (read.detail !== 'brief') {
154
- Object.assign(view, await childText(catalog, tree, child, read.lang));
155
- }
156
- const slots = child.slots.filter(slot => slot.children.length > 0);
157
- if (slots.length > 0) {
158
- if (level < read.depth) {
159
- view.slots = await slotsBelow(catalog, tree, slots, level + 1, read);
160
- } else {
161
- view.childCount = countChildren(slots);
162
- }
163
- }
164
- return view;
165
- }
166
-
167
- /**
168
- * A child's text: a guide's compiled sections, or the content of a namespace
169
- * or typed doc.
170
- * @param {DocsCatalog} catalog
171
- * @param {DocsTree} tree
172
- * @param {TreeNode} child
173
- * @param {string | null} lang
174
- * @returns {Promise<{content?: any[], sections?: any[]}>}
175
- */
176
- async function childText(catalog, tree, child, lang) {
177
- if (child.kind === 'generic') {
178
- const entry = child.ref?.topicFile
179
- ? guideEntry(child)
180
- : child.ref?.flatTopic
181
- ? catalog.resolve(child.ref.flatTopic)
182
- : null;
183
- if (!entry) return {};
184
- return {
185
- sections: detailView(await compileTopic(catalog, entry, lang)).sections,
186
- };
187
- }
188
- const {content} = await nodeContent(catalog, tree, child);
189
- return {content};
190
67
  }
191
68
 
192
69
  /**
@@ -13,7 +13,7 @@
13
13
  export function list({ cwd, category, detail, zh, lang, }?: {
14
14
  cwd?: string | undefined;
15
15
  category?: string | undefined;
16
- detail?: "compact" | "full" | "brief" | "names" | undefined;
16
+ detail?: "compact" | "full" | "names" | "brief" | undefined;
17
17
  zh?: boolean | undefined;
18
18
  lang?: string | null | undefined;
19
19
  }): Promise<import("../hook.type.mjs").HookListResponse>;
@@ -22,9 +22,7 @@ export const doc = {
22
22
  'does, and `--index` its section index. A route ' +
23
23
  'opens a node of the docs tree: `cli` lists its guides and reference, ' +
24
24
  '`cli/api/functions` lists every API function, and `cli/api/functions/search` prints ' +
25
- 'one. `--depth` reads as far down the tree as you ask, from the doc alone (0) to ' +
26
- 'everything below it (all), and with it `--detail` sets how much of each doc below ' +
27
- 'shows: one line (brief, the default), its sections (compact), or all of it (full).',
25
+ 'one.',
28
26
  fn: 'docs',
29
27
  args: [
30
28
  {name: 'topic', param: 'topic', required: false},
@@ -41,12 +39,6 @@ export const doc = {
41
39
  description:
42
40
  'Print the whole topic instead of its sections (text; `--json` returns the whole topic unless --index). Cannot be set with --index',
43
41
  },
44
- {
45
- flag: '--depth <levels>',
46
- param: 'options.depth',
47
- description:
48
- 'How many levels of the docs tree to read below a namespace: 0 for the namespace alone, 1 for its children (what a read without --depth shows), all for everything below it. With it, --detail sets how much of each doc below shows: brief (one line each, the default), compact (with its sections), or full',
49
- },
50
42
  ],
51
43
  examples: [
52
44
  {label: 'List topics', cli: 'astryx docs'},
@@ -54,11 +46,6 @@ export const doc = {
54
46
  {label: 'A whole topic as JSON', cli: 'astryx docs spacing --json'},
55
47
  {label: 'One section', cli: 'astryx docs theme quick-start'},
56
48
  {label: 'The CLI docs tree', cli: 'astryx docs cli'},
57
- {label: 'Every CLI doc, one line each', cli: 'astryx docs cli --depth all'},
58
- {
59
- label: 'The integration guides as one read',
60
- cli: 'astryx docs cli/integrations --depth all --detail full',
61
- },
62
49
  {label: 'One API function', cli: 'astryx docs cli/api/functions/search'},
63
50
  {label: 'A whole guide', cli: 'astryx docs cli/integrations/quick-start --full'},
64
51
  ],
@@ -66,7 +53,7 @@ export const doc = {
66
53
  {code: 0, when: 'success'},
67
54
  {
68
55
  code: 1,
69
- when: 'unknown topic or route, a section that matches no section or more than one, or a --depth that is not a number of levels or all',
56
+ when: 'unknown topic or route, or a section that matches no section or more than one',
70
57
  },
71
58
  ],
72
59
  related: ['search', 'component', 'hook', 'template'],
@@ -4,10 +4,9 @@
4
4
  * @file docs command — Print Astryx reference docs
5
5
  *
6
6
  * In text, every read is one level: a topic lists its sections, so a reader can
7
- * open one section by its key, and `--full` prints the whole topic. `--depth`
8
- * reads a docs-tree namespace as many levels down as asked, each doc below it
9
- * at --detail (brief by default: one line each). `--json` keeps the docs()
10
- * contract: a topic returns its whole doc, and `--index` its sections.
7
+ * open one section by its key, and `--full` prints the whole topic. `--json`
8
+ * keeps the docs() contract: a topic returns its whole doc, and `--index` its
9
+ * sections.
11
10
  * Supports --detail (full|compact|brief) and --lang (en|zh|dense). A code
12
11
  * block's label prints above its fence, and table cells escape their pipes.
13
12
  *
@@ -19,7 +18,6 @@
19
18
  * astryx docs <topic> --full Print the whole topic
20
19
  * astryx docs <route> Open a node of the docs tree, such as
21
20
  * cli, cli/api, or cli/api/functions/search
22
- * astryx docs <route> --depth <n|all> Read that many levels below it
23
21
  */
24
22
 
25
23
  import {
@@ -183,202 +181,6 @@ function formatReferenceFull(docs, detail) {
183
181
  return `${header}\n\n${sections.join(sep)}`;
184
182
  }
185
183
 
186
- /**
187
- * @param {string} title
188
- * @param {number} level
189
- * @returns {string}
190
- */
191
- function treeHeading(title, level) {
192
- return `${'#'.repeat(Math.max(1, Math.min(6, level)))} ${title}`;
193
- }
194
-
195
- /**
196
- * A doc's blocks at one depth: its headings move down with it.
197
- * @param {import('@astryxdesign/cli/authoring').ReferenceContentBlock[]} blocks
198
- * @param {'full' | 'compact' | 'brief'} detail
199
- * @param {number} headingOffset
200
- * @returns {string[]}
201
- */
202
- function formatTreeBlocks(blocks, detail, headingOffset) {
203
- /** @type {string[]} */
204
- const formatted = [];
205
- for (const block of blocks) {
206
- const value =
207
- block.type === 'heading'
208
- ? treeHeading(block.text, (block.level || 3) + headingOffset)
209
- : formatBlock(block, detail);
210
- if (value) formatted.push(value);
211
- }
212
- return formatted;
213
- }
214
-
215
- /**
216
- * @param {import('../../../api/docs/docs.type.mjs').DocsReadSection} docSection
217
- * @param {'full' | 'compact' | 'brief'} detail
218
- * @param {number} headingLevel
219
- * @returns {string}
220
- */
221
- function formatTreeSection(docSection, detail, headingLevel) {
222
- const heading = treeHeading(docSection.title, headingLevel);
223
- const blocks = formatTreeBlocks(docSection.content, detail, headingLevel - 2);
224
- return blocks.length > 0 ? `${heading}\n\n${blocks.join('\n\n')}` : heading;
225
- }
226
-
227
- /**
228
- * Where a route sits below the namespace a read names.
229
- * @param {string} route
230
- * @param {string} root
231
- * @returns {string}
232
- */
233
- function belowRoot(route, root) {
234
- return route.startsWith(`${root}/`) ? route.slice(root.length + 1) : route;
235
- }
236
-
237
- /**
238
- * @param {number} count
239
- * @returns {string}
240
- */
241
- function docsBelow(count) {
242
- return `${count} ${count === 1 ? 'doc' : 'docs'} below`;
243
- }
244
-
245
- /**
246
- * Every child of a depth read, one row each in reading order, named by where
247
- * it sits below the read's namespace.
248
- * @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild[]} children
249
- * @param {string} root
250
- * @returns {{name: string, summary: string}[]}
251
- */
252
- function treeRows(children, root) {
253
- return children.flatMap(child => [
254
- {
255
- name: belowRoot(child.route, root),
256
- summary: child.childCount
257
- ? `${childRow(child).summary} (${docsBelow(child.childCount)})`
258
- : childRow(child).summary,
259
- },
260
- ...(child.slots ?? []).flatMap(slot => treeRows(slot.children, root)),
261
- ]);
262
- }
263
-
264
- /**
265
- * One child of a depth read with its text, under a heading for its level, and
266
- * its own children below it.
267
- * @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild} child
268
- * @param {'full' | 'compact'} detail
269
- * @param {number} level
270
- * @param {string} root
271
- * @param {string} run
272
- * @returns {string}
273
- */
274
- function formatTreeChild(child, detail, level, root, run) {
275
- const parts = [
276
- `${treeHeading(child.title, level)} (${belowRoot(child.route, root)})`,
277
- ];
278
- if (
279
- child.summary &&
280
- (child.kind === 'namespace' || child.kind === 'generic')
281
- ) {
282
- parts.push(child.summary);
283
- }
284
- const content = formatTreeBlocks(child.content ?? [], detail, level - 2);
285
- if (content.length > 0) parts.push(content.join('\n\n'));
286
- parts.push(
287
- ...(child.sections ?? []).map(docSection =>
288
- formatTreeSection(docSection, detail, level + 1),
289
- ),
290
- );
291
- if (child.childCount) {
292
- parts.push(
293
- `${docsBelow(child.childCount)}: ${run} docs ${child.route} --depth 1`,
294
- );
295
- }
296
- for (const slot of child.slots ?? []) {
297
- parts.push(
298
- ...slot.children.map(each =>
299
- formatTreeChild(each, detail, level + 1, root, run),
300
- ),
301
- );
302
- }
303
- return parts.join('\n\n');
304
- }
305
-
306
- /**
307
- * A depth read of a namespace: its intro, then each slot's docs as deep as
308
- * asked, one line each (brief) or with their text (compact, full). A typed doc
309
- * has nothing below it, so it reads as it always does.
310
- * @param {import('../../../api/docs/docs.type.mjs').DocsNode} node
311
- * @param {'full' | 'compact' | 'brief'} detail how the named node reads
312
- * @param {'full' | 'compact' | 'brief'} childDetail how each doc below reads
313
- * @param {string} run
314
- */
315
- function emitTree(node, detail, childDetail, run) {
316
- if (node.kind !== 'namespace') {
317
- emitNode(node, detail, run);
318
- return;
319
- }
320
- /**
321
- * @param {import('../../../api/docs/docs.type.mjs').DocsNodeChild[]} children
322
- * @returns {string[]}
323
- */
324
- const routes = children =>
325
- children.flatMap(child => [
326
- child.route,
327
- ...(child.slots ?? []).flatMap(slot => routes(slot.children)),
328
- ]);
329
- const allBelow = node.slots
330
- .flatMap(slot => routes(slot.children))
331
- .every(route => route.startsWith(`${node.route}/`));
332
- const root = allBelow ? node.route : '';
333
- emit(
334
- section(node.title, wrapText(node.summary)),
335
- ...(node.content?.length
336
- ? [
337
- text(
338
- node.content
339
- .map(b => formatBlock(b, detail))
340
- .filter(Boolean)
341
- .join('\n\n'),
342
- ),
343
- ]
344
- : []),
345
- ...(node.childCount
346
- ? [
347
- text(
348
- `${docsBelow(node.childCount)}. Read them: ${run} docs ${node.route} --depth 1`,
349
- ),
350
- ]
351
- : []),
352
- ...node.slots.flatMap(slot => [
353
- ...(node.slots.length === 1 && slot.title === node.title
354
- ? []
355
- : [section(slot.title)]),
356
- childDetail === 'brief'
357
- ? records(treeRows(slot.children, root), {
358
- fields: ['name', 'summary'],
359
- layout: 'inline',
360
- })
361
- : code(
362
- slot.children
363
- .map(child => formatTreeChild(child, childDetail, 2, root, run))
364
- .join('\n\n'),
365
- ),
366
- ]),
367
- text(
368
- [
369
- ...(node.slots.length > 0
370
- ? [
371
- allBelow
372
- ? `Open one: ${run} docs ${node.route}/<name>`
373
- : `Open one: ${run} docs <name>`,
374
- ]
375
- : []),
376
- ...linkLines(node.links),
377
- ].join('\n'),
378
- ),
379
- );
380
- }
381
-
382
184
  /**
383
185
  * The moves a read offers (spec:AST-047), one runnable command per line: up to
384
186
  * the level it sits in, the item before and after it, and the docs it names.
@@ -529,7 +331,7 @@ export function registerDocs(program) {
529
331
  action: async (
530
332
  /** @type {string | undefined} */ topic,
531
333
  /** @type {string | undefined} */ sectionName,
532
- /** @type {{index?: boolean, full?: boolean, depth?: string}} */ options = {},
334
+ /** @type {{index?: boolean, full?: boolean}} */ options = {},
533
335
  ) => {
534
336
  const run = getCliInvocation();
535
337
  const lang = program.opts().lang || null;
@@ -544,22 +346,6 @@ export function registerDocs(program) {
544
346
  {code: ERROR_CODES.ERR_INVALID_ARGUMENT},
545
347
  );
546
348
  }
547
- /** @type {number | 'all' | undefined} */
548
- let depth;
549
- if (options.depth != null) {
550
- if (options.depth === 'all') depth = 'all';
551
- else if (/^\d+$/.test(options.depth)) depth = Number(options.depth);
552
- else {
553
- return cliError(
554
- `--depth takes a number of levels (0, 1, 2, ...) or all, not "${options.depth}".`,
555
- {code: ERROR_CODES.ERR_INVALID_ARGUMENT},
556
- );
557
- }
558
- }
559
- // With --depth, --detail is how much of each doc below shows; left at
560
- // its default, each is one line.
561
- const childDetail =
562
- program.getOptionValueSource('detail') === 'default' ? 'brief' : detail;
563
349
  // Text reads one level: a topic lists its sections (one with a single
564
350
  // section prints whole). JSON keeps docs(): the whole topic unless
565
351
  // --index. The dense variant is written to be read whole.
@@ -577,7 +363,6 @@ export function registerDocs(program) {
577
363
  zh,
578
364
  dense,
579
365
  index: listSections,
580
- ...(depth != null ? {depth, detail: childDetail} : {}),
581
366
  });
582
367
  if (
583
368
  !options.index &&
@@ -632,7 +417,6 @@ export function registerDocs(program) {
632
417
  ` ${run} docs <topic> <section> read one section`,
633
418
  ` ${run} docs <topic> --full read the whole topic`,
634
419
  ` ${run} docs cli/api go down the docs tree one level at a time`,
635
- ` ${run} docs cli --depth all every doc below cli, one line each`,
636
420
  `With --json, a topic returns its whole doc; add --index for its section list.`,
637
421
  ].join('\n'),
638
422
  ),
@@ -678,8 +462,7 @@ export function registerDocs(program) {
678
462
  }
679
463
 
680
464
  case 'docs.node': {
681
- if (depth != null) emitTree(result.data, detail, childDetail, run);
682
- else emitNode(result.data, detail, run);
465
+ emitNode(result.data, detail, run);
683
466
  break;
684
467
  }
685
468
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.6.5-canary.67efe5b",
3
+ "version": "0.6.5-canary.69aa1cb",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -101,10 +101,10 @@
101
101
  "zod": "^4.4.3"
102
102
  },
103
103
  "peerDependencies": {
104
- "@astryxdesign/charts": "0.6.5-canary.67efe5b",
105
- "@astryxdesign/core": "0.6.5-canary.67efe5b",
106
- "@astryxdesign/lab": "0.6.5-canary.67efe5b",
107
- "@astryxdesign/theme-neutral": "0.6.5-canary.67efe5b"
104
+ "@astryxdesign/charts": "0.6.5-canary.69aa1cb",
105
+ "@astryxdesign/core": "0.6.5-canary.69aa1cb",
106
+ "@astryxdesign/lab": "0.6.5-canary.69aa1cb",
107
+ "@astryxdesign/theme-neutral": "0.6.5-canary.69aa1cb"
108
108
  },
109
109
  "peerDependenciesMeta": {
110
110
  "@astryxdesign/charts": {
@@ -121,10 +121,10 @@
121
121
  }
122
122
  },
123
123
  "devDependencies": {
124
- "@astryxdesign/charts": "0.6.5-canary.67efe5b",
125
- "@astryxdesign/core": "0.6.5-canary.67efe5b",
126
- "@astryxdesign/lab": "0.6.5-canary.67efe5b",
127
- "@astryxdesign/theme-neutral": "0.6.5-canary.67efe5b",
124
+ "@astryxdesign/charts": "0.6.5-canary.69aa1cb",
125
+ "@astryxdesign/core": "0.6.5-canary.69aa1cb",
126
+ "@astryxdesign/lab": "0.6.5-canary.69aa1cb",
127
+ "@astryxdesign/theme-neutral": "0.6.5-canary.69aa1cb",
128
128
  "@heroicons/react": "^2.2.0",
129
129
  "@stylexjs/stylex": "^0.19.0",
130
130
  "@types/babel__core": "^7.20.5",
@@ -1,132 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- import {describe, expect, it} from 'vitest';
4
- import {docs} from './docs.mjs';
5
-
6
- const SLOW = 60_000;
7
-
8
- /**
9
- * @param {any} node
10
- * @param {string} route
11
- * @returns {any}
12
- */
13
- function findRoute(node, route) {
14
- if (node.route === route) return node;
15
- for (const slot of node.slots ?? []) {
16
- for (const child of slot.children) {
17
- const found = findRoute(child, route);
18
- if (found) return found;
19
- }
20
- }
21
- return undefined;
22
- }
23
-
24
- /**
25
- * @param {any} node
26
- * @returns {any[]}
27
- */
28
- function children(node) {
29
- return (node.slots ?? []).flatMap((/** @type {any} */ slot) => slot.children);
30
- }
31
-
32
- describe('docs() depth', () => {
33
- it(
34
- 'reads one level down, as it always has, without a depth',
35
- async () => {
36
- const plain = await docs('cli/api');
37
- expect(plain.type).toBe('docs.node');
38
- if (plain.type !== 'docs.node') return;
39
- expect(plain.data).not.toHaveProperty('childCount');
40
- for (const child of children(plain.data)) {
41
- expect(Object.keys(child).sort()).toEqual([
42
- 'kind',
43
- 'name',
44
- 'route',
45
- 'summary',
46
- 'title',
47
- ]);
48
- }
49
- },
50
- SLOW,
51
- );
52
-
53
- it(
54
- 'goes as many levels down as asked, each doc below as its identity',
55
- async () => {
56
- const result = await docs('cli/api', undefined, {depth: 2});
57
- if (result.type !== 'docs.node') throw new Error(result.type);
58
- const functions = findRoute(result.data, 'cli/api/functions');
59
- expect(functions).not.toHaveProperty('childCount');
60
- expect(findRoute(result.data, 'cli/api/functions/search')).toEqual({
61
- route: 'cli/api/functions/search',
62
- name: 'search',
63
- kind: 'function',
64
- title: 'search()',
65
- summary: expect.any(String),
66
- });
67
- },
68
- SLOW,
69
- );
70
-
71
- it(
72
- 'says how many docs sit below where the read stops',
73
- async () => {
74
- const one = await docs('cli/api', undefined, {depth: 1});
75
- if (one.type !== 'docs.node') throw new Error(one.type);
76
- const functions = findRoute(one.data, 'cli/api/functions');
77
- expect(functions).not.toHaveProperty('slots');
78
- expect(functions.childCount).toBeGreaterThan(1);
79
-
80
- const zero = await docs('cli/api', undefined, {depth: 0});
81
- if (zero.type !== 'docs.node') throw new Error(zero.type);
82
- expect(zero.data.slots).toEqual([]);
83
- expect(zero.data.childCount).toBe(children(one.data).length);
84
- },
85
- SLOW,
86
- );
87
-
88
- it(
89
- "reads every level with 'all', and each doc's text at full detail",
90
- async () => {
91
- const result = await docs('cli/api', undefined, {
92
- depth: 'all',
93
- detail: 'full',
94
- });
95
- if (result.type !== 'docs.node') throw new Error(result.type);
96
- expect(JSON.stringify(result.data)).not.toContain('"childCount"');
97
- const search = findRoute(result.data, 'cli/api/functions/search');
98
- expect(JSON.stringify(search.content)).toContain(
99
- '`astryx search` runs it. Read it with `astryx docs cli/commands/search`.',
100
- );
101
- },
102
- SLOW,
103
- );
104
-
105
- it(
106
- 'reads a doc with nothing below it the same at any depth',
107
- async () => {
108
- expect(
109
- await docs('cli/api/functions/search', undefined, {depth: 3}),
110
- ).toEqual(await docs('cli/api/functions/search'));
111
- },
112
- SLOW,
113
- );
114
-
115
- it(
116
- 'refuses a depth that is not a number of levels, and an unknown detail',
117
- async () => {
118
- for (const depth of [-1, 1.5, 'deep', '2']) {
119
- await expect(
120
- docs('cli/api', undefined, {depth: /** @type {any} */ (depth)}),
121
- ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
122
- }
123
- await expect(
124
- docs('cli/api', undefined, {
125
- depth: 1,
126
- detail: /** @type {any} */ ('huge'),
127
- }),
128
- ).rejects.toMatchObject({code: 'ERR_INVALID_DETAIL'});
129
- },
130
- SLOW,
131
- );
132
- });
@@ -1,219 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- import * as fs from 'node:fs';
4
- import * as path from 'node:path';
5
- import {afterEach, beforeEach, describe, expect, it} from 'vitest';
6
- import {runCli} from '../../../test-utils/run-cli.mjs';
7
-
8
- const SLOW = 60_000;
9
-
10
- /** @type {string} */
11
- let tmpDir;
12
-
13
- beforeEach(() => {
14
- tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-docs-depth-test-'));
15
- });
16
-
17
- afterEach(() => {
18
- fs.rmSync(tmpDir, {recursive: true, force: true});
19
- });
20
-
21
- /** An app with an integration that places one guide under its namespace. */
22
- function scaffoldGuide() {
23
- fs.writeFileSync(
24
- path.join(tmpDir, 'package.json'),
25
- JSON.stringify({name: 'consumer'}),
26
- );
27
- fs.writeFileSync(
28
- path.join(tmpDir, 'astryx.config.mjs'),
29
- "export default {integrations: ['@acme/kit']};\n",
30
- );
31
- const packageDir = path.join(tmpDir, 'node_modules', '@acme', 'kit');
32
- fs.mkdirSync(path.join(packageDir, 'docs'), {recursive: true});
33
- fs.writeFileSync(
34
- path.join(packageDir, 'package.json'),
35
- JSON.stringify({name: '@acme/kit', version: '1.0.0'}),
36
- );
37
- fs.writeFileSync(
38
- path.join(packageDir, 'astryx.integration.mjs'),
39
- "export default {docs: './docs'};\n",
40
- );
41
- const namespace = {
42
- type: 'namespace',
43
- name: 'acme',
44
- title: 'Acme docs',
45
- summary: 'Build with the Acme kit.',
46
- slots: {guides: {title: 'Guides', accepts: {kinds: ['generic']}}},
47
- };
48
- const guide = {
49
- type: 'generic',
50
- name: 'themes',
51
- title: 'Theme building',
52
- description: 'Build an Acme theme.',
53
- placement: {parent: 'namespace:acme', slot: 'guides'},
54
- sections: [
55
- {
56
- title: 'Create the theme',
57
- content: [
58
- {
59
- type: 'prose',
60
- text: 'Child guide body marker: compile the ocean palette.',
61
- },
62
- {type: 'code', lang: 'bash', code: 'npx acme theme build ocean'},
63
- ],
64
- },
65
- ],
66
- };
67
- for (const [file, doc] of [
68
- ['acme.doc.mjs', namespace],
69
- ['themes.doc.mjs', guide],
70
- ]) {
71
- fs.writeFileSync(
72
- path.join(packageDir, 'docs', file),
73
- `export const docs = ${JSON.stringify(doc, null, 2)};\n`,
74
- );
75
- }
76
- }
77
-
78
- describe('astryx docs --depth', () => {
79
- it(
80
- 'lists every doc below a namespace, one line each, by where it sits',
81
- async () => {
82
- const result = await runCli(['docs', 'cli/api', '--depth', 'all']);
83
- expect(result.status).toBe(0);
84
- expect(result.stdout).toMatch(/^functions\s+\S/m);
85
- expect(result.stdout).toMatch(/^functions\/search\s+search\(\): /m);
86
- expect(result.stdout).toContain('Open one: ');
87
- expect(result.stdout).toContain('docs cli/api/<name>');
88
- // One line each: no doc's body.
89
- expect(result.stdout).not.toContain('`astryx search` runs it.');
90
- },
91
- SLOW,
92
- );
93
-
94
- it(
95
- 'says how many docs sit below where the read stops',
96
- async () => {
97
- const zero = await runCli(['docs', 'cli/api', '--depth', '0']);
98
- expect(zero.status).toBe(0);
99
- expect(zero.stdout).toMatch(
100
- /^\d+ docs below\. Read them: .*docs cli\/api --depth 1$/m,
101
- );
102
- expect(zero.stdout).not.toMatch(/^functions\s/m);
103
-
104
- const one = await runCli(['docs', 'cli/api', '--depth', '1']);
105
- expect(one.status).toBe(0);
106
- expect(one.stdout).toMatch(/^functions\s+.*\(\d+ docs below\)$/m);
107
- expect(one.stdout).not.toMatch(/^functions\/search\s/m);
108
- },
109
- SLOW,
110
- );
111
-
112
- it(
113
- 'prints each doc below whole with --detail full, and drops code at compact',
114
- async () => {
115
- scaffoldGuide();
116
- const full = await runCli(
117
- ['docs', 'acme', '--depth', 'all', '--detail', 'full'],
118
- tmpDir,
119
- );
120
- expect(full.status).toBe(0);
121
- expect(full.stdout).toMatch(/^## Theme building \(themes\)$/m);
122
- expect(full.stdout).toMatch(/^### Create the theme$/m);
123
- expect(full.stdout).toContain(
124
- 'Child guide body marker: compile the ocean palette.',
125
- );
126
- expect(full.stdout).toContain('npx acme theme build ocean');
127
-
128
- const compact = await runCli(
129
- ['docs', 'acme', '--depth', '1', '--detail', 'compact'],
130
- tmpDir,
131
- );
132
- expect(compact.status).toBe(0);
133
- expect(compact.stdout).toContain('Child guide body marker');
134
- expect(compact.stdout).not.toContain('npx acme theme build ocean');
135
-
136
- // Without --depth, the namespace still lists the guide by one line.
137
- const plain = await runCli(['docs', 'acme'], tmpDir);
138
- expect(plain.status).toBe(0);
139
- expect(plain.stdout).toMatch(/^themes\s+Build an Acme theme\./m);
140
- expect(plain.stdout).not.toContain('Child guide body marker');
141
- },
142
- SLOW,
143
- );
144
-
145
- it(
146
- 'returns the same tree as JSON, with text only when --detail asks',
147
- async () => {
148
- const brief = await runCli(['--json', 'docs', 'cli/api', '--depth', '2']);
149
- expect(brief.status).toBe(0);
150
- const briefData = JSON.parse(brief.stdout);
151
- expect(briefData.type).toBe('docs.node');
152
- const functions = briefData.data.slots
153
- .flatMap((/** @type {any} */ slot) => slot.children)
154
- .find(
155
- (/** @type {any} */ child) => child.route === 'cli/api/functions',
156
- );
157
- const search = functions.slots
158
- .flatMap((/** @type {any} */ slot) => slot.children)
159
- .find(
160
- (/** @type {any} */ child) =>
161
- child.route === 'cli/api/functions/search',
162
- );
163
- expect(search).not.toHaveProperty('content');
164
-
165
- const full = await runCli([
166
- '--json',
167
- 'docs',
168
- 'cli/api',
169
- '--depth',
170
- '2',
171
- '--detail',
172
- 'full',
173
- ]);
174
- expect(full.status).toBe(0);
175
- expect(full.stdout).toContain('`astryx search` runs it.');
176
- },
177
- SLOW,
178
- );
179
-
180
- it(
181
- 'composes with --index and --full, and leaves a topic read as it was',
182
- async () => {
183
- const depth = await runCli(['docs', 'cli/api', '--depth', '1']);
184
- expect(depth.status).toBe(0);
185
- for (const flag of ['--index', '--full']) {
186
- const both = await runCli(['docs', 'cli/api', '--depth', '1', flag]);
187
- expect(both.status).toBe(0);
188
- expect(both.stdout).toBe(depth.stdout);
189
- }
190
- for (const args of [
191
- ['docs', 'theme'],
192
- ['docs', 'theme', '--index'],
193
- ['docs', 'theme', '--full'],
194
- ]) {
195
- const plain = await runCli(args);
196
- const withDepth = await runCli([...args, '--depth', '2']);
197
- expect(withDepth.status).toBe(plain.status);
198
- expect(withDepth.stdout).toBe(plain.stdout);
199
- }
200
- },
201
- SLOW,
202
- );
203
-
204
- it(
205
- 'refuses a depth that is not a number of levels',
206
- async () => {
207
- const result = await runCli([
208
- '--json',
209
- 'docs',
210
- 'cli/api',
211
- '--depth',
212
- 'deep',
213
- ]);
214
- expect(result.status).toBe(1);
215
- expect(JSON.parse(result.stdout).code).toBe('ERR_INVALID_ARGUMENT');
216
- },
217
- SLOW,
218
- );
219
- });