@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
@@ -1,8 +1,10 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  import {afterEach, beforeEach, describe, expect, it} from 'vitest';
4
+ import {execFileSync} from 'node:child_process';
4
5
  import * as fs from 'node:fs';
5
6
  import * as path from 'node:path';
7
+ import {CLI_ROOT, findInstalledPackage} from '../../foundation/fs/paths.mjs';
6
8
  import {integrationAddTheme} from './add-theme.mjs';
7
9
  import {validateLocalIntegration} from './validate-integration.mjs';
8
10
 
@@ -84,7 +86,7 @@ describe('integrationAddTheme', () => {
84
86
  const pkg = JSON.parse(
85
87
  fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
86
88
  );
87
- expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.7.0'});
89
+ expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
88
90
  expect(pkg.peerDependenciesMeta).toEqual({
89
91
  '@astryxdesign/cli': {optional: true},
90
92
  });
@@ -310,3 +312,314 @@ describe('integrationAddTheme', () => {
310
312
  );
311
313
  });
312
314
  });
315
+
316
+ describe('integrationAddTheme --from', () => {
317
+ it('forks a bundled theme into the integration package', async () => {
318
+ setup();
319
+ const result = await integrationAddTheme('ocean', {
320
+ cwd: tmpDir,
321
+ from: 'neutral',
322
+ });
323
+
324
+ expect(result.type).toBe('integration.add');
325
+ expect(result.data.kind).toBe('theme');
326
+ expect(result.data.name).toBe('ocean');
327
+ expect(result.data.from).toBe('neutral');
328
+ expect(result.data.written).toBe(true);
329
+ expect(result.data.dryRun).toBe(false);
330
+ expect(result.data.root).toEqual({path: './themes', created: true});
331
+
332
+ // The entry file must exist with the new export name.
333
+ const entry = fs.readFileSync(
334
+ path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
335
+ 'utf-8',
336
+ );
337
+ expect(entry).toContain('oceanTheme');
338
+ expect(entry).toContain("name: 'ocean'");
339
+ // It must NOT contain the original theme identifier as a prefix.
340
+ expect(entry).not.toMatch(/\bneutralTheme\b/);
341
+ expect(entry).not.toMatch(/\bneutralPalettes\b/);
342
+ expect(entry).not.toMatch(/\bneutralSyntax\b/);
343
+ expect(entry).toContain('defineTheme');
344
+
345
+ // A fresh descriptor, not copied from the base.
346
+ const descriptor = fs.readFileSync(
347
+ path.join(tmpDir, 'themes/ocean/oceanTheme.doc.mjs'),
348
+ 'utf-8',
349
+ );
350
+ expect(descriptor).toContain("name: 'ocean'");
351
+ expect(descriptor).toContain("@astryxdesign/cli/authoring').ThemeDoc");
352
+ expect(descriptor).toContain('maintained: true');
353
+
354
+ // The theme must validate.
355
+ expect((await validateLocalIntegration(tmpDir)).issues).toEqual([]);
356
+ });
357
+
358
+ it('renames palette and support files from the base theme', async () => {
359
+ setup();
360
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
361
+
362
+ const themeDir = path.join(tmpDir, 'themes/ocean');
363
+ const files = fs.readdirSync(themeDir).sort();
364
+ // neutralPalettes.ts → oceanPalettes.ts, etc.
365
+ expect(files).toContain('oceanTheme.ts');
366
+ expect(files).toContain('oceanTheme.doc.mjs');
367
+ expect(files).toContain('oceanPalettes.ts');
368
+ expect(files).toContain('oceanPaletteRefs.generated.ts');
369
+ expect(files).toContain('icons.tsx');
370
+ // Must not contain any file starting with 'neutral'.
371
+ expect(files.filter(f => f.startsWith('neutral'))).toEqual([]);
372
+ });
373
+
374
+ it('rewrites import paths inside forked files', async () => {
375
+ setup();
376
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
377
+
378
+ const entry = fs.readFileSync(
379
+ path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
380
+ 'utf-8',
381
+ );
382
+ // Import references must use the new identifier.
383
+ expect(entry).toContain('./oceanPaletteRefs.generated');
384
+ expect(entry).not.toContain('./neutralPaletteRefs.generated');
385
+ // The icon registry import must also be renamed.
386
+ expect(entry).toContain('oceanIconRegistry');
387
+ expect(entry).not.toContain('neutralIconRegistry');
388
+ });
389
+
390
+ it('rewrites CSS custom properties scoped to the base theme', async () => {
391
+ setup();
392
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
393
+
394
+ const entry = fs.readFileSync(
395
+ path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
396
+ 'utf-8',
397
+ );
398
+ expect(entry).toContain('--astryx-theme-ocean-');
399
+ expect(entry).not.toContain('--astryx-theme-neutral-');
400
+ });
401
+
402
+ it('rewrites the syntax theme name', async () => {
403
+ setup();
404
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
405
+
406
+ const entry = fs.readFileSync(
407
+ path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
408
+ 'utf-8',
409
+ );
410
+ expect(entry).toContain("'astryx-ocean'");
411
+ expect(entry).not.toContain("'astryx-neutral'");
412
+ });
413
+
414
+ it('strips the copyright header from forked files', async () => {
415
+ setup();
416
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
417
+
418
+ const entry = fs.readFileSync(
419
+ path.join(tmpDir, 'themes/ocean/oceanTheme.ts'),
420
+ 'utf-8',
421
+ );
422
+ expect(entry).not.toContain('Copyright (c) Meta Platforms');
423
+ });
424
+
425
+ it('includes data.from in the receipt only when --from is used', async () => {
426
+ setup();
427
+ const blank = await integrationAddTheme('plain', {cwd: tmpDir});
428
+ expect(blank.data).not.toHaveProperty('from');
429
+
430
+ const forked = await integrationAddTheme('ocean', {
431
+ cwd: tmpDir,
432
+ from: 'neutral',
433
+ });
434
+ expect(forked.data.from).toBe('neutral');
435
+ });
436
+
437
+ it('refuses to fork a theme into itself', async () => {
438
+ setup();
439
+ await expect(
440
+ integrationAddTheme('neutral', {cwd: tmpDir, from: 'neutral'}),
441
+ ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
442
+ });
443
+
444
+ it('refuses an unknown base theme with a helpful suggestion list', async () => {
445
+ setup();
446
+ await expect(
447
+ integrationAddTheme('ocean', {cwd: tmpDir, from: 'nonexistent'}),
448
+ ).rejects.toMatchObject({
449
+ code: 'ERR_UNKNOWN_THEME',
450
+ message: expect.stringContaining('nonexistent'),
451
+ });
452
+ });
453
+
454
+ it('dry-runs with --from without writing anything', async () => {
455
+ setup();
456
+ const result = await integrationAddTheme('ocean', {
457
+ cwd: tmpDir,
458
+ from: 'neutral',
459
+ dryRun: true,
460
+ });
461
+
462
+ expect(result.data.written).toBe(false);
463
+ expect(result.data.dryRun).toBe(true);
464
+ expect(result.data.from).toBe('neutral');
465
+ expect(result.data.files).toContain('themes/ocean/oceanTheme.ts');
466
+ expect(result.data.files).toContain('themes/ocean/oceanTheme.doc.mjs');
467
+ expect(fs.existsSync(path.join(tmpDir, 'themes'))).toBe(false);
468
+ });
469
+
470
+ it('refuses to overwrite when the target already exists', async () => {
471
+ setup();
472
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
473
+ await expect(
474
+ integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'}),
475
+ ).rejects.toMatchObject({code: 'ERR_FILE_EXISTS'});
476
+ });
477
+
478
+ it('declares the npm packages the forked files import, at the range the bundled themes use', async () => {
479
+ setup({includeFiles: false});
480
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
481
+ const pkg = JSON.parse(
482
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
483
+ );
484
+ const cli = JSON.parse(
485
+ fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf-8'),
486
+ );
487
+ // The copied icons.tsx imports lucide-react; Core and React are every
488
+ // app's own, so the fork does not declare them.
489
+ expect(pkg.dependencies).toEqual({
490
+ 'lucide-react': cli.devDependencies['lucide-react'],
491
+ });
492
+ expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
493
+ });
494
+
495
+ it('keeps a dependency the package already declares', async () => {
496
+ setup({includeFiles: false});
497
+ const file = path.join(tmpDir, 'package.json');
498
+ const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'));
499
+ fs.writeFileSync(
500
+ file,
501
+ `${JSON.stringify({...pkg, dependencies: {'lucide-react': '^1.0.0'}}, null, 2)}\n`,
502
+ );
503
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
504
+ expect(JSON.parse(fs.readFileSync(file, 'utf-8')).dependencies).toEqual({
505
+ 'lucide-react': '^1.0.0',
506
+ });
507
+ });
508
+
509
+ it('declares nothing for a fork of a theme the package owns', async () => {
510
+ setup({includeFiles: false});
511
+ await integrationAddTheme('base', {cwd: tmpDir});
512
+ await integrationAddTheme('variant', {cwd: tmpDir, from: 'base'});
513
+ const pkg = JSON.parse(
514
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
515
+ );
516
+ expect(pkg.dependencies).toBeUndefined();
517
+ });
518
+
519
+ it('builds a forked neutral theme once the package installs what --from declared', async () => {
520
+ setup({includeFiles: false});
521
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
522
+ const pkg = JSON.parse(
523
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
524
+ );
525
+ // Install exactly what the package declares, plus what every Astryx
526
+ // project has: Core and React.
527
+ for (const name of [
528
+ ...Object.keys(pkg.dependencies ?? {}),
529
+ '@astryxdesign/core',
530
+ 'react',
531
+ ]) {
532
+ const installed = findInstalledPackage(CLI_ROOT, name);
533
+ expect(installed, name).not.toBeNull();
534
+ const link = path.join(tmpDir, 'node_modules', ...name.split('/'));
535
+ fs.mkdirSync(path.dirname(link), {recursive: true});
536
+ fs.symlinkSync(
537
+ fs.realpathSync(/** @type {string} */ (installed)),
538
+ link,
539
+ 'dir',
540
+ );
541
+ }
542
+ // A separate process without NODE_PATH, so only what the package
543
+ // installed can resolve.
544
+ let status = 0;
545
+ let output = '';
546
+ try {
547
+ execFileSync(
548
+ process.execPath,
549
+ [
550
+ path.join(CLI_ROOT, 'clients/cli/bin/astryx.mjs'),
551
+ 'theme',
552
+ 'build',
553
+ 'themes/ocean/oceanTheme.ts',
554
+ ],
555
+ {
556
+ cwd: tmpDir,
557
+ env: {...process.env, NODE_PATH: ''},
558
+ encoding: 'utf-8',
559
+ stdio: 'pipe',
560
+ },
561
+ );
562
+ } catch (error) {
563
+ const failure = /** @type {any} */ (error);
564
+ status = failure.status ?? 1;
565
+ output = `${failure.stdout ?? ''}${failure.stderr ?? ''}`;
566
+ }
567
+ expect({status, output: status === 0 ? '' : output}).toEqual({
568
+ status: 0,
569
+ output: '',
570
+ });
571
+ expect(fs.existsSync(path.join(tmpDir, 'themes/ocean/ocean.css'))).toBe(
572
+ true,
573
+ );
574
+ });
575
+
576
+ it('works with different bundled themes', async () => {
577
+ setup();
578
+ const result = await integrationAddTheme('dusk', {
579
+ cwd: tmpDir,
580
+ from: 'gothic',
581
+ });
582
+
583
+ expect(result.data.from).toBe('gothic');
584
+ const entry = fs.readFileSync(
585
+ path.join(tmpDir, 'themes/dusk/duskTheme.ts'),
586
+ 'utf-8',
587
+ );
588
+ expect(entry).toContain('duskTheme');
589
+ expect(entry).toContain("name: 'dusk'");
590
+ expect(entry).not.toMatch(/\bgothicTheme\b/);
591
+ expect((await validateLocalIntegration(tmpDir)).issues).toEqual([]);
592
+ });
593
+
594
+ it('forks from a theme the package already owns', async () => {
595
+ setup();
596
+ // First, add a blank theme.
597
+ await integrationAddTheme('base', {cwd: tmpDir});
598
+ // Then fork it.
599
+ const result = await integrationAddTheme('variant', {
600
+ cwd: tmpDir,
601
+ from: 'base',
602
+ });
603
+
604
+ expect(result.data.from).toBe('base');
605
+ const entry = fs.readFileSync(
606
+ path.join(tmpDir, 'themes/variant/variantTheme.ts'),
607
+ 'utf-8',
608
+ );
609
+ expect(entry).toContain('variantTheme');
610
+ expect(entry).toContain("name: 'variant'");
611
+ expect((await validateLocalIntegration(tmpDir)).issues).toEqual([]);
612
+ });
613
+
614
+ it('declares the optional CLI peer that reads typed theme descriptors', async () => {
615
+ setup({includeFiles: false});
616
+ await integrationAddTheme('ocean', {cwd: tmpDir, from: 'neutral'});
617
+ const pkg = JSON.parse(
618
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
619
+ );
620
+ expect(pkg.peerDependencies).toEqual({'@astryxdesign/cli': '>=0.6.4'});
621
+ expect(pkg.peerDependenciesMeta).toEqual({
622
+ '@astryxdesign/cli': {optional: true},
623
+ });
624
+ });
625
+ });
@@ -92,6 +92,7 @@ function addErrors(issues, errors, code) {
92
92
  export async function integrationTemplateConflicts(pkg, options = {}) {
93
93
  const {cwd = process.cwd()} = options;
94
94
  const resolved = await resolveIntegration(pkg, cwd);
95
+ const validated = resolved.found;
95
96
  const name = resolved.found ? (resolved.name ?? null) : null;
96
97
  const version = resolved.found ? (resolved.version ?? null) : null;
97
98
  const issues = [...resolved.issues];
@@ -99,7 +100,7 @@ export async function integrationTemplateConflicts(pkg, options = {}) {
99
100
  if (!resolved.integration || name == null) {
100
101
  return {
101
102
  type: 'integration.template-conflicts',
102
- data: {name, version, conflicts: [], issues},
103
+ data: {validated, name, version, conflicts: [], issues},
103
104
  };
104
105
  }
105
106
 
@@ -215,7 +216,7 @@ export async function integrationTemplateConflicts(pkg, options = {}) {
215
216
 
216
217
  return {
217
218
  type: 'integration.template-conflicts',
218
- data: {name, version, conflicts, issues},
219
+ data: {validated, name, version, conflicts, issues},
219
220
  };
220
221
  }
221
222
 
@@ -228,6 +229,7 @@ export async function integrationTemplateConflicts(pkg, options = {}) {
228
229
  export async function integrationComponentConflicts(pkg, options = {}) {
229
230
  const {cwd = process.cwd()} = options;
230
231
  const resolved = await resolveIntegration(pkg, cwd);
232
+ const validated = resolved.found;
231
233
  const name = resolved.found ? (resolved.name ?? null) : null;
232
234
  const version = resolved.found ? (resolved.version ?? null) : null;
233
235
  const issues = [...resolved.issues];
@@ -235,7 +237,7 @@ export async function integrationComponentConflicts(pkg, options = {}) {
235
237
  if (!resolved.integration?.components || name == null) {
236
238
  return {
237
239
  type: 'integration.component-conflicts',
238
- data: {name, version, conflicts: [], issues},
240
+ data: {validated, name, version, conflicts: [], issues},
239
241
  };
240
242
  }
241
243
 
@@ -249,7 +251,7 @@ export async function integrationComponentConflicts(pkg, options = {}) {
249
251
  });
250
252
  return {
251
253
  type: 'integration.component-conflicts',
252
- data: {name, version, conflicts: [], issues},
254
+ data: {validated, name, version, conflicts: [], issues},
253
255
  };
254
256
  }
255
257
 
@@ -274,7 +276,7 @@ export async function integrationComponentConflicts(pkg, options = {}) {
274
276
 
275
277
  return {
276
278
  type: 'integration.component-conflicts',
277
- data: {name, version, conflicts, issues},
279
+ data: {validated, name, version, conflicts, issues},
278
280
  };
279
281
  }
280
282
 
@@ -287,6 +289,7 @@ export async function integrationComponentConflicts(pkg, options = {}) {
287
289
  export async function integrationDocConflicts(pkg, options = {}) {
288
290
  const {cwd = process.cwd()} = options;
289
291
  const resolved = await resolveIntegration(pkg, cwd);
292
+ const validated = resolved.found;
290
293
  const name = resolved.found ? (resolved.name ?? null) : null;
291
294
  const version = resolved.found ? (resolved.version ?? null) : null;
292
295
  const issues = [...resolved.issues];
@@ -294,7 +297,7 @@ export async function integrationDocConflicts(pkg, options = {}) {
294
297
  if (!resolved.integration?.docs || name == null) {
295
298
  return {
296
299
  type: 'integration.doc-conflicts',
297
- data: {name, version, findings: [], issues},
300
+ data: {validated, name, version, findings: [], issues},
298
301
  };
299
302
  }
300
303
 
@@ -388,6 +391,6 @@ export async function integrationDocConflicts(pkg, options = {}) {
388
391
 
389
392
  return {
390
393
  type: 'integration.doc-conflicts',
391
- data: {name, version, findings, issues},
394
+ data: {validated, name, version, findings, issues},
392
395
  };
393
396
  }
@@ -32,9 +32,15 @@ export type IntegrationDocFinding = {
32
32
  coreTopic: string;
33
33
  message: string;
34
34
  };
35
+ /**
36
+ * Each of the three authoring checks reports `validated`: false means no
37
+ * integration manifest was found, so nothing was inspected and the empty
38
+ * conflicts/findings list carries no information about the package.
39
+ */
35
40
  export type IntegrationTemplateConflictResponse = {
36
41
  type: "integration.template-conflicts";
37
42
  data: {
43
+ validated: boolean;
38
44
  name: string | null;
39
45
  version: string | null;
40
46
  conflicts: IntegrationTemplateConflict[];
@@ -44,6 +50,7 @@ export type IntegrationTemplateConflictResponse = {
44
50
  export type IntegrationComponentConflictResponse = {
45
51
  type: "integration.component-conflicts";
46
52
  data: {
53
+ validated: boolean;
47
54
  name: string | null;
48
55
  version: string | null;
49
56
  conflicts: IntegrationComponentConflict[];
@@ -53,6 +60,7 @@ export type IntegrationComponentConflictResponse = {
53
60
  export type IntegrationDocConflictResponse = {
54
61
  type: "integration.doc-conflicts";
55
62
  data: {
63
+ validated: boolean;
56
64
  name: string | null;
57
65
  version: string | null;
58
66
  findings: IntegrationDocFinding[];
@@ -49,21 +49,25 @@
49
49
  */
50
50
 
51
51
  /**
52
+ * Each of the three authoring checks reports `validated`: false means no
53
+ * integration manifest was found, so nothing was inspected and the empty
54
+ * conflicts/findings list carries no information about the package.
55
+ *
52
56
  * @typedef {object} IntegrationTemplateConflictResponse
53
57
  * @property {'integration.template-conflicts'} type
54
- * @property {{name: string | null, version: string | null, conflicts: IntegrationTemplateConflict[], issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[]}} data
58
+ * @property {{validated: boolean, name: string | null, version: string | null, conflicts: IntegrationTemplateConflict[], issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[]}} data
55
59
  */
56
60
 
57
61
  /**
58
62
  * @typedef {object} IntegrationComponentConflictResponse
59
63
  * @property {'integration.component-conflicts'} type
60
- * @property {{name: string | null, version: string | null, conflicts: IntegrationComponentConflict[], issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[]}} data
64
+ * @property {{validated: boolean, name: string | null, version: string | null, conflicts: IntegrationComponentConflict[], issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[]}} data
61
65
  */
62
66
 
63
67
  /**
64
68
  * @typedef {object} IntegrationDocConflictResponse
65
69
  * @property {'integration.doc-conflicts'} type
66
- * @property {{name: string | null, version: string | null, findings: IntegrationDocFinding[], issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[]}} data
70
+ * @property {{validated: boolean, name: string | null, version: string | null, findings: IntegrationDocFinding[], issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[]}} data
67
71
  */
68
72
 
69
73
  export {};
@@ -19,7 +19,9 @@ export type IntegrationAddCodemodOptions = IntegrationAddBaseOptions & {
19
19
  to: string;
20
20
  };
21
21
  export type IntegrationAddAgentDocOptions = IntegrationAddBaseOptions;
22
- export type IntegrationAddThemeOptions = IntegrationAddBaseOptions;
22
+ export type IntegrationAddThemeOptions = IntegrationAddBaseOptions & {
23
+ from?: string;
24
+ };
23
25
  /**
24
26
  * Options for the generic `integrationAdd` dispatcher. Prefer a per-kind API
25
27
  * when the contribution kind is known so the accepted options stay narrow.
@@ -54,4 +56,5 @@ export type IntegrationAddData = {
54
56
  files: string[];
55
57
  written: boolean;
56
58
  dryRun: boolean;
59
+ from?: string | undefined;
57
60
  };
@@ -37,7 +37,11 @@
37
37
  */
38
38
 
39
39
  /** @typedef {IntegrationAddBaseOptions} IntegrationAddAgentDocOptions */
40
- /** @typedef {IntegrationAddBaseOptions} IntegrationAddThemeOptions */
40
+ /**
41
+ * @typedef {IntegrationAddBaseOptions & {
42
+ * from?: string,
43
+ * }} IntegrationAddThemeOptions
44
+ */
41
45
 
42
46
  /**
43
47
  * Options for the generic `integrationAdd` dispatcher. Prefer a per-kind API
@@ -73,6 +77,7 @@
73
77
  * @property {string[]} files
74
78
  * @property {boolean} written
75
79
  * @property {boolean} dryRun
80
+ * @property {string} [from]
76
81
  */
77
82
 
78
83
  export {};
@@ -78,6 +78,12 @@ export const doc = {
78
78
  type: 'string',
79
79
  description: 'Exact target semver (e.g. 1.2.0). Required for codemod and only valid there.',
80
80
  },
81
+ {
82
+ name: 'options.from',
83
+ type: 'string',
84
+ description:
85
+ 'Slug of an existing theme to fork as the starting point. Only valid for theme.',
86
+ },
81
87
  ],
82
88
  returns: [
83
89
  {
@@ -33,6 +33,12 @@ export const doc = {
33
33
  'Validate and return the same receipt without writing; data.written is false and data.dryRun is true.',
34
34
  default: 'false',
35
35
  },
36
+ {
37
+ name: 'options.from',
38
+ type: 'string',
39
+ description:
40
+ 'Slug of an existing theme to fork as the starting point. 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).',
41
+ },
36
42
  ],
37
43
  returns: [
38
44
  {
@@ -76,6 +82,10 @@ export const doc = {
76
82
  label: 'Add a theme',
77
83
  code: "await integrationAddTheme('ocean');",
78
84
  },
85
+ {
86
+ label: 'Fork an existing theme',
87
+ code: "await integrationAddTheme('ocean', {from: 'neutral'});",
88
+ },
79
89
  {
80
90
  label: 'Preview writes',
81
91
  code: "await integrationAddTheme('ocean', {dryRun: true});",
@@ -26,7 +26,7 @@ export const doc = {
26
26
  {
27
27
  type: 'integration.component-conflicts',
28
28
  description:
29
- 'Integration identity, structural issues, and Core component-name conflicts with package-qualified commands.',
29
+ '`validated` (false when no integration manifest was found, so nothing was inspected), integration identity, structural issues, and Core component-name conflicts with package-qualified commands.',
30
30
  },
31
31
  ],
32
32
  examples: [
@@ -26,7 +26,7 @@ export const doc = {
26
26
  {
27
27
  type: 'integration.doc-conflicts',
28
28
  description:
29
- 'Integration identity, structural issues, and classified Core doc relationships.',
29
+ '`validated` (false when no integration manifest was found, so nothing was inspected), integration identity, structural issues, and classified Core doc relationships.',
30
30
  },
31
31
  ],
32
32
  examples: [
@@ -41,7 +41,7 @@ export const doc = {
41
41
  {
42
42
  type: 'integration.template-conflicts',
43
43
  description:
44
- 'The integration identity, structural issues, and every Core template-id conflict with a package-qualified command.',
44
+ '`validated` (false when no integration manifest was found, so nothing was inspected and the empty conflict list carries no information), the integration identity, structural issues, and every Core template-id conflict with a package-qualified command.',
45
45
  },
46
46
  ],
47
47
  examples: [
@@ -29,6 +29,7 @@ import {assertWithin} from '../../foundation/fs/path-safety.mjs';
29
29
  import {resolvePackageDir} from '../../foundation/integrations/integrations.mjs';
30
30
  import {
31
31
  docsTreeCliProblem,
32
+ keywordsCliProblem,
32
33
  replacesCliProblem,
33
34
  sectionIdsCliProblem,
34
35
  themesCliProblem,
@@ -663,15 +664,16 @@ export async function integrationPackCheck(options = {}) {
663
664
  ])
664
665
  ) {
665
666
  // A section `id` is also a field an older CLI rejects, hiding the
666
- // package's doc topics; the same peer range fixes both.
667
+ // package's doc topics. It needs an older CLI than the docs tree does.
667
668
  const idProblem = sectionIdsCliProblem(pkg);
668
669
  if (idProblem != null) {
669
670
  issues.push(error('section_ids_need_cli', idProblem));
670
671
  }
671
672
  }
672
673
  }
673
- // A template that sets `replaces` needs a CLI that reads the field
674
- // (spec:AST-035): an older CLI drops that template and hides the package's docs.
674
+ // A template that sets `replaces` (spec:AST-035) or `keywords` needs a CLI
675
+ // that reads the field: an older CLI drops that template and hides the
676
+ // package's docs.
675
677
  if (loaded.templates) {
676
678
  const found = await discoverIntegrationTemplatesForOne(loaded).catch(
677
679
  () => ({templates: [], errors: []}),
@@ -683,6 +685,13 @@ export async function integrationPackCheck(options = {}) {
683
685
  );
684
686
  const problem = setsReplaces ? replacesCliProblem(pkg) : null;
685
687
  if (problem != null) issues.push(error('replaces_needs_cli', problem));
688
+ const setsKeywords = found.templates.some(
689
+ template => template.keywords != null && template.keywords.length > 0,
690
+ );
691
+ const keywordsProblem = setsKeywords ? keywordsCliProblem(pkg) : null;
692
+ if (keywordsProblem != null) {
693
+ issues.push(error('keywords_needs_cli', keywordsProblem));
694
+ }
686
695
  }
687
696
  // A theme needs a CLI that reads typed theme descriptors: an older CLI
688
697
  // rejects the themes root and withholds the package's themes and docs.