@astryxdesign/cli 0.6.5 → 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 (217) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +16 -15
  3. package/api/build/_adapter.d.mts +50 -2
  4. package/api/build/_adapter.mjs +98 -10
  5. package/api/build/build.doc.mjs +2 -2
  6. package/api/build/build.test.mjs +111 -2
  7. package/api/build/kit/kit.mjs +98 -22
  8. package/api/build/kit/rank.d.mts +32 -8
  9. package/api/build/kit/rank.mjs +291 -97
  10. package/api/build/kit/rank.test.mjs +231 -48
  11. package/api/build/kit/weights.d.mts +82 -0
  12. package/api/build/kit/weights.json +1 -0
  13. package/api/build/kit/weights.mjs +305 -0
  14. package/api/build/kit/weights.test.mjs +190 -0
  15. package/api/docs/docs.d.mts +6 -0
  16. package/api/docs/docs.depth.test.mjs +132 -0
  17. package/api/docs/docs.doc.mjs +31 -2
  18. package/api/docs/docs.mjs +44 -1
  19. package/api/docs/docs.test.mjs +279 -0
  20. package/api/docs/docs.type.d.mts +38 -1
  21. package/api/docs/docs.type.mjs +18 -1
  22. package/api/docs/integration-tree.test.mjs +572 -0
  23. package/api/docs/integrationDocs.test.mjs +336 -0
  24. package/api/docs/node/node.d.mts +28 -3
  25. package/api/docs/node/node.mjs +146 -23
  26. package/api/error.d.mts +22 -0
  27. package/api/error.mjs +42 -0
  28. package/api/gap-report/gap-report.d.mts +3 -1
  29. package/api/gap-report/gap-report.mjs +12 -2
  30. package/api/gap-report/gap-report.test.mjs +106 -0
  31. package/api/hook/list/list.d.mts +1 -1
  32. package/api/integration/add-contribution.d.mts +2 -1
  33. package/api/integration/add-contribution.mjs +7 -3
  34. package/api/integration/add-contribution.test.mjs +3 -3
  35. package/api/integration/add-theme.mjs +338 -26
  36. package/api/integration/add-theme.test.mjs +314 -1
  37. package/api/integration/authoring-checks.mjs +10 -7
  38. package/api/integration/authoring-checks.type.d.mts +8 -0
  39. package/api/integration/authoring-checks.type.mjs +7 -3
  40. package/api/integration/integration-authoring.type.d.mts +4 -1
  41. package/api/integration/integration-authoring.type.mjs +6 -1
  42. package/api/integration/integrationAdd.doc.mjs +6 -0
  43. package/api/integration/integrationAddTheme.doc.mjs +10 -0
  44. package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
  45. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  46. package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
  47. package/api/integration/pack-check.mjs +12 -3
  48. package/api/integration/pack-check.test.mjs +52 -3
  49. package/api/integration/validate-integration.d.mts +4 -2
  50. package/api/integration/validate-integration.mjs +7 -2
  51. package/api/integration/validate-integration.test.mjs +55 -0
  52. package/api/integration/validate-integration.type.d.mts +5 -0
  53. package/api/integration/validate-integration.type.mjs +5 -1
  54. package/api/integration/validateIntegration.doc.mjs +1 -1
  55. package/api/layout/expand/expand.mjs +12 -7
  56. package/api/layout/expand/expand.receipt.test.mjs +74 -0
  57. package/api/layout/layout.type.d.mts +1 -0
  58. package/api/layout/layout.type.mjs +1 -0
  59. package/api/layout/layoutExpand.doc.mjs +1 -1
  60. package/api/search/search.d.mts +36 -5
  61. package/api/search/search.doc.mjs +4 -4
  62. package/api/search/search.mjs +194 -54
  63. package/api/search/search.test.mjs +825 -0
  64. package/api/search/search.type.d.mts +5 -5
  65. package/api/search/search.type.mjs +5 -5
  66. package/api/swizzle/copy/copy.mjs +66 -3
  67. package/api/swizzle/swizzle.doc.mjs +4 -0
  68. package/api/template/copy/copy.mjs +14 -8
  69. package/api/template/copy/copy.receipt.test.mjs +77 -0
  70. package/api/template/show/show.mjs +15 -4
  71. package/api/template/show/show.test.mjs +76 -0
  72. package/api/template/template-integration.test.mjs +14 -0
  73. package/api/template/template.d.mts +1 -1
  74. package/api/template/template.doc.mjs +6 -2
  75. package/api/template/template.mjs +1 -0
  76. package/api/template/template.type.d.mts +2 -0
  77. package/api/template/template.type.mjs +2 -0
  78. package/api/theme/build/build.d.mts +24 -0
  79. package/api/theme/build/build.icon-lineage.test.mjs +117 -0
  80. package/api/theme/build/build.icon-preservation.test.mjs +639 -0
  81. package/api/theme/build/build.mjs +381 -77
  82. package/api/theme/build/build.project-core.test.mjs +165 -0
  83. package/api/theme/build/build.test.mjs +190 -1
  84. package/api/theme/build/icon-imports.d.mts +47 -0
  85. package/api/theme/build/icon-imports.mjs +691 -0
  86. package/api/theme/themeBuild.doc.d.mts +4 -1
  87. package/api/theme/themeBuild.doc.mjs +14 -3
  88. package/api/upgrade/run/run.mjs +20 -3
  89. package/api/upgrade/run/run.test.mjs +45 -1
  90. package/api/upgrade/upgrade.doc.mjs +1 -1
  91. package/api/upgrade/upgrade.type.d.mts +1 -0
  92. package/api/upgrade/upgrade.type.mjs +1 -0
  93. package/assets/docs/icons.doc.mjs +1 -0
  94. package/assets/docs/theme.doc.mjs +3 -2
  95. package/assets/docs/tokens.doc.mjs +3 -3
  96. package/assets/docs/tree/add-a-theme.doc.mjs +4 -0
  97. package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
  98. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  99. package/assets/docs/tree/checks.doc.mjs +1 -1
  100. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
  101. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  102. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  103. package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
  104. package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
  105. package/assets/docs/tree/versioning.doc.mjs +7 -6
  106. package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.doc.mjs +15 -0
  107. package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupShowcase.tsx +38 -0
  108. package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.doc.mjs +20 -0
  109. package/assets/templates/blocks/components/DropdownMenuGroup/DropdownMenuGroupWithSelectable.tsx +48 -0
  110. package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
  111. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
  112. package/assets/templates/pages/blank/template.doc.mjs +3 -1
  113. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
  114. package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
  115. package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
  116. package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
  117. package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
  118. package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
  119. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
  120. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
  121. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
  122. package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
  123. package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
  124. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
  125. package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
  126. package/assets/templates/pages/documentation/template.doc.mjs +10 -1
  127. package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
  128. package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
  129. package/assets/templates/pages/editor/template.doc.mjs +9 -1
  130. package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
  131. package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
  132. package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
  133. package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
  134. package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
  135. package/assets/templates/pages/ide/template.doc.mjs +9 -1
  136. package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
  137. package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
  138. package/assets/templates/pages/library/template.doc.mjs +15 -1
  139. package/assets/templates/pages/login/template.doc.mjs +10 -1
  140. package/assets/templates/pages/login-card/template.doc.mjs +11 -1
  141. package/assets/templates/pages/login-split/template.doc.mjs +10 -1
  142. package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
  143. package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
  144. package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
  145. package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
  146. package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
  147. package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
  148. package/assets/templates/pages/settings/template.doc.mjs +3 -1
  149. package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
  150. package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
  151. package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
  152. package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
  153. package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
  154. package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
  155. package/assets/templates/pages/table/template.doc.mjs +11 -1
  156. package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
  157. package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
  158. package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
  159. package/assets/templates/pages/table-page/template.doc.mjs +20 -1
  160. package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
  161. package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
  162. package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
  163. package/assets/templates/themes/butter/icons.tsx +2 -0
  164. package/assets/templates/themes/chocolate/icons.tsx +2 -0
  165. package/assets/templates/themes/gothic/icons.tsx +2 -0
  166. package/assets/templates/themes/matcha/icons.tsx +2 -0
  167. package/assets/templates/themes/neutral/icons.tsx +2 -0
  168. package/assets/templates/themes/stone/icons.tsx +2 -0
  169. package/assets/templates/themes/y2k/icons.tsx +2 -0
  170. package/authoring/doctypes/template/parse.d.mts +2 -0
  171. package/authoring/doctypes/template/parse.mjs +1 -0
  172. package/authoring/doctypes/template/parse.test.mjs +21 -0
  173. package/authoring/doctypes/template/template.doc.mjs +6 -0
  174. package/authoring/doctypes/template/type.ts +10 -0
  175. package/clients/cli/commands/build-theme.mjs +8 -2
  176. package/clients/cli/commands/discover.mjs +29 -1
  177. package/clients/cli/commands/discover.no-source.test.mjs +75 -0
  178. package/clients/cli/commands/docs.depth.test.mjs +219 -0
  179. package/clients/cli/commands/docs.doc.mjs +15 -2
  180. package/clients/cli/commands/docs.mjs +222 -5
  181. package/clients/cli/commands/docs.test.mjs +383 -0
  182. package/clients/cli/commands/doctor.mjs +4 -4
  183. package/clients/cli/commands/gap-report.mjs +12 -0
  184. package/clients/cli/commands/gap-report.test.mjs +63 -0
  185. package/clients/cli/commands/integration-add.doc.mjs +10 -0
  186. package/clients/cli/commands/integration-authoring.test.mjs +12 -2
  187. package/clients/cli/commands/integration.mjs +3 -1
  188. package/clients/cli/commands/layout-expand.doc.mjs +3 -1
  189. package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
  190. package/clients/cli/commands/layout.mjs +16 -0
  191. package/clients/cli/commands/search.doc.mjs +5 -4
  192. package/clients/cli/commands/search.mjs +30 -6
  193. package/clients/cli/commands/search.test.mjs +60 -16
  194. package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
  195. package/clients/cli/commands/template.mjs +19 -5
  196. package/clients/cli/commands/template.show-media.test.mjs +62 -0
  197. package/clients/cli/commands/theme-list.behavior.test.mjs +41 -0
  198. package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
  199. package/clients/cli/commands/write-failure.test.mjs +175 -0
  200. package/clients/cli/lib/manifest.mjs +44 -165
  201. package/clients/cli/lib/manifest.test.mjs +98 -7
  202. package/foundation/agent-docs/agent-docs.mjs +2 -1
  203. package/foundation/agent-docs/agent-docs.test.mjs +1168 -0
  204. package/foundation/discovery/template-adapter.d.mts +14 -0
  205. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
  206. package/foundation/discovery/template-adapter.mjs +21 -1
  207. package/foundation/discovery/theme-discovery.d.mts +6 -0
  208. package/foundation/discovery/theme-discovery.mjs +9 -0
  209. package/foundation/doc-compiler/doc-loads.test.mjs +3 -3
  210. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  211. package/foundation/doc-compiler/tree.test.mjs +649 -0
  212. package/foundation/integrations/cli-requirement.d.mts +57 -13
  213. package/foundation/integrations/cli-requirement.mjs +84 -22
  214. package/foundation/integrations/cli-requirement.test.mjs +135 -8
  215. package/foundation/response/response-types.doc.d.mts +5 -5
  216. package/foundation/response/response-types.doc.mjs +13 -13
  217. package/package.json +1 -1
@@ -120,6 +120,20 @@ async function readExpression(expr, options = {}) {
120
120
  return expr ?? '';
121
121
  }
122
122
 
123
+ /**
124
+ * The disclosure for demo media replaced in spliced template blocks, or '' when
125
+ * none was. After printed code it is a line comment, so piped output stays TSX.
126
+ * @param {LayoutExpandResponse['data']} data
127
+ * @returns {string}
128
+ */
129
+ function demoMediaNotice({demoMediaReplaced, written}) {
130
+ if (demoMediaReplaced === 0) return '';
131
+ const notice =
132
+ `Replaced ${demoMediaReplaced} Astryx demo media reference${demoMediaReplaced === 1 ? '' : 's'} in ${written ?? 'the code above'}: ` +
133
+ 'images now show a neutral placeholder and videos have an empty source. Supply your own media there.';
134
+ return written ? notice : `// ${notice}`;
135
+ }
136
+
123
137
  /**
124
138
  * @param {import('commander').Command} program
125
139
  */
@@ -181,6 +195,8 @@ export function registerLayout(program) {
181
195
  // Raw expanded TSX (no target path) — preformatted, emitted verbatim.
182
196
  out.push(code(result.data.code));
183
197
  }
198
+ const mediaNotice = demoMediaNotice(result.data);
199
+ if (mediaNotice) out.push(text(mediaNotice));
184
200
  emit(...out);
185
201
  return NO_RESULT_SET;
186
202
  },
@@ -13,11 +13,11 @@ export const doc = {
13
13
  name: 'search',
14
14
  displayName: 'astryx search',
15
15
  namespace: 'cli/commands',
16
- summary: 'Search components, hooks, docs, and templates in one ranked list',
16
+ summary: 'Search components, hooks, docs, templates, and themes in one ranked list',
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 the docs.',
20
+ 'Outside an app, where @astryxdesign/core is not installed, it searches the docs and themes.',
21
21
  fn: 'search',
22
22
  // Every word after `search` is the query: `astryx search dark mode` searches
23
23
  // for "dark mode", with no quotes needed.
@@ -26,8 +26,8 @@ export const doc = {
26
26
  {
27
27
  flag: '--type <domain>',
28
28
  param: 'options.type',
29
- choices: ['component', 'hook', 'doc', 'template'],
30
- description: 'Filter to one domain (component|hook|doc|template)',
29
+ choices: ['component', 'hook', 'doc', 'template', 'theme'],
30
+ description: 'Filter to one domain (component|hook|doc|template|theme)',
31
31
  },
32
32
  {
33
33
  flag: '--limit <n>',
@@ -49,6 +49,7 @@ export const doc = {
49
49
  label: 'Filter + JSON',
50
50
  cli: 'astryx search "data table" --type template --json',
51
51
  },
52
+ {label: 'Themes you can add', cli: 'astryx search warm --type theme'},
52
53
  ],
53
54
  exitCodes: [
54
55
  {code: 0, when: 'success (including zero matches)'},
@@ -4,9 +4,9 @@
4
4
  * @file search command — unified ranked search with a stable result summary.
5
5
  *
6
6
  * One "I'm looking for X" entry point spanning components, hooks, docs topics,
7
- * and templates (page + block). Results are ranked by relevance and tagged
8
- * with their domain, with a follow-up command so the user knows what to run
9
- * next.
7
+ * templates (page + block), and themes. Results are ranked by relevance and
8
+ * tagged with their domain, with a follow-up command so the user knows what to
9
+ * run next.
10
10
  *
11
11
  * The command surface (description, args, flags) is sourced from the colocated
12
12
  * `search.doc.mjs` CommandDoc via `defineCommand`; this file supplies only the
@@ -104,13 +104,13 @@ export function registerSearch(program) {
104
104
  // ── Text output ──────────────────────────────────────────────
105
105
  const run = getCliInvocation();
106
106
  const {query: q, matchCount, results} = result.data;
107
- // Outside an app an open search covers the docs alone. Say so, so a
108
- // docs-only list does not read as "Astryx has no such component".
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
109
  const note =
110
110
  !options.type && !findCoreDir(process.cwd())
111
111
  ? [
112
112
  text(
113
- '@astryxdesign/core is not installed here, so only the docs were searched.',
113
+ '@astryxdesign/core is not installed here, so only the docs and themes were searched.',
114
114
  ),
115
115
  ]
116
116
  : [];
@@ -123,6 +123,7 @@ export function registerSearch(program) {
123
123
  text(
124
124
  `Try a broader term, or browse: ${run} ${note.length > 0 ? 'docs' : 'component --list'}`,
125
125
  ),
126
+ ...discoverHint(run, q, options.type),
126
127
  );
127
128
  return answered;
128
129
  }
@@ -174,11 +175,34 @@ export function registerSearch(program) {
174
175
  format: {command: formatCliCommand, parent: formatCliCommand},
175
176
  }),
176
177
  ...note,
178
+ ...discoverHint(run, q, options.type),
177
179
  );
178
180
  return answered;
179
181
  },
180
182
  });
181
183
  }
182
184
 
185
+ /**
186
+ * Search reads only what is installed. Point at `discover` for the packages
187
+ * that could add more, except for hooks, which no integration adds.
188
+ * @param {string} run - The caller's CLI invocation prefix.
189
+ * @param {string} query
190
+ * @param {string | undefined} type
191
+ */
192
+ function discoverHint(run, query, type) {
193
+ if (type === 'hook') return [];
194
+ return [
195
+ text(`More in packages you could add: ${run} discover ${shellWord(query)}`),
196
+ ];
197
+ }
198
+
199
+ /**
200
+ * One shell word: the value itself when it is plain, else single-quoted.
201
+ * @param {string} value
202
+ */
203
+ function shellWord(value) {
204
+ return /^[\w@./:-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
205
+ }
206
+
183
207
  // Re-export the API for external consumers.
184
208
  export {search, SEARCH_DOMAINS} from '../../../api/search/search.mjs';
@@ -118,6 +118,15 @@ describe('search() API — filters', () => {
118
118
  }
119
119
  });
120
120
 
121
+ it('--type theme returns only themes, each with the command that adds it', async () => {
122
+ const {data} = await search('warm', {...OPTS, type: 'theme'});
123
+ expect(data.results.map(r => r.name)).toContain('neutral');
124
+ for (const r of data.results) {
125
+ expect(r.domain).toBe('theme');
126
+ expect(r.command).toBe(`astryx theme add ${r.name}`);
127
+ }
128
+ });
129
+
121
130
  it('respects --limit', async () => {
122
131
  const {data} = await search('button', {...OPTS, limit: 3});
123
132
  expect(data.results.length).toBeLessThanOrEqual(3);
@@ -279,22 +288,31 @@ describe('search CLI — exit codes + JSON contract', () => {
279
288
  });
280
289
 
281
290
  it('prints every result field under its JSON key (score and reason with --verbose)', async () => {
282
- // One query that reaches all four domains, so every per-domain field shows.
283
- const args = ['search', 'theme', '--limit', '60'];
284
- const env = JSON.parse((await runCli(['--json', ...args], REPO_ROOT)).stdout);
285
- expect(new Set(env.data.results.map(r => r.domain))).toEqual(new Set(SEARCH_DOMAINS));
286
- const plain = (await runCli(args, REPO_ROOT)).stdout.split('\n');
287
- const verbose = (await runCli([...args, '--verbose'], REPO_ROOT)).stdout.split('\n');
288
- for (const result of env.data.results) {
289
- for (const [key, value] of Object.entries(result)) {
290
- if (value == null || value === '') continue;
291
- const label = `${result.domain} ${result.name}: ${key}`;
292
- expect(printsField(verbose, key, value), label).toBe(true);
293
- if (key !== 'score' && key !== 'reason') {
294
- 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
+ }
295
312
  }
296
313
  }
297
314
  }
315
+ expect(domains).toEqual(new Set(SEARCH_DOMAINS));
298
316
  }, 90_000);
299
317
 
300
318
  it('--verbose exits 0 and prints import/match detail', async () => {
@@ -311,16 +329,42 @@ describe('search CLI — exit codes + JSON contract', () => {
311
329
  expect(r.stdout).toContain('reason:');
312
330
  });
313
331
 
314
- it('searches the docs when no @astryxdesign/core is reachable, and exits 1 for --type component', async () => {
332
+ it('points at discover for packages that could add more, except for hooks', async () => {
333
+ const open = await runCli(['search', 'data', 'table'], REPO_ROOT);
334
+ expect(open.status).toBe(0);
335
+ expect(open.stdout).toMatch(/^More in packages you could add: .*discover 'data table'$/m);
336
+ const none = await runCli(['search', 'zzqqxxnomatch'], REPO_ROOT);
337
+ expect(none.stdout).toMatch(/^More in packages you could add: .*discover zzqqxxnomatch$/m);
338
+ const hooks = await runCli(['search', 'click', '--type', 'hook'], REPO_ROOT);
339
+ expect(hooks.status).toBe(0);
340
+ expect(hooks.stdout).not.toContain('More in packages you could add');
341
+ const json = await runCli(['--json', 'search', 'button'], REPO_ROOT);
342
+ expect(json.stdout).not.toContain('More in packages you could add');
343
+ });
344
+
345
+ it('searches the docs and themes when no @astryxdesign/core is reachable, and exits 1 for --type component', async () => {
315
346
  const empty = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-search-cli-no-core-'));
316
347
  try {
317
348
  const open = await runCli(['--json', 'search', 'make', 'an', 'integration'], empty);
318
349
  expect(open.status).toBe(0);
319
350
  expect(JSON.parse(open.stdout).data.results[0]).toMatchObject({domain: 'doc'});
320
- // The text says the search covered the docs alone.
351
+ // Bundled themes need no project, so an open search finds them too.
352
+ const theme = await runCli(['--json', 'search', 'neutral'], empty);
353
+ expect(theme.status).toBe(0);
354
+ expect(JSON.parse(theme.stdout).data.results[0]).toMatchObject({
355
+ domain: 'theme',
356
+ name: 'neutral',
357
+ });
358
+ // The text says the search covered the docs and themes alone.
321
359
  const text = await runCli(['search', 'button'], empty);
322
360
  expect(text.status).toBe(0);
323
- expect(text.stdout).toContain('only the docs were searched');
361
+ expect(text.stdout).toContain('only the docs and themes were searched');
362
+ // A themes-only search needs no core, like a docs-only one.
363
+ const themes = await runCli(['--json', 'search', 'warm', '--type', 'theme'], empty);
364
+ expect(themes.status).toBe(0);
365
+ const found = JSON.parse(themes.stdout).data.results;
366
+ expect(found.map(r => r.name)).toContain('neutral');
367
+ expect(found.every(r => r.domain === 'theme')).toBe(true);
324
368
  const json = await runCli(['--json', 'search', 'button', '--type', 'component'], empty);
325
369
  expect(json.status).toBe(1);
326
370
  expect(JSON.parse(json.stdout)).toMatchObject({code: 'ERR_CORE_NOT_FOUND'});
@@ -0,0 +1,60 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx template <name> <path>` tells the caller, in JSON and in text,
5
+ * when demo media in the copied file was replaced with placeholders.
6
+ */
7
+
8
+ import {describe, it, expect, beforeEach, afterEach} from 'vitest';
9
+ import * as fs from 'node:fs';
10
+ import * as os from 'node:os';
11
+ import * as path from 'node:path';
12
+ import {runCli} from '../../../test-utils/run-cli.mjs';
13
+ import {discoverTemplates} from '../../../api/template/template.mjs';
14
+
15
+ const SLOW = 60_000;
16
+
17
+ /** A page template whose source carries demo media, and one that carries none. */
18
+ async function pickPages() {
19
+ const pages = /** @type {Array<{dirName: string, type: string, filePath: string}>} */ (
20
+ await discoverTemplates()
21
+ ).filter(t => t.type === 'page' && fs.existsSync(t.filePath));
22
+ const hasMedia = (/** @type {{filePath: string}} */ t) =>
23
+ /\/template-assets\/[\w.-]+\.\w+/.test(fs.readFileSync(t.filePath, 'utf-8'));
24
+ const withMedia = pages.find(hasMedia);
25
+ const without = pages.find(t => !hasMedia(t));
26
+ if (!withMedia || !without) throw new Error('catalog lacks a page with and without demo media');
27
+ return {withMedia: withMedia.dirName, without: without.dirName};
28
+ }
29
+
30
+ describe('template copy receipt discloses replaced demo media', () => {
31
+ let dir;
32
+ beforeEach(() => {
33
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-receipt-cli-'));
34
+ });
35
+ afterEach(() => fs.rmSync(dir, {recursive: true, force: true}));
36
+
37
+ it('--json carries demoMediaReplaced and the text states the same count', async () => {
38
+ const {withMedia} = await pickPages();
39
+ const json = await runCli(['template', withMedia, './a', '--json'], dir);
40
+ expect(json.status).toBe(0);
41
+ const {data} = JSON.parse(json.stdout);
42
+ expect(data.demoMediaReplaced).toBeGreaterThan(0);
43
+
44
+ const human = await runCli(['template', withMedia, './b'], dir);
45
+ expect(human.status).toBe(0);
46
+ expect(human.stdout).toContain(
47
+ `Replaced ${data.demoMediaReplaced} Astryx demo media reference`,
48
+ );
49
+ expect(human.stdout).toContain('b/page.tsx');
50
+ }, SLOW);
51
+
52
+ it('says nothing about media when none was replaced', async () => {
53
+ const {without} = await pickPages();
54
+ const json = await runCli(['template', without, './a', '--json'], dir);
55
+ expect(JSON.parse(json.stdout).data.demoMediaReplaced).toBe(0);
56
+ const human = await runCli(['template', without, './b'], dir);
57
+ expect(human.status).toBe(0);
58
+ expect(human.stdout).not.toMatch(/demo media/i);
59
+ }, SLOW);
60
+ });
@@ -156,16 +156,30 @@ export function registerTemplate(program) {
156
156
  }
157
157
 
158
158
  case 'template.show': {
159
- // Source must survive piping byte-for-byte.
160
- emit(code(result.data.source));
159
+ // Source must survive piping byte-for-byte, so the note about
160
+ // replaced demo media goes to stderr, in the copy receipt's words.
161
+ // (Text mode only: --json returned above with the count in data.)
162
+ const {source, demoMediaReplaced} = result.data;
163
+ emit(code(source));
164
+ if (demoMediaReplaced > 0) {
165
+ console.error(
166
+ `Replaced ${demoMediaReplaced} Astryx demo media reference${demoMediaReplaced === 1 ? '' : 's'}: ` +
167
+ 'images now show a neutral placeholder and videos have an empty source. Supply your own media there.',
168
+ );
169
+ }
161
170
  break;
162
171
  }
163
172
 
164
173
  case 'template.copy': {
174
+ const {outputDir, fileName, demoMediaReplaced} = result.data;
175
+ const file = `${outputDir}/${fileName}`;
165
176
  emit(
166
- text(
167
- `Copied template to ${result.data.outputDir}/${result.data.fileName}`,
168
- ),
177
+ text(`Copied template to ${file}`),
178
+ demoMediaReplaced > 0 &&
179
+ text(
180
+ `Replaced ${demoMediaReplaced} Astryx demo media reference${demoMediaReplaced === 1 ? '' : 's'} in ${file}: ` +
181
+ 'images now show a neutral placeholder and videos have an empty source. Supply your own media there.',
182
+ ),
169
183
  );
170
184
  break;
171
185
  }
@@ -0,0 +1,62 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx template <name>` says how many demo media references it
5
+ * replaced: in `--json` as `demoMediaReplaced`, and in text on stderr, so that
6
+ * stdout stays exactly the source a copy writes and can be piped into a file.
7
+ */
8
+
9
+ import {describe, it, expect, beforeAll, afterAll} from 'vitest';
10
+ import * as fs from 'node:fs';
11
+ import * as os from 'node:os';
12
+ import * as path from 'node:path';
13
+ import {runCli} from '../../../test-utils/run-cli.mjs';
14
+ import {discoverTemplates} from '../../../api/template/template.mjs';
15
+
16
+ const SLOW = 60_000;
17
+
18
+ /** A page template whose source carries demo media, and one that carries none. */
19
+ async function pickPages() {
20
+ const pages = /** @type {Array<{dirName: string, type: string, filePath: string}>} */ (
21
+ await discoverTemplates()
22
+ ).filter(t => t.type === 'page' && fs.existsSync(t.filePath));
23
+ const hasMedia = (/** @type {{filePath: string}} */ t) =>
24
+ /\/template-assets\/[\w.-]+\.\w+/.test(fs.readFileSync(t.filePath, 'utf-8'));
25
+ const withMedia = pages.find(hasMedia);
26
+ const without = pages.find(t => !hasMedia(t));
27
+ if (!withMedia || !without) throw new Error('catalog lacks a page with and without demo media');
28
+ return {withMedia: withMedia.dirName, without: without.dirName};
29
+ }
30
+
31
+ describe('template show discloses replaced demo media', () => {
32
+ /** @type {string} */
33
+ let dir;
34
+ beforeAll(() => {
35
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-show-cli-'));
36
+ });
37
+ afterAll(() => fs.rmSync(dir, {recursive: true, force: true}));
38
+
39
+ it('--json carries demoMediaReplaced, and text states it on stderr with stdout left as the source', async () => {
40
+ const {withMedia} = await pickPages();
41
+ const json = await runCli(['template', withMedia, '--type', 'page', '--json'], dir);
42
+ expect(json.status).toBe(0);
43
+ const {data} = JSON.parse(json.stdout);
44
+ expect(data.demoMediaReplaced).toBeGreaterThan(0);
45
+
46
+ const human = await runCli(['template', withMedia, '--type', 'page'], dir);
47
+ expect(human.status).toBe(0);
48
+ expect(human.stdout.trimEnd()).toBe(data.source.trimEnd());
49
+ expect(human.stderr).toContain(
50
+ `Replaced ${data.demoMediaReplaced} Astryx demo media reference`,
51
+ );
52
+ }, SLOW);
53
+
54
+ it('says nothing about media when none was replaced', async () => {
55
+ const {without} = await pickPages();
56
+ const json = await runCli(['template', without, '--type', 'page', '--json'], dir);
57
+ expect(JSON.parse(json.stdout).data.demoMediaReplaced).toBe(0);
58
+ const human = await runCli(['template', without, '--type', 'page'], dir);
59
+ expect(human.status).toBe(0);
60
+ expect(human.stderr).not.toMatch(/demo media/i);
61
+ }, SLOW);
62
+ });
@@ -0,0 +1,41 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file CLI behavior for `astryx theme list`.
5
+ *
6
+ * `theme list` shows the themes this project can add now. Themes in packages
7
+ * it has not installed are `discover`'s, so the list ends by pointing there:
8
+ * an agent that never learns `discover` exists searches the registry instead.
9
+ */
10
+
11
+ import {describe, it, expect, beforeEach, afterEach} from 'vitest';
12
+ import * as fs from 'node:fs';
13
+ import * as path from 'node:path';
14
+ import * as os from 'node:os';
15
+ import {runCli} from '../../../test-utils/run-cli.mjs';
16
+
17
+ let tmpDir;
18
+ beforeEach(() => {
19
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-cli-theme-list-'));
20
+ });
21
+ afterEach(() => {
22
+ fs.rmSync(tmpDir, {recursive: true, force: true});
23
+ });
24
+
25
+ describe('astryx theme list', () => {
26
+ it('lists the bundled themes and points at discover for more', async () => {
27
+ const {status, stdout} = await runCli(['theme', 'list'], {cwd: tmpDir});
28
+
29
+ expect(status).toBe(0);
30
+ expect(stdout).toMatch(/^- neutral \(maintained, @astryxdesign\/cli\)/m);
31
+ expect(stdout).toMatch(/More themes in packages you could add: .*discover theme$/m);
32
+ });
33
+
34
+ it('keeps the JSON envelope free of the hint', async () => {
35
+ const {status, stdout} = await runCli(['--json', 'theme', 'list'], {cwd: tmpDir});
36
+
37
+ expect(status).toBe(0);
38
+ expect(stdout).not.toContain('discover');
39
+ expect(JSON.parse(stdout).type).toBe('theme.list');
40
+ });
41
+ });
@@ -84,4 +84,18 @@ describe('upgrade human output is ASCII', () => {
84
84
  'minSize: 200',
85
85
  );
86
86
  });
87
+
88
+ // Every fixture above has a real src/, so the completion line for a project
89
+ // whose source is somewhere else was never reached — this suite was green on
90
+ // that path by luck, not by coverage.
91
+ it('reports a source directory that does not exist', async () => {
92
+ fs.rmSync(path.join(tmpDir, 'src'), {recursive: true, force: true});
93
+ fs.mkdirSync(path.join(tmpDir, 'app'), {recursive: true});
94
+ write('app/panel.tsx', 'export const x = 1;\n');
95
+
96
+ expect(await nonAsciiLines(['upgrade', '--from', '0.5.0'])).toEqual([]);
97
+ expect(
98
+ await nonAsciiLines(['upgrade', '--from', '0.5.0', '--apply']),
99
+ ).toEqual([]);
100
+ });
87
101
  });
@@ -0,0 +1,175 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file A write that fails on the filesystem reports ERR_WRITE_FAILED.
5
+ *
6
+ * An unwritable target produced `{"error": "EACCES: permission denied, open
7
+ * '/abs/host/path/readonly/x.tsx'", "code": "ERR_UNKNOWN"}` — the raw Node
8
+ * errno error, with the wrong code and an absolute host path in the message.
9
+ * ERR_WRITE_FAILED is in the frozen registry for exactly this case, and every
10
+ * other Astryx message names its target relative to the project.
11
+ */
12
+
13
+ import {describe, it, expect, beforeEach, afterEach} from 'vitest';
14
+ import * as fs from 'node:fs';
15
+ import * as os from 'node:os';
16
+ import * as path from 'node:path';
17
+ import {fileURLToPath} from 'node:url';
18
+ import {runCli} from '../../../test-utils/run-cli.mjs';
19
+
20
+ const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../..');
21
+
22
+ // chmod means nothing to root, so the unwritable directory would be writable
23
+ // and the command would succeed. Skip rather than assert something false.
24
+ const asRoot = typeof process.getuid === 'function' && process.getuid() === 0;
25
+
26
+ let dir;
27
+ let readonlyDir;
28
+
29
+ beforeEach(() => {
30
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-write-fail-'));
31
+ fs.writeFileSync(
32
+ path.join(dir, 'package.json'),
33
+ JSON.stringify({
34
+ name: 'scratch',
35
+ version: '1.0.0',
36
+ dependencies: {'@astryxdesign/core': '0.6.3'},
37
+ }),
38
+ );
39
+ fs.mkdirSync(path.join(dir, 'node_modules', '@astryxdesign'), {recursive: true});
40
+ fs.symlinkSync(
41
+ path.join(REPO, 'packages', 'core'),
42
+ path.join(dir, 'node_modules', '@astryxdesign', 'core'),
43
+ 'dir',
44
+ );
45
+ readonlyDir = path.join(dir, 'readonly');
46
+ fs.mkdirSync(readonlyDir);
47
+ fs.chmodSync(readonlyDir, 0o500);
48
+ });
49
+
50
+ afterEach(() => {
51
+ try {
52
+ fs.chmodSync(readonlyDir, 0o700);
53
+ } catch {
54
+ // already gone
55
+ }
56
+ fs.rmSync(dir, {recursive: true, force: true});
57
+ });
58
+
59
+ /** @param {string[]} args */
60
+ const json = async args => {
61
+ const {status, stdout} = await runCli(['--json', ...args], {cwd: dir});
62
+ return {status, body: JSON.parse(stdout)};
63
+ };
64
+
65
+ describe.skipIf(asRoot)('a failed write reports ERR_WRITE_FAILED', () => {
66
+ it('template into an unwritable directory', async () => {
67
+ const {status, body} = await json(['template', 'ai-chat', 'readonly/x.tsx']);
68
+
69
+ expect(status).toBe(1);
70
+ expect(body.code).toBe('ERR_WRITE_FAILED');
71
+ expect(body.error).toContain('readonly/x.tsx');
72
+ expect(body.error).toContain('EACCES');
73
+ // The whole point of the relative form: no absolute host path escapes.
74
+ expect(body.error).not.toContain(dir);
75
+ expect(fs.existsSync(path.join(readonlyDir, 'x.tsx'))).toBe(false);
76
+ });
77
+
78
+ it('swizzle into an unwritable directory', async () => {
79
+ const {status, body} = await json([
80
+ 'swizzle',
81
+ 'Button',
82
+ '--output',
83
+ 'readonly/sub',
84
+ ]);
85
+
86
+ expect(status).toBe(1);
87
+ expect(body.code).toBe('ERR_WRITE_FAILED');
88
+ expect(body.error).toContain('readonly/sub');
89
+ expect(body.error).not.toContain(dir);
90
+ expect(fs.existsSync(path.join(readonlyDir, 'sub'))).toBe(false);
91
+ });
92
+
93
+ it('still writes normally into a writable directory', async () => {
94
+ const {status, body} = await json(['template', 'ai-chat', 'src/page.tsx']);
95
+
96
+ expect(status, JSON.stringify(body).slice(0, 200)).toBe(0);
97
+ expect(body.type).toBe('template.copy');
98
+ expect(fs.existsSync(path.join(dir, 'src', 'page.tsx'))).toBe(true);
99
+ });
100
+ });
101
+
102
+ describe.skipIf(asRoot)('a swizzle that fails part-way undoes what it wrote', () => {
103
+ it('restores replaced files, removes created ones, and says nothing was written', async () => {
104
+ // Learn the component's files, in copy order, from a successful swizzle.
105
+ const probe = await json(['swizzle', 'Button', '--output', 'probe']);
106
+ expect(probe.status, JSON.stringify(probe.body).slice(0, 200)).toBe(0);
107
+ const files = probe.body.data.files;
108
+ expect(files.length).toBeGreaterThan(1);
109
+ const outDir = path.join(dir, 'out', path.basename(probe.body.data.outputDir));
110
+
111
+ // The first file exists (replaceable), the middle ones do not, and the
112
+ // last one is read-only, so --overwrite fails after writing the others.
113
+ const first = files[0];
114
+ const middle = files.slice(1, -1);
115
+ const last = files[files.length - 1];
116
+ fs.mkdirSync(outDir, {recursive: true});
117
+ fs.writeFileSync(path.join(outDir, first), 'before first\n');
118
+ fs.writeFileSync(path.join(outDir, last), 'before last\n');
119
+ fs.chmodSync(path.join(outDir, last), 0o444);
120
+
121
+ const {status, body} = await json([
122
+ 'swizzle',
123
+ 'Button',
124
+ '--output',
125
+ 'out',
126
+ '--overwrite',
127
+ ]);
128
+ fs.chmodSync(path.join(outDir, last), 0o644);
129
+
130
+ expect(status).toBe(1);
131
+ expect(body.code).toBe('ERR_WRITE_FAILED');
132
+ expect(body.error).toContain(last);
133
+ expect(body.error).toContain('Nothing was written.');
134
+ expect(body.error).not.toContain(dir);
135
+ expect(fs.readFileSync(path.join(outDir, first), 'utf8')).toBe('before first\n');
136
+ expect(fs.readFileSync(path.join(outDir, last), 'utf8')).toBe('before last\n');
137
+ for (const file of middle) {
138
+ expect(fs.existsSync(path.join(outDir, file))).toBe(false);
139
+ }
140
+ });
141
+
142
+ it('undoes the copy when a destination cannot be read back', async () => {
143
+ const probe = await json(['swizzle', 'Button', '--output', 'probe']);
144
+ expect(probe.status, JSON.stringify(probe.body).slice(0, 200)).toBe(0);
145
+ const files = probe.body.data.files;
146
+ const outDir = path.join(dir, 'out', path.basename(probe.body.data.outputDir));
147
+
148
+ // A directory where the last file goes: the rollback snapshot cannot read
149
+ // it, and the earlier files are already written when the copy reaches it.
150
+ const first = files[0];
151
+ const middle = files.slice(1, -1);
152
+ const last = files[files.length - 1];
153
+ fs.mkdirSync(path.join(outDir, last), {recursive: true});
154
+ fs.writeFileSync(path.join(outDir, first), 'before first\n');
155
+
156
+ const {status, body} = await json([
157
+ 'swizzle',
158
+ 'Button',
159
+ '--output',
160
+ 'out',
161
+ '--overwrite',
162
+ ]);
163
+
164
+ expect(status).toBe(1);
165
+ expect(body.code).toBe('ERR_WRITE_FAILED');
166
+ expect(body.error).toContain(last);
167
+ expect(body.error).toContain('Nothing was written.');
168
+ expect(body.error).not.toContain(dir);
169
+ expect(fs.readFileSync(path.join(outDir, first), 'utf8')).toBe('before first\n');
170
+ expect(fs.statSync(path.join(outDir, last)).isDirectory()).toBe(true);
171
+ for (const file of middle) {
172
+ expect(fs.existsSync(path.join(outDir, file))).toBe(false);
173
+ }
174
+ });
175
+ });