@astryxdesign/cli 0.6.5-canary.b421f01 → 0.6.5-canary.b65e45f

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 (34) hide show
  1. package/api/build/_adapter.d.mts +14 -0
  2. package/api/build/_adapter.mjs +58 -1
  3. package/api/build/build.test.mjs +74 -1
  4. package/api/build/kit/kit.mjs +39 -7
  5. package/api/build/kit/rank.d.mts +8 -0
  6. package/api/build/kit/rank.mjs +14 -0
  7. package/api/build/kit/weights.d.mts +82 -0
  8. package/api/build/kit/weights.json +1 -0
  9. package/api/build/kit/weights.mjs +305 -0
  10. package/api/build/kit/weights.test.mjs +190 -0
  11. package/api/docs/docs.d.mts +6 -0
  12. package/api/docs/docs.depth.test.mjs +132 -0
  13. package/api/docs/docs.doc.mjs +31 -2
  14. package/api/docs/docs.mjs +44 -1
  15. package/api/docs/docs.type.d.mts +38 -1
  16. package/api/docs/docs.type.mjs +18 -1
  17. package/api/docs/node/node.d.mts +28 -3
  18. package/api/docs/node/node.mjs +146 -23
  19. package/api/hook/list/list.d.mts +1 -1
  20. package/api/integration/add-theme.mjs +93 -3
  21. package/api/integration/add-theme.test.mjs +100 -0
  22. package/api/integration/integrationAddTheme.doc.mjs +1 -1
  23. package/api/search/search.d.mts +8 -1
  24. package/api/search/search.mjs +48 -37
  25. package/api/search/search.test.mjs +114 -1
  26. package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
  27. package/clients/cli/commands/docs.depth.test.mjs +219 -0
  28. package/clients/cli/commands/docs.doc.mjs +15 -2
  29. package/clients/cli/commands/docs.mjs +222 -5
  30. package/clients/cli/commands/integration-add.doc.mjs +1 -1
  31. package/clients/cli/commands/search.test.mjs +22 -13
  32. package/foundation/discovery/theme-discovery.d.mts +6 -0
  33. package/foundation/discovery/theme-discovery.mjs +9 -0
  34. package/package.json +9 -9
@@ -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>',
@@ -288,22 +288,31 @@ describe('search CLI — exit codes + JSON contract', () => {
288
288
  });
289
289
 
290
290
  it('prints every result field under its JSON key (score and reason with --verbose)', async () => {
291
- // One query that reaches every domain, so every per-domain field shows.
292
- const args = ['search', 'theme', '--limit', '60'];
293
- const env = JSON.parse((await runCli(['--json', ...args], REPO_ROOT)).stdout);
294
- expect(new Set(env.data.results.map(r => r.domain))).toEqual(new Set(SEARCH_DOMAINS));
295
- const plain = (await runCli(args, REPO_ROOT)).stdout.split('\n');
296
- const verbose = (await runCli([...args, '--verbose'], REPO_ROOT)).stdout.split('\n');
297
- for (const result of env.data.results) {
298
- for (const [key, value] of Object.entries(result)) {
299
- if (value == null || value === '') continue;
300
- const label = `${result.domain} ${result.name}: ${key}`;
301
- expect(printsField(verbose, key, value), label).toBe(true);
302
- if (key !== 'score' && key !== 'reason') {
303
- expect(printsField(plain, key, value), label).toBe(true);
291
+ // Between them these reach every domain, so every per-domain field shows.
292
+ // A theme matches `theme` only through its description, a prose mention
293
+ // ranked below every name and keyword hit, so the theme domain comes from
294
+ // a theme's own name.
295
+ const domains = new Set();
296
+ for (const args of [
297
+ ['search', 'theme', '--limit', '60'],
298
+ ['search', 'neutral', '--type', 'theme'],
299
+ ]) {
300
+ const env = JSON.parse((await runCli(['--json', ...args], REPO_ROOT)).stdout);
301
+ const plain = (await runCli(args, REPO_ROOT)).stdout.split('\n');
302
+ const verbose = (await runCli([...args, '--verbose'], REPO_ROOT)).stdout.split('\n');
303
+ for (const result of env.data.results) {
304
+ domains.add(result.domain);
305
+ for (const [key, value] of Object.entries(result)) {
306
+ if (value == null || value === '') continue;
307
+ const label = `${result.domain} ${result.name}: ${key}`;
308
+ expect(printsField(verbose, key, value), label).toBe(true);
309
+ if (key !== 'score' && key !== 'reason') {
310
+ expect(printsField(plain, key, value), label).toBe(true);
311
+ }
304
312
  }
305
313
  }
306
314
  }
315
+ expect(domains).toEqual(new Set(SEARCH_DOMAINS));
307
316
  }, 90_000);
308
317
 
309
318
  it('--verbose exits 0 and prints import/match detail', async () => {
@@ -1,6 +1,12 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * Every module a theme source file imports or re-exports, as written.
6
+ * @param {string} file
7
+ * @returns {string[]}
8
+ */
9
+ export function themeFileImports(file: string): string[];
4
10
  /**
5
11
  * How messages about a theme descriptor name it.
6
12
  * @param {string} docPath
@@ -200,6 +200,15 @@ function moduleSpecifiers(file, jscodeshift) {
200
200
  return specifiers;
201
201
  }
202
202
 
203
+ /**
204
+ * Every module a theme source file imports or re-exports, as written.
205
+ * @param {string} file
206
+ * @returns {string[]}
207
+ */
208
+ export function themeFileImports(file) {
209
+ return moduleSpecifiers(file, sourceParser());
210
+ }
211
+
203
212
  /**
204
213
  * Validate that every local static dependency is copied with the theme.
205
214
  * @param {string} file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.6.5-canary.b421f01",
3
+ "version": "0.6.5-canary.b65e45f",
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.b421f01",
105
- "@astryxdesign/core": "0.6.5-canary.b421f01",
106
- "@astryxdesign/lab": "0.6.5-canary.b421f01",
107
- "@astryxdesign/theme-neutral": "0.6.5-canary.b421f01"
104
+ "@astryxdesign/charts": "0.6.5-canary.b65e45f",
105
+ "@astryxdesign/core": "0.6.5-canary.b65e45f",
106
+ "@astryxdesign/lab": "0.6.5-canary.b65e45f",
107
+ "@astryxdesign/theme-neutral": "0.6.5-canary.b65e45f"
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.b421f01",
125
- "@astryxdesign/core": "0.6.5-canary.b421f01",
126
- "@astryxdesign/lab": "0.6.5-canary.b421f01",
127
- "@astryxdesign/theme-neutral": "0.6.5-canary.b421f01",
124
+ "@astryxdesign/charts": "0.6.5-canary.b65e45f",
125
+ "@astryxdesign/core": "0.6.5-canary.b65e45f",
126
+ "@astryxdesign/lab": "0.6.5-canary.b65e45f",
127
+ "@astryxdesign/theme-neutral": "0.6.5-canary.b65e45f",
128
128
  "@heroicons/react": "^2.2.0",
129
129
  "@stylexjs/stylex": "^0.19.0",
130
130
  "@types/babel__core": "^7.20.5",