@astryxdesign/cli 0.6.5-vanilla-poc.6e25cfc → 0.6.6

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 (197) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +1 -34
  3. package/api/build/_adapter.d.mts +14 -0
  4. package/api/build/_adapter.mjs +58 -1
  5. package/api/build/build.test.mjs +74 -1
  6. package/api/build/kit/kit.mjs +39 -7
  7. package/api/build/kit/rank.d.mts +8 -0
  8. package/api/build/kit/rank.mjs +14 -0
  9. package/api/build/kit/weights.d.mts +82 -0
  10. package/api/build/kit/weights.json +1 -0
  11. package/api/build/kit/weights.mjs +305 -0
  12. package/api/build/kit/weights.test.mjs +190 -0
  13. package/api/component/_adapter.d.mts +1 -51
  14. package/api/component/_adapter.mjs +3 -110
  15. package/api/component/component.d.mts +1 -9
  16. package/api/component/component.doc.mjs +7 -52
  17. package/api/component/component.mjs +3 -276
  18. package/api/component/component.type.d.mts +1 -28
  19. package/api/component/component.type.mjs +1 -20
  20. package/api/docs/docs.d.mts +6 -0
  21. package/api/docs/docs.depth.test.mjs +132 -0
  22. package/api/docs/docs.doc.mjs +31 -2
  23. package/api/docs/docs.mjs +44 -1
  24. package/api/docs/docs.type.d.mts +38 -1
  25. package/api/docs/docs.type.mjs +18 -1
  26. package/api/docs/node/node.d.mts +28 -3
  27. package/api/docs/node/node.mjs +146 -23
  28. package/api/hook/list/list.d.mts +1 -1
  29. package/api/index.d.mts +0 -8
  30. package/api/index.mjs +0 -8
  31. package/api/integration/add-theme.mjs +93 -3
  32. package/api/integration/add-theme.test.mjs +100 -0
  33. package/api/integration/integrationAddTheme.doc.mjs +1 -1
  34. package/api/search/search.d.mts +8 -1
  35. package/api/search/search.doc.mjs +3 -3
  36. package/api/search/search.mjs +58 -73
  37. package/api/search/search.test.mjs +122 -21
  38. package/api/search/search.type.d.mts +0 -10
  39. package/api/search/search.type.mjs +0 -1
  40. package/api/template/cdn/cdn.test.mjs +2 -50
  41. package/api/template/template.d.mts +0 -6
  42. package/api/template/template.doc.mjs +4 -56
  43. package/api/template/template.mjs +0 -82
  44. package/api/template/template.type.d.mts +0 -12
  45. package/api/template/template.type.mjs +0 -7
  46. package/assets/cdn.template.html +5 -19
  47. package/assets/docs/tokens.doc.mjs +3 -3
  48. package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
  49. package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
  50. package/clients/cli/commands/component/index.mjs +9 -66
  51. package/clients/cli/commands/component.doc.mjs +4 -26
  52. package/clients/cli/commands/docs.depth.test.mjs +219 -0
  53. package/clients/cli/commands/docs.doc.mjs +15 -2
  54. package/clients/cli/commands/docs.mjs +222 -5
  55. package/clients/cli/commands/integration-add.doc.mjs +1 -1
  56. package/clients/cli/commands/search.doc.mjs +2 -3
  57. package/clients/cli/commands/search.mjs +11 -8
  58. package/clients/cli/commands/search.test.mjs +35 -40
  59. package/clients/cli/commands/template.doc.mjs +3 -31
  60. package/clients/cli/commands/template.mjs +2 -37
  61. package/foundation/discovery/theme-discovery.d.mts +6 -0
  62. package/foundation/discovery/theme-discovery.mjs +9 -0
  63. package/foundation/response/response-types.doc.mjs +0 -38
  64. package/package.json +5 -9
  65. package/api/_vanilla-assets.d.mts +0 -10
  66. package/api/_vanilla-assets.mjs +0 -59
  67. package/api/component/html/html.d.mts +0 -12
  68. package/api/component/html/html.doc.d.mts +0 -5
  69. package/api/component/html/html.doc.mjs +0 -66
  70. package/api/component/html/html.mjs +0 -25
  71. package/api/component/html/html.test.mjs +0 -61
  72. package/api/component/html/html.type.d.mts +0 -23
  73. package/api/component/html/html.type.mjs +0 -27
  74. package/api/component/web-components/web-components.d.mts +0 -12
  75. package/api/component/web-components/web-components.doc.d.mts +0 -5
  76. package/api/component/web-components/web-components.doc.mjs +0 -70
  77. package/api/component/web-components/web-components.mjs +0 -32
  78. package/api/component/web-components/web-components.test.mjs +0 -50
  79. package/api/component/web-components/web-components.type.d.mts +0 -23
  80. package/api/component/web-components/web-components.type.mjs +0 -27
  81. package/api/template/_adapter.d.mts +0 -38
  82. package/api/template/_adapter.mjs +0 -90
  83. package/api/template/html/html.d.mts +0 -17
  84. package/api/template/html/html.doc.d.mts +0 -5
  85. package/api/template/html/html.doc.mjs +0 -72
  86. package/api/template/html/html.mjs +0 -61
  87. package/api/template/html/html.test.mjs +0 -71
  88. package/api/template/html/html.type.d.mts +0 -26
  89. package/api/template/html/html.type.mjs +0 -28
  90. package/api/template/web-components/web-components.d.mts +0 -13
  91. package/api/template/web-components/web-components.doc.d.mts +0 -5
  92. package/api/template/web-components/web-components.doc.mjs +0 -69
  93. package/api/template/web-components/web-components.mjs +0 -51
  94. package/api/template/web-components/web-components.test.mjs +0 -73
  95. package/api/template/web-components/web-components.type.d.mts +0 -26
  96. package/api/template/web-components/web-components.type.mjs +0 -28
  97. package/assets/generated/core-component-docs.json +0 -1
  98. package/assets/vanilla/elements-markup/Avatar.html +0 -27
  99. package/assets/vanilla/elements-markup/Badge.html +0 -16
  100. package/assets/vanilla/elements-markup/Banner.html +0 -32
  101. package/assets/vanilla/elements-markup/Breadcrumbs.html +0 -23
  102. package/assets/vanilla/elements-markup/Button.html +0 -37
  103. package/assets/vanilla/elements-markup/Card.html +0 -24
  104. package/assets/vanilla/elements-markup/CheckboxInput.html +0 -28
  105. package/assets/vanilla/elements-markup/Collapsible.html +0 -26
  106. package/assets/vanilla/elements-markup/DateInput.html +0 -28
  107. package/assets/vanilla/elements-markup/Dialog.html +0 -33
  108. package/assets/vanilla/elements-markup/Divider.html +0 -20
  109. package/assets/vanilla/elements-markup/DropdownMenu.html +0 -26
  110. package/assets/vanilla/elements-markup/EmptyState.html +0 -27
  111. package/assets/vanilla/elements-markup/Heading.html +0 -18
  112. package/assets/vanilla/elements-markup/HoverCard.html +0 -39
  113. package/assets/vanilla/elements-markup/Layout.html +0 -28
  114. package/assets/vanilla/elements-markup/Lightbox.html +0 -33
  115. package/assets/vanilla/elements-markup/Link.html +0 -23
  116. package/assets/vanilla/elements-markup/NumberInput.html +0 -34
  117. package/assets/vanilla/elements-markup/ProgressBar.html +0 -47
  118. package/assets/vanilla/elements-markup/RadioList.html +0 -28
  119. package/assets/vanilla/elements-markup/Selector.html +0 -34
  120. package/assets/vanilla/elements-markup/SideNav.html +0 -32
  121. package/assets/vanilla/elements-markup/Skeleton.html +0 -18
  122. package/assets/vanilla/elements-markup/Slider.html +0 -31
  123. package/assets/vanilla/elements-markup/Stack.html +0 -33
  124. package/assets/vanilla/elements-markup/StatusDot.html +0 -19
  125. package/assets/vanilla/elements-markup/Switch.html +0 -28
  126. package/assets/vanilla/elements-markup/Tab.html +0 -18
  127. package/assets/vanilla/elements-markup/TabList.html +0 -31
  128. package/assets/vanilla/elements-markup/Table.html +0 -31
  129. package/assets/vanilla/elements-markup/Text.html +0 -24
  130. package/assets/vanilla/elements-markup/TextArea.html +0 -32
  131. package/assets/vanilla/elements-markup/TextInput.html +0 -92
  132. package/assets/vanilla/elements-markup/Theme.html +0 -16
  133. package/assets/vanilla/elements-markup/TimeInput.html +0 -29
  134. package/assets/vanilla/elements-markup/Toast.html +0 -22
  135. package/assets/vanilla/elements-markup/Tooltip.html +0 -30
  136. package/assets/vanilla/elements-markup/TopNav.html +0 -85
  137. package/assets/vanilla/elements-markup/Typeahead.html +0 -31
  138. package/assets/vanilla/elements-templates/dashboard.html +0 -167
  139. package/assets/vanilla/elements-templates/detail-page.html +0 -145
  140. package/assets/vanilla/elements-templates/form-two-column.html +0 -135
  141. package/assets/vanilla/elements-templates/kanban-board.html +0 -141
  142. package/assets/vanilla/elements-templates/login.html +0 -100
  143. package/assets/vanilla/elements-templates/product-detail.html +0 -128
  144. package/assets/vanilla/elements-templates/settings.html +0 -130
  145. package/assets/vanilla/elements-templates/shell-side-nav.html +0 -160
  146. package/assets/vanilla/elements-templates/table-filter.html +0 -154
  147. package/assets/vanilla/markup/Avatar.html +0 -24
  148. package/assets/vanilla/markup/Badge.html +0 -12
  149. package/assets/vanilla/markup/Banner.html +0 -49
  150. package/assets/vanilla/markup/Breadcrumbs.html +0 -38
  151. package/assets/vanilla/markup/Button.html +0 -37
  152. package/assets/vanilla/markup/Card.html +0 -16
  153. package/assets/vanilla/markup/CheckboxInput.html +0 -45
  154. package/assets/vanilla/markup/Collapsible.html +0 -9
  155. package/assets/vanilla/markup/DateInput.html +0 -42
  156. package/assets/vanilla/markup/Dialog.html +0 -45
  157. package/assets/vanilla/markup/Divider.html +0 -9
  158. package/assets/vanilla/markup/DropdownMenu.html +0 -30
  159. package/assets/vanilla/markup/EmptyState.html +0 -41
  160. package/assets/vanilla/markup/Heading.html +0 -9
  161. package/assets/vanilla/markup/HoverCard.html +0 -85
  162. package/assets/vanilla/markup/Layout.html +0 -35
  163. package/assets/vanilla/markup/Lightbox.html +0 -107
  164. package/assets/vanilla/markup/Link.html +0 -6
  165. package/assets/vanilla/markup/NumberInput.html +0 -55
  166. package/assets/vanilla/markup/ProgressBar.html +0 -101
  167. package/assets/vanilla/markup/RadioList.html +0 -90
  168. package/assets/vanilla/markup/Selector.html +0 -92
  169. package/assets/vanilla/markup/SideNav.html +0 -82
  170. package/assets/vanilla/markup/Skeleton.html +0 -26
  171. package/assets/vanilla/markup/Slider.html +0 -65
  172. package/assets/vanilla/markup/Stack.html +0 -13
  173. package/assets/vanilla/markup/StatusDot.html +0 -22
  174. package/assets/vanilla/markup/Switch.html +0 -47
  175. package/assets/vanilla/markup/TabList.html +0 -56
  176. package/assets/vanilla/markup/Table.html +0 -75
  177. package/assets/vanilla/markup/Text.html +0 -9
  178. package/assets/vanilla/markup/TextArea.html +0 -37
  179. package/assets/vanilla/markup/TextInput.html +0 -80
  180. package/assets/vanilla/markup/Theme.html +0 -48
  181. package/assets/vanilla/markup/TimeInput.html +0 -43
  182. package/assets/vanilla/markup/Toast.html +0 -42
  183. package/assets/vanilla/markup/Tooltip.html +0 -18
  184. package/assets/vanilla/markup/TopNav.html +0 -81
  185. package/assets/vanilla/markup/Typeahead.html +0 -60
  186. package/assets/vanilla/templates/dashboard.html +0 -462
  187. package/assets/vanilla/templates/detail-page.html +0 -536
  188. package/assets/vanilla/templates/form-two-column.html +0 -438
  189. package/assets/vanilla/templates/kanban-board.html +0 -443
  190. package/assets/vanilla/templates/login.html +0 -199
  191. package/assets/vanilla/templates/product-detail.html +0 -335
  192. package/assets/vanilla/templates/settings.html +0 -374
  193. package/assets/vanilla/templates/shell-side-nav.html +0 -440
  194. package/assets/vanilla/templates/table-filter.html +0 -514
  195. package/clients/cli/commands/vanilla-html.test.mjs +0 -245
  196. package/foundation/discovery/bundled-component-docs.d.mts +0 -39
  197. package/foundation/discovery/bundled-component-docs.mjs +0 -92
@@ -0,0 +1,219 @@
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
+ });
@@ -22,7 +22,9 @@ 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.',
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).',
26
28
  fn: 'docs',
27
29
  args: [
28
30
  {name: 'topic', param: 'topic', required: false},
@@ -39,6 +41,12 @@ export const doc = {
39
41
  description:
40
42
  'Print the whole topic instead of its sections (text; `--json` returns the whole topic unless --index). Cannot be set with --index',
41
43
  },
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
+ },
42
50
  ],
43
51
  examples: [
44
52
  {label: 'List topics', cli: 'astryx docs'},
@@ -46,6 +54,11 @@ export const doc = {
46
54
  {label: 'A whole topic as JSON', cli: 'astryx docs spacing --json'},
47
55
  {label: 'One section', cli: 'astryx docs theme quick-start'},
48
56
  {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
+ },
49
62
  {label: 'One API function', cli: 'astryx docs cli/api/functions/search'},
50
63
  {label: 'A whole guide', cli: 'astryx docs cli/integrations/quick-start --full'},
51
64
  ],
@@ -53,7 +66,7 @@ export const doc = {
53
66
  {code: 0, when: 'success'},
54
67
  {
55
68
  code: 1,
56
- when: 'unknown topic or route, or a section that matches no section or more than one',
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',
57
70
  },
58
71
  ],
59
72
  related: ['search', 'component', 'hook', 'template'],
@@ -4,9 +4,10 @@
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. `--json`
8
- * keeps the docs() contract: a topic returns its whole doc, and `--index` its
9
- * sections.
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.
10
11
  * Supports --detail (full|compact|brief) and --lang (en|zh|dense). A code
11
12
  * block's label prints above its fence, and table cells escape their pipes.
12
13
  *
@@ -18,6 +19,7 @@
18
19
  * astryx docs <topic> --full Print the whole topic
19
20
  * astryx docs <route> Open a node of the docs tree, such as
20
21
  * cli, cli/api, or cli/api/functions/search
22
+ * astryx docs <route> --depth <n|all> Read that many levels below it
21
23
  */
22
24
 
23
25
  import {
@@ -181,6 +183,202 @@ function formatReferenceFull(docs, detail) {
181
183
  return `${header}\n\n${sections.join(sep)}`;
182
184
  }
183
185
 
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
+
184
382
  /**
185
383
  * The moves a read offers (spec:AST-047), one runnable command per line: up to
186
384
  * the level it sits in, the item before and after it, and the docs it names.
@@ -331,7 +529,7 @@ export function registerDocs(program) {
331
529
  action: async (
332
530
  /** @type {string | undefined} */ topic,
333
531
  /** @type {string | undefined} */ sectionName,
334
- /** @type {{index?: boolean, full?: boolean}} */ options = {},
532
+ /** @type {{index?: boolean, full?: boolean, depth?: string}} */ options = {},
335
533
  ) => {
336
534
  const run = getCliInvocation();
337
535
  const lang = program.opts().lang || null;
@@ -346,6 +544,22 @@ export function registerDocs(program) {
346
544
  {code: ERROR_CODES.ERR_INVALID_ARGUMENT},
347
545
  );
348
546
  }
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;
349
563
  // Text reads one level: a topic lists its sections (one with a single
350
564
  // section prints whole). JSON keeps docs(): the whole topic unless
351
565
  // --index. The dense variant is written to be read whole.
@@ -363,6 +577,7 @@ export function registerDocs(program) {
363
577
  zh,
364
578
  dense,
365
579
  index: listSections,
580
+ ...(depth != null ? {depth, detail: childDetail} : {}),
366
581
  });
367
582
  if (
368
583
  !options.index &&
@@ -417,6 +632,7 @@ export function registerDocs(program) {
417
632
  ` ${run} docs <topic> <section> read one section`,
418
633
  ` ${run} docs <topic> --full read the whole topic`,
419
634
  ` ${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`,
420
636
  `With --json, a topic returns its whole doc; add --index for its section list.`,
421
637
  ].join('\n'),
422
638
  ),
@@ -462,7 +678,8 @@ export function registerDocs(program) {
462
678
  }
463
679
 
464
680
  case 'docs.node': {
465
- emitNode(result.data, detail, run);
681
+ if (depth != null) emitTree(result.data, detail, childDetail, run);
682
+ else emitNode(result.data, detail, run);
466
683
  break;
467
684
  }
468
685
  }
@@ -60,7 +60,7 @@ export const doc = {
60
60
  flag: '--from <theme>',
61
61
  param: 'options.from',
62
62
  description:
63
- 'Existing theme slug to fork as a starting point instead of a blank scaffold; the new theme copies the base and has no link back. Only valid for theme',
63
+ 'Existing theme slug to fork as a starting point instead of a blank scaffold; the new theme copies the base and has no link back, and package.json `dependencies` gains the npm packages the copied files import (other than Core and React). Only valid for theme',
64
64
  },
65
65
  {
66
66
  flag: '--to <version>',
@@ -17,8 +17,7 @@ export const doc = {
17
17
  description:
18
18
  'Terminal front-end to search(): prints one ranked, greppable list across ' +
19
19
  'every content domain, each row carrying a follow-up command to act on it. ' +
20
- 'Outside an app, where @astryxdesign/core is not installed, it searches built-in ' +
21
- 'docs and themes plus the version-matched Core component docs bundled with the CLI.',
20
+ 'Outside an app, where @astryxdesign/core is not installed, it searches the docs and themes.',
22
21
  fn: 'search',
23
22
  // Every word after `search` is the query: `astryx search dark mode` searches
24
23
  // for "dark mode", with no quotes needed.
@@ -56,7 +55,7 @@ export const doc = {
56
55
  {code: 0, when: 'success (including zero matches)'},
57
56
  {
58
57
  code: 1,
59
- when: 'invalid --type, a --limit that is not a positive integer, or --type hook or template where @astryxdesign/core cannot be found',
58
+ when: 'invalid --type, a --limit that is not a positive integer, or --type component, hook, or template where @astryxdesign/core cannot be found',
60
59
  },
61
60
  ],
62
61
  related: ['component', 'hook', 'docs', 'template', 'build'],
@@ -32,6 +32,7 @@ import {cliError} from '../lib/cli-error.mjs';
32
32
  import {defineCommand} from '../lib/define-command.mjs';
33
33
  import {search as searchApi} from '../../../api/search/search.mjs';
34
34
  import {Project} from '../../../foundation/config/project.mjs';
35
+ import {findCoreDir} from '../../../foundation/fs/paths.mjs';
35
36
  import {warnOnIntegrationIssues} from '../../../foundation/integrations/integration-warnings.mjs';
36
37
  import {doc as searchCommand} from './search.doc.mjs';
37
38
  import {doc as searchFn} from '../../../api/search/search.doc.mjs';
@@ -103,14 +104,16 @@ export function registerSearch(program) {
103
104
  // ── Text output ──────────────────────────────────────────────
104
105
  const run = getCliInvocation();
105
106
  const {query: q, matchCount, results} = result.data;
106
- const bundledDocs = result.meta?.componentDocs;
107
- const note = bundledDocs
108
- ? [
109
- text(
110
- `Component results use ${bundledDocs.package}@${bundledDocs.version} docs bundled with the CLI because Core is not installed here.${options.type ? '' : ' Docs and themes were also searched; hooks and templates were not.'}`,
111
- ),
112
- ]
113
- : [];
107
+ // Outside an app an open search covers the docs and themes alone. Say
108
+ // so, so that list does not read as "Astryx has no such component".
109
+ const note =
110
+ !options.type && !findCoreDir(process.cwd())
111
+ ? [
112
+ text(
113
+ '@astryxdesign/core is not installed here, so only the docs and themes were searched.',
114
+ ),
115
+ ]
116
+ : [];
114
117
 
115
118
  // No matches is a valid, successful outcome — clean message, exit 0.
116
119
  if (results.length === 0) {