@astryxdesign/cli 0.6.0 → 0.6.1

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 (219) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/README.md +76 -67
  3. package/api/build/build.test.mjs +37 -0
  4. package/api/build/build.type.mjs +1 -1
  5. package/api/build/kit/kit.mjs +31 -1
  6. package/api/component/_adapter.mjs +14 -28
  7. package/api/component/integration-import-agreement.test.mjs +318 -0
  8. package/api/doctor/doctor.d.mts +32 -3
  9. package/api/doctor/doctor.doc.mjs +2 -1
  10. package/api/doctor/doctor.mjs +97 -4
  11. package/api/doctor/doctor.test.mjs +90 -1
  12. package/api/gap-report/gap-report-worker.d.mts +4 -0
  13. package/api/gap-report/gap-report-worker.mjs +73 -0
  14. package/api/gap-report/gap-report.d.mts +81 -0
  15. package/api/gap-report/gap-report.doc.d.mts +9 -0
  16. package/api/gap-report/gap-report.doc.mjs +127 -0
  17. package/api/gap-report/gap-report.mjs +707 -0
  18. package/api/gap-report/gap-report.test.mjs +1210 -0
  19. package/api/gap-report/gap-report.type.d.mts +88 -0
  20. package/api/gap-report/gap-report.type.mjs +69 -0
  21. package/api/index.d.mts +8 -1
  22. package/api/index.mjs +24 -1
  23. package/api/integration/add-contribution.d.mts +44 -0
  24. package/api/integration/add-contribution.mjs +1160 -0
  25. package/api/integration/add-contribution.test.mjs +733 -0
  26. package/api/integration/add-helpers.d.mts +80 -0
  27. package/api/integration/add-helpers.mjs +333 -0
  28. package/api/integration/add-helpers.test.mjs +161 -0
  29. package/api/integration/add-theme.d.mts +10 -0
  30. package/api/integration/add-theme.mjs +332 -0
  31. package/api/integration/add-theme.test.mjs +194 -0
  32. package/api/integration/integration-authoring.type.d.mts +55 -0
  33. package/api/integration/integration-authoring.type.mjs +76 -0
  34. package/api/integration/integration-block-exports.test.mjs +4 -0
  35. package/api/integration/integrationAdd.doc.d.mts +5 -0
  36. package/api/integration/integrationAdd.doc.mjs +100 -0
  37. package/api/integration/integrationAddAgentDoc.doc.d.mts +5 -0
  38. package/api/integration/integrationAddAgentDoc.doc.mjs +49 -0
  39. package/api/integration/integrationAddCodemod.doc.d.mts +5 -0
  40. package/api/integration/integrationAddCodemod.doc.mjs +55 -0
  41. package/api/integration/integrationAddComponent.doc.d.mts +5 -0
  42. package/api/integration/integrationAddComponent.doc.mjs +49 -0
  43. package/api/integration/integrationAddDoc.doc.d.mts +5 -0
  44. package/api/integration/integrationAddDoc.doc.mjs +59 -0
  45. package/api/integration/integrationAddTemplate.doc.d.mts +5 -0
  46. package/api/integration/integrationAddTemplate.doc.mjs +55 -0
  47. package/api/integration/integrationAddTheme.doc.d.mts +5 -0
  48. package/api/integration/integrationAddTheme.doc.mjs +85 -0
  49. package/api/integration/integrationPackCheck.doc.d.mts +5 -0
  50. package/api/integration/integrationPackCheck.doc.mjs +35 -0
  51. package/api/integration/pack-check.d.mts +27 -0
  52. package/api/integration/pack-check.mjs +795 -0
  53. package/api/integration/pack-check.test.mjs +569 -0
  54. package/api/integration/pack-check.type.d.mts +45 -0
  55. package/api/integration/pack-check.type.mjs +56 -0
  56. package/api/integration/public-api.test.mjs +21 -0
  57. package/api/integration/validate-integration.mjs +221 -11
  58. package/api/integration/validate-integration.test.mjs +189 -5
  59. package/api/integration/validateIntegration.doc.mjs +2 -2
  60. package/api/json/index.ts +1 -0
  61. package/api/search/search.mjs +19 -1
  62. package/api/theme/_adapter.d.mts +26 -28
  63. package/api/theme/_adapter.mjs +101 -38
  64. package/api/theme/add/add.d.mts +2 -1
  65. package/api/theme/add/add.mjs +56 -20
  66. package/api/theme/add/add.test.mjs +1 -0
  67. package/api/theme/build/build.d.mts +25 -0
  68. package/api/theme/build/build.mjs +101 -70
  69. package/api/theme/build/build.test.mjs +77 -44
  70. package/api/theme/integration-themes.test.mjs +183 -0
  71. package/api/theme/list/list.d.mts +10 -2
  72. package/api/theme/list/list.mjs +31 -10
  73. package/api/theme/list/list.test.mjs +102 -23
  74. package/api/theme/listThemes.doc.d.mts +1 -5
  75. package/api/theme/listThemes.doc.mjs +6 -13
  76. package/api/theme/targets/targets.test.mjs +22 -8
  77. package/api/theme/theme.d.mts +1 -1
  78. package/api/theme/theme.mjs +1 -1
  79. package/api/theme/theme.type.d.mts +9 -0
  80. package/api/theme/theme.type.mjs +3 -1
  81. package/api/theme/themeAdd.doc.d.mts +1 -4
  82. package/api/theme/themeAdd.doc.mjs +31 -31
  83. package/api/theme/themeBuild.doc.mjs +1 -1
  84. package/api/theme/themeList.doc.d.mts +1 -4
  85. package/api/theme/themeList.doc.mjs +7 -15
  86. package/api/theme/themeListAvailable.doc.d.mts +8 -0
  87. package/api/theme/themeListAvailable.doc.mjs +57 -0
  88. package/api/theme/themeTargets.doc.mjs +21 -7
  89. package/api/upgrade/_adapter.d.mts +2 -0
  90. package/api/upgrade/_adapter.mjs +1 -0
  91. package/api/upgrade/registry/registry.d.mts +40 -0
  92. package/api/upgrade/registry/registry.mjs +1154 -0
  93. package/api/upgrade/registry/registry.test.mjs +826 -0
  94. package/api/upgrade/run/run.mjs +49 -8
  95. package/api/upgrade/status/status.d.mts +6 -4
  96. package/api/upgrade/status/status.mjs +26 -8
  97. package/api/upgrade/upgrade.d.mts +2 -2
  98. package/api/upgrade/upgrade.doc.mjs +33 -9
  99. package/api/upgrade/upgrade.mjs +34 -7
  100. package/api/upgrade/upgrade.test.mjs +198 -8
  101. package/api/upgrade/upgrade.type.d.mts +90 -1
  102. package/api/upgrade/upgrade.type.mjs +51 -2
  103. package/assets/docs/cli-integrations.doc.mjs +152 -28
  104. package/assets/docs/getting-started.doc.mjs +1 -1
  105. package/assets/docs/{shadcn-compatibility.doc.mjs → shadcn-compatibility.doc.draft.mjs} +23 -13
  106. package/assets/docs/styling.doc.mjs +3 -3
  107. package/assets/docs/theme.doc.dense.mjs +2 -2
  108. package/assets/docs/theme.doc.mjs +23 -13
  109. package/assets/docs/theme.doc.zh.mjs +1 -1
  110. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.doc.mjs +2 -1
  111. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadCustomSearch.tsx +38 -12
  112. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.doc.mjs +15 -0
  113. package/assets/templates/blocks/components/BaseTypeahead/BaseTypeaheadShowcase.tsx +87 -0
  114. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +23 -0
  115. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +75 -0
  116. package/assets/templates/blocks/components/BreadcrumbItem/BreadcrumbItemShowcase.tsx +5 -19
  117. package/assets/templates/blocks/components/Center/CenterHorizontal.doc.mjs +3 -2
  118. package/assets/templates/blocks/components/Center/CenterHorizontal.tsx +4 -5
  119. package/assets/templates/blocks/components/Toast/ToastAction.tsx +2 -1
  120. package/assets/templates/blocks/components/Toast/ToastDeduplication.tsx +2 -1
  121. package/assets/templates/blocks/components/Toast/ToastDismiss.tsx +2 -1
  122. package/assets/templates/blocks/components/Toast/ToastShowcase.tsx +2 -1
  123. package/assets/templates/blocks/components/Toast/ToastStacking.tsx +2 -1
  124. package/assets/templates/blocks/components/Toast/ToastTypes.tsx +2 -1
  125. package/assets/templates/pages/dashboard/template.doc.mjs +2 -2
  126. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +3 -2
  127. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +3 -2
  128. package/assets/templates/pages/dashboard-comparison/template.doc.mjs +3 -3
  129. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -2
  130. package/assets/templates/pages/dashboard-progress/template.doc.mjs +2 -2
  131. package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -2
  132. package/assets/templates/themes/butter/butterTheme.ts +3 -3
  133. package/assets/templates/themes/neutral/neutralTheme.ts +2 -2
  134. package/assets/templates/themes/stone/stoneTheme.ts +3 -3
  135. package/assets/theme.template.ts +4 -7
  136. package/authoring/config/config.doc.mjs +9 -1
  137. package/authoring/config/parse.d.mts +2 -0
  138. package/authoring/config/parse.mjs +28 -3
  139. package/authoring/config/parse.test.mjs +25 -3
  140. package/authoring/config/type.ts +3 -0
  141. package/authoring/doctypes/_schema.d.mts +3 -0
  142. package/authoring/doctypes/_schema.mjs +6 -1
  143. package/authoring/doctypes/base/type.ts +6 -6
  144. package/authoring/doctypes/component/component.doc.mjs +6 -0
  145. package/authoring/doctypes/component/type.ts +2 -0
  146. package/authoring/gap-report/parse.d.mts +63 -0
  147. package/authoring/gap-report/parse.mjs +121 -0
  148. package/authoring/gap-report/parse.test.mjs +172 -0
  149. package/authoring/gap-report/type.ts +107 -0
  150. package/authoring/index.d.mts +1 -0
  151. package/authoring/index.d.ts +12 -0
  152. package/authoring/index.mjs +4 -0
  153. package/authoring/integration/integration.doc.mjs +14 -2
  154. package/authoring/integration/parse.test.mjs +9 -4
  155. package/authoring/integration/schema.d.mts +2 -0
  156. package/authoring/integration/schema.mjs +1 -0
  157. package/authoring/integration/type.ts +23 -6
  158. package/authoring/shadcn/receipt.d.mts +219 -0
  159. package/authoring/shadcn/receipt.mjs +248 -0
  160. package/authoring/shadcn/receipt.test.mjs +187 -0
  161. package/authoring/shadcn/source-variants.d.mts +28 -0
  162. package/authoring/shadcn/source-variants.mjs +176 -0
  163. package/authoring/shadcn/source-variants.test.mjs +120 -0
  164. package/clients/cli/commands/build-theme.mjs +54 -19
  165. package/clients/cli/commands/build-theme.variants.test.mjs +15 -12
  166. package/clients/cli/commands/component/index.mjs +1 -1
  167. package/clients/cli/commands/docs.test.mjs +1 -0
  168. package/clients/cli/commands/doctor-integration.doc.mjs +1 -1
  169. package/clients/cli/commands/gap-report.doc.mjs +73 -0
  170. package/clients/cli/commands/gap-report.mjs +114 -0
  171. package/clients/cli/commands/gap-report.test.mjs +198 -0
  172. package/clients/cli/commands/import-hint-correctness.test.mjs +88 -0
  173. package/clients/cli/commands/integration-add.doc.mjs +88 -0
  174. package/clients/cli/commands/integration-authoring.test.mjs +177 -0
  175. package/clients/cli/commands/integration-pack.doc.mjs +34 -0
  176. package/clients/cli/commands/integration-real-world.test.mjs +618 -0
  177. package/clients/cli/commands/integration.doc.mjs +28 -0
  178. package/clients/cli/commands/integration.mjs +153 -0
  179. package/clients/cli/commands/theme-add.doc.mjs +11 -6
  180. package/clients/cli/commands/theme-list.doc.mjs +21 -5
  181. package/clients/cli/commands/theme-targets.behavior.test.mjs +19 -2
  182. package/clients/cli/commands/theme.doc.mjs +2 -2
  183. package/clients/cli/commands/upgrade.doc.mjs +17 -4
  184. package/clients/cli/commands/upgrade.mjs +12 -1
  185. package/clients/cli/commands/upgrade.test.mjs +41 -0
  186. package/clients/cli/index.mjs +5 -0
  187. package/clients/cli/lib/component-format.mjs +42 -26
  188. package/clients/cli/lib/component-format.test.mjs +34 -3
  189. package/clients/cli/lib/manifest.mjs +12 -0
  190. package/foundation/config/project-themes.test.mjs +127 -0
  191. package/foundation/config/project.d.mts +23 -4
  192. package/foundation/config/project.mjs +96 -9
  193. package/foundation/config/project.test.mjs +132 -6
  194. package/foundation/discovery/component-discovery.d.mts +36 -0
  195. package/foundation/discovery/component-discovery.mjs +96 -0
  196. package/foundation/discovery/theme-discovery.d.mts +39 -0
  197. package/foundation/discovery/theme-discovery.mjs +650 -0
  198. package/foundation/discovery/theme-discovery.test.mjs +375 -0
  199. package/foundation/discovery/theming-targets.d.mts +16 -0
  200. package/foundation/discovery/theming-targets.mjs +39 -3
  201. package/foundation/discovery/theming-targets.test.mjs +139 -0
  202. package/foundation/integrations/autolink.d.mts +96 -0
  203. package/foundation/integrations/autolink.mjs +265 -0
  204. package/foundation/integrations/autolink.test.mjs +430 -0
  205. package/foundation/integrations/contribution-inventory.d.mts +152 -0
  206. package/foundation/integrations/contribution-inventory.mjs +497 -0
  207. package/foundation/integrations/contribution-inventory.test.mjs +361 -0
  208. package/foundation/integrations/integrations.d.mts +73 -9
  209. package/foundation/integrations/integrations.mjs +158 -8
  210. package/foundation/integrations/integrations.test.mjs +152 -29
  211. package/foundation/integrations/manifest-writer.d.mts +56 -0
  212. package/foundation/integrations/manifest-writer.mjs +328 -0
  213. package/foundation/integrations/manifest-writer.test.mjs +229 -0
  214. package/foundation/integrations/validate-contributions.mjs +81 -6
  215. package/foundation/response/error-codes.d.mts +4 -1
  216. package/foundation/response/error-codes.doc.mjs +16 -1
  217. package/foundation/response/error-codes.mjs +10 -1
  218. package/foundation/response/response-types.doc.mjs +23 -2
  219. package/package.json +8 -1
@@ -143,22 +143,25 @@ describe('theme build custom-variant augmentations', () => {
143
143
  path.join(tmpDir, 'variants-theme.css'),
144
144
  'utf-8',
145
145
  );
146
- const mainTypeIndex = css.indexOf(
147
- '.astryx-heading[data-type="hero"]',
148
- );
146
+ const mainTypeIndex = css.indexOf('.astryx-heading[data-type="hero"]');
149
147
  const mainTypeWeightIndex = css.indexOf('font-weight: 300;', mainTypeIndex);
150
- const mainWeightIndex = css.indexOf(
151
- '.astryx-heading[data-weight="bold"]',
148
+ const mainWeightIndex = css.indexOf('.astryx-heading[data-weight="bold"]');
149
+ const mainWeightValueIndex = css.indexOf(
150
+ 'font-weight: 900;',
151
+ mainWeightIndex,
152
152
  );
153
- const mainWeightValueIndex = css.indexOf('font-weight: 900;', mainWeightIndex);
154
- const mediaTypeIndex = css.lastIndexOf(
155
- '.astryx-heading[data-type="hero"]',
153
+ const mediaTypeIndex = css.lastIndexOf('.astryx-heading[data-type="hero"]');
154
+ const mediaTypeWeightIndex = css.indexOf(
155
+ 'font-weight: 350;',
156
+ mediaTypeIndex,
156
157
  );
157
- const mediaTypeWeightIndex = css.indexOf('font-weight: 350;', mediaTypeIndex);
158
158
  const mediaWeightIndex = css.lastIndexOf(
159
159
  '.astryx-heading[data-weight="bold"]',
160
160
  );
161
- const mediaWeightValueIndex = css.indexOf('font-weight: 800;', mediaWeightIndex);
161
+ const mediaWeightValueIndex = css.indexOf(
162
+ 'font-weight: 800;',
163
+ mediaWeightIndex,
164
+ );
162
165
  expect(mainTypeWeightIndex).toBeGreaterThan(mainTypeIndex);
163
166
  expect(mainWeightValueIndex).toBeGreaterThan(mainWeightIndex);
164
167
  expect(mediaTypeWeightIndex).toBeGreaterThan(mediaTypeIndex);
@@ -342,9 +345,9 @@ describe('theme build custom-variant augmentations', () => {
342
345
  divider: { 'variant:customDivider': { borderColor: 'currentColor' } },
343
346
  'field-status': { 'variant:customFieldStatus': { color: 'currentColor' } },
344
347
  pagination: { 'variant:customPagination': { color: 'currentColor' } },
345
- progressbar: { 'variant:customProgressBar': { backgroundColor: 'transparent' } },
348
+ 'progress-bar': { 'variant:customProgressBar': { backgroundColor: 'transparent' } },
346
349
  section: { 'variant:customSection': { backgroundColor: 'transparent' } },
347
- statusdot: { 'variant:customStatusDot': { backgroundColor: 'transparent' } },
350
+ 'status-dot': { 'variant:customStatusDot': { backgroundColor: 'transparent' } },
348
351
  heading: { 'type:customHeading': { fontSize: '3rem' } },
349
352
  text: { 'color:customTextColor': { color: 'currentColor' } },
350
353
  token: { 'color:customTokenColor': { backgroundColor: 'transparent' } },
@@ -231,7 +231,7 @@ export function registerComponent(program) {
231
231
 
232
232
  case 'component.detail': {
233
233
  const resolvedName = (name || '').replace(/^XDS/, '');
234
- const importHint = resolveImportPath(coreDir, resolvedName);
234
+ const importHint = result.data.import;
235
235
  const doc =
236
236
  detail === 'brief'
237
237
  ? code(formatBrief(result.data, resolvedName, importHint, {themeData}))
@@ -35,6 +35,7 @@ describe('registerDocs', () => {
35
35
  const output = console.log.mock.calls.map(c => c[0]).join('\n');
36
36
  expect(output).toContain('principles');
37
37
  expect(output).toContain('tokens');
38
+ expect(output).not.toContain('shadcn-compatibility');
38
39
  });
39
40
 
40
41
  it('errors for unknown topic', async () => {
@@ -14,7 +14,7 @@ export const doc = {
14
14
  description:
15
15
  'The integration-authoring diagnostics group. Validate a manifest and all ' +
16
16
  'contributions with `validate`, or check templates, components, and docs ' +
17
- 'against built-in Core identities before publishing.',
17
+ 'against built-in Core identities before publishing. Theme catalogs are checked by validate.',
18
18
  subcommands: ['validate', 'templates', 'components', 'docs'],
19
19
  examples: [
20
20
  {
@@ -0,0 +1,73 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file CommandDoc for `astryx gap-report`.
5
+ * @position packages/cli/clients/cli/commands — command documentation
6
+ */
7
+
8
+ /** @type {import('@astryxdesign/cli/authoring').CommandDoc} */
9
+ export const doc = {
10
+ type: 'command',
11
+ name: 'gap-report',
12
+ displayName: 'astryx gap-report',
13
+ namespace: 'cli',
14
+ summary: 'Route a design-system gap to its owning package',
15
+ description:
16
+ 'Reports a missing component, variant, layout, styling, accessibility, API, or documentation capability. The command selects an explicit package first, then a unique component owner, then Core. The report fans out to every effective handler: project config first, then each loaded integration in config order. Public handlers require --confirm-public per handler; internal handlers always run. A handler failure is isolated and does not prevent later handlers.',
17
+ fn: 'gapReport',
18
+ args: [{name: 'component', param: 'component', required: false}],
19
+ options: [
20
+ {
21
+ flag: '--category <category>',
22
+ param: 'options.category',
23
+ description: 'Gap category (run --list-categories for values)',
24
+ },
25
+ {
26
+ flag: '--reason <reason>',
27
+ param: 'options.reason',
28
+ description: 'What capability was missing or difficult',
29
+ },
30
+ {
31
+ flag: '--additional-context <text>',
32
+ param: 'options.detail',
33
+ description: 'Optional additional context',
34
+ },
35
+ {
36
+ flag: '--package <pkg>',
37
+ param: 'options.package',
38
+ description: 'Route to a specific loaded package',
39
+ },
40
+ {
41
+ flag: '--confirm-public',
42
+ param: 'options.confirmPublic',
43
+ description: 'Consent to public handlers or GitHub issue creation',
44
+ },
45
+ {
46
+ flag: '--list-categories',
47
+ param: 'options.listCategories',
48
+ description: 'List valid report categories without filing',
49
+ },
50
+ ],
51
+ examples: [
52
+ {label: 'List categories', cli: 'astryx gap-report --list-categories'},
53
+ {
54
+ label: 'Route an agent report',
55
+ cli: "astryx gap-report Button --category missing_variant --reason 'Need a compact size'",
56
+ },
57
+ {
58
+ label: 'Confirm public filing',
59
+ cli: "astryx gap-report Button --category docs_gap --reason 'Missing keyboard example' --confirm-public",
60
+ },
61
+ ],
62
+ exitCodes: [
63
+ {
64
+ code: 0,
65
+ when: 'filed, routed-only, confirmation required, skipped, or categories listed',
66
+ },
67
+ {
68
+ code: 1,
69
+ when: 'failed or partial delivery, invalid input, or ambiguous routing',
70
+ },
71
+ ],
72
+ related: ['component', 'discover', 'swizzle'],
73
+ };
@@ -0,0 +1,114 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx gap-report` CLI adapter.
5
+ */
6
+
7
+ import {gapReport as gapReportApi} from '../../../api/gap-report/gap-report.mjs';
8
+ import {NO_RESULT_SET, resultSet} from '../../../foundation/debug/index.mjs';
9
+ import {jsonOut} from '../../../foundation/response/json.mjs';
10
+ import {emit, record, records, section} from '../formatters/index.mjs';
11
+ import {cliError} from '../lib/cli-error.mjs';
12
+ import {defineCommand} from '../lib/define-command.mjs';
13
+ import {doc as gapReportCommand} from './gap-report.doc.mjs';
14
+ import {doc as gapReportFn} from '../../../api/gap-report/gap-report.doc.mjs';
15
+
16
+ /** @param {import('commander').Command} program */
17
+ export function registerGapReport(program) {
18
+ defineCommand(program, gapReportCommand, {
19
+ fn: gapReportFn,
20
+ action: async (
21
+ /** @type {string|undefined} */ component,
22
+ /** @type {{category?: string, reason?: string, additionalContext?: string, package?: string, confirmPublic?: boolean, listCategories?: boolean}} */ options,
23
+ ) => {
24
+ /** @type {Awaited<ReturnType<typeof gapReportApi>>} */
25
+ let result;
26
+ try {
27
+ result = await gapReportApi(component, {
28
+ cwd: process.cwd(),
29
+ category:
30
+ /** @type {import('../../../api/gap-report/gap-report.type.mjs').GapReportCategory|undefined} */ (
31
+ options.category
32
+ ),
33
+ reason: options.reason,
34
+ detail: options.additionalContext,
35
+ package: options.package,
36
+ confirmPublic: options.confirmPublic,
37
+ listCategories: options.listCategories,
38
+ });
39
+ } catch (error) {
40
+ const err =
41
+ /** @type {import('../../../api/error.mjs').AstryxError} */ (error);
42
+ return cliError(err.message, {
43
+ suggestions: err.suggestions,
44
+ code: err.code,
45
+ });
46
+ }
47
+
48
+ const answered =
49
+ result.type === 'gap-report.categories'
50
+ ? resultSet({count: result.data.length, resultKind: 'command'})
51
+ : NO_RESULT_SET;
52
+
53
+ // CLI exits nonzero for failed/partial but still emits the receipt
54
+ const isFailure =
55
+ result.type === 'gap-report.file' &&
56
+ (result.data.status === 'failed' || result.data.status === 'partial');
57
+
58
+ if (program.opts().json) {
59
+ jsonOut(result);
60
+ if (isFailure) process.exitCode = 1;
61
+ return answered;
62
+ }
63
+
64
+ if (result.type === 'gap-report.categories') {
65
+ emit(
66
+ section('Gap report categories'),
67
+ records(result.data, {fields: ['value', 'label']}),
68
+ );
69
+ return answered;
70
+ }
71
+
72
+ const heading =
73
+ result.data.status === 'filed'
74
+ ? 'Gap report filed'
75
+ : result.data.status === 'partial'
76
+ ? 'Gap report partially filed'
77
+ : result.data.status === 'failed'
78
+ ? 'Gap report failed'
79
+ : 'Gap report route';
80
+
81
+ emit(
82
+ section(heading),
83
+ record(result.data, {
84
+ fields: [
85
+ 'status',
86
+ 'package',
87
+ 'issuesUrl',
88
+ 'filedCount',
89
+ 'routedOnlyCount',
90
+ ],
91
+ }),
92
+ );
93
+
94
+ if (result.data.deliveries.length > 0) {
95
+ emit(
96
+ section('Deliveries'),
97
+ records(result.data.deliveries, {
98
+ fields: [
99
+ 'handlerType',
100
+ 'handler',
101
+ 'audience',
102
+ 'status',
103
+ 'url',
104
+ 'message',
105
+ ],
106
+ }),
107
+ );
108
+ }
109
+
110
+ if (isFailure) process.exitCode = 1;
111
+ return answered;
112
+ },
113
+ });
114
+ }
@@ -0,0 +1,198 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import * as fs from 'node:fs';
4
+ import * as os from 'node:os';
5
+ import * as path from 'node:path';
6
+ import {describe, expect, it} from 'vitest';
7
+ import {gapReport} from '../../../api/gap-report/gap-report.mjs';
8
+ import {runCli} from '../../../test-utils/run-cli.mjs';
9
+
10
+ describe('gap-report CLI and API parity', () => {
11
+ it('returns the same category catalog', async () => {
12
+ const api = await gapReport(undefined, {listCategories: true});
13
+ const cli = await runCli(['gap-report', '--list-categories', '--json']);
14
+
15
+ expect(cli.status).toBe(0);
16
+ const envelope = JSON.parse(cli.stdout);
17
+ expect({type: envelope.type, data: envelope.data}).toEqual(api);
18
+ });
19
+
20
+ it('keeps the global --detail option separate from gap-report context', async () => {
21
+ for (const args of [
22
+ ['--detail', 'compact', 'gap-report', '--list-categories', '--json'],
23
+ ['gap-report', '--list-categories', '--detail', 'compact', '--json'],
24
+ ]) {
25
+ const cli = await runCli(args);
26
+ expect(cli.status).toBe(0);
27
+ expect(JSON.parse(cli.stdout)).toMatchObject({
28
+ type: 'gap-report.categories',
29
+ });
30
+ }
31
+ });
32
+
33
+ it('maps --additional-context to the API detail field', async () => {
34
+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-gap-context-'));
35
+ try {
36
+ fs.writeFileSync(
37
+ path.join(cwd, 'package.json'),
38
+ JSON.stringify({name: 'fixture-app'}),
39
+ );
40
+ fs.writeFileSync(
41
+ path.join(cwd, 'astryx.config.mjs'),
42
+ `export default {
43
+ gapReport: {
44
+ audience: 'internal',
45
+ handle(report) {
46
+ return {status: 'filed', message: report.detail};
47
+ },
48
+ },
49
+ };\n`,
50
+ );
51
+
52
+ const cli = await runCli(
53
+ [
54
+ 'gap-report',
55
+ 'Button',
56
+ '--category',
57
+ 'docs_gap',
58
+ '--reason',
59
+ 'Need a keyboard example',
60
+ '--additional-context',
61
+ 'The example must show focus order.',
62
+ '--json',
63
+ ],
64
+ {cwd},
65
+ );
66
+
67
+ expect(cli.status).toBe(0);
68
+ expect(JSON.parse(cli.stdout)).toMatchObject({
69
+ type: 'gap-report.file',
70
+ data: {
71
+ deliveries: [
72
+ {
73
+ handler: 'project',
74
+ status: 'filed',
75
+ message: 'The example must show focus order.',
76
+ },
77
+ ],
78
+ },
79
+ });
80
+ } finally {
81
+ fs.rmSync(cwd, {recursive: true, force: true});
82
+ }
83
+ });
84
+
85
+ it('returns the same consent-required Core receipt without writing', async () => {
86
+ const options = {
87
+ category: 'docs_gap',
88
+ reason: 'Need a keyboard example',
89
+ cwd: process.cwd(),
90
+ };
91
+ const api = await gapReport('Button', options);
92
+ const cli = await runCli([
93
+ 'gap-report',
94
+ 'Button',
95
+ '--category',
96
+ 'docs_gap',
97
+ '--reason',
98
+ 'Need a keyboard example',
99
+ '--json',
100
+ ]);
101
+
102
+ expect(cli.status).toBe(0);
103
+ const envelope = JSON.parse(cli.stdout);
104
+ expect({type: envelope.type, data: envelope.data}).toEqual(api);
105
+ expect(envelope.data.status).toBe('consent_required');
106
+ });
107
+
108
+ it('keeps the JSON receipt and exits nonzero for a partial fan-out', async () => {
109
+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-gap-cli-'));
110
+ try {
111
+ fs.writeFileSync(
112
+ path.join(cwd, 'package.json'),
113
+ JSON.stringify({name: 'fixture-app'}),
114
+ );
115
+ fs.writeFileSync(
116
+ path.join(cwd, 'astryx.config.mjs'),
117
+ `export default {
118
+ integrations: ['@test/receiver'],
119
+ gapReport: {
120
+ audience: 'internal',
121
+ handle() { throw new Error('project failed'); },
122
+ },
123
+ };\n`,
124
+ );
125
+ const integrationDir = path.join(
126
+ cwd,
127
+ 'node_modules',
128
+ '@test',
129
+ 'receiver',
130
+ );
131
+ fs.mkdirSync(integrationDir, {recursive: true});
132
+ fs.writeFileSync(
133
+ path.join(integrationDir, 'package.json'),
134
+ JSON.stringify({name: '@test/receiver', version: '1.0.0'}),
135
+ );
136
+ fs.writeFileSync(
137
+ path.join(integrationDir, 'astryx.integration.mjs'),
138
+ `export const gapReport = {
139
+ audience: 'internal',
140
+ handle() { return {status: 'filed', message: 'received'}; },
141
+ };
142
+ export default {};\n`,
143
+ );
144
+
145
+ const cli = await runCli(
146
+ [
147
+ 'gap-report',
148
+ 'Button',
149
+ '--category',
150
+ 'docs_gap',
151
+ '--reason',
152
+ 'Need a keyboard example',
153
+ '--json',
154
+ ],
155
+ {cwd},
156
+ );
157
+
158
+ expect(cli.status).toBe(1);
159
+ expect(JSON.parse(cli.stdout)).toMatchObject({
160
+ type: 'gap-report.file',
161
+ data: {
162
+ status: 'partial',
163
+ filedCount: 1,
164
+ deliveries: [
165
+ {handler: 'project', status: 'failed'},
166
+ {handler: '@test/receiver', status: 'filed'},
167
+ ],
168
+ },
169
+ });
170
+ } finally {
171
+ fs.rmSync(cwd, {recursive: true, force: true});
172
+ }
173
+ });
174
+
175
+ it('reports missing required fields through the JSON error contract', async () => {
176
+ const cli = await runCli(['gap-report', 'Button', '--json']);
177
+ expect(cli.status).toBe(1);
178
+ expect(JSON.parse(cli.stdout)).toMatchObject({
179
+ code: 'ERR_MISSING_ARGUMENT',
180
+ });
181
+ });
182
+
183
+ it('uses the existing unknown-category error code', async () => {
184
+ const cli = await runCli([
185
+ 'gap-report',
186
+ 'Button',
187
+ '--category',
188
+ 'not_real',
189
+ '--reason',
190
+ 'Need something else',
191
+ '--json',
192
+ ]);
193
+ expect(cli.status).toBe(1);
194
+ expect(JSON.parse(cli.stdout)).toMatchObject({
195
+ code: 'ERR_UNKNOWN_CATEGORY',
196
+ });
197
+ });
198
+ });
@@ -123,6 +123,94 @@ describe('import hint correctness', () => {
123
123
  }
124
124
  });
125
125
 
126
+ describe('integration-owned components show their own package as the import hint', () => {
127
+ /**
128
+ * @param {{exports?: Record<string, string>}} [opts]
129
+ * @returns {string} the fixture's project root (pass as runCli's cwd)
130
+ */
131
+ function createIntegrationFixture({exports: pkgExports} = {}) {
132
+ const fixtureDir = fs.mkdtempSync(
133
+ path.join(__dirname, '__import_hint_integration_'),
134
+ );
135
+
136
+ fs.mkdirSync(path.join(fixtureDir, 'packages'), {recursive: true});
137
+ fs.symlinkSync(coreDir, path.join(fixtureDir, 'packages', 'core'));
138
+ fs.writeFileSync(
139
+ path.join(fixtureDir, 'package.json'),
140
+ JSON.stringify({name: 'fixture-app', version: '1.0.0'}),
141
+ );
142
+ fs.writeFileSync(
143
+ path.join(fixtureDir, 'astryx.config.mjs'),
144
+ "export default { integrations: ['@test/widgets'] };",
145
+ );
146
+
147
+ const intDir = path.join(fixtureDir, 'node_modules', '@test', 'widgets');
148
+ const compDir = path.join(intDir, 'components', 'Widget');
149
+ fs.mkdirSync(compDir, {recursive: true});
150
+ fs.writeFileSync(
151
+ path.join(intDir, 'package.json'),
152
+ JSON.stringify({
153
+ name: '@test/widgets',
154
+ version: '1.0.0',
155
+ ...(pkgExports ? {exports: pkgExports} : {}),
156
+ }),
157
+ );
158
+ fs.writeFileSync(
159
+ path.join(intDir, 'astryx.integration.mjs'),
160
+ "export default { components: './components' };",
161
+ );
162
+ fs.writeFileSync(
163
+ path.join(compDir, 'Widget.doc.mjs'),
164
+ "export const docs = {\n name: 'Widget',\n usage: { description: 'A test widget.' },\n props: [{ name: 'label', type: 'string', description: 'Label text' }],\n};\n",
165
+ );
166
+
167
+ return fixtureDir;
168
+ }
169
+
170
+ it('component <Name> (full) shows the integration package, not @astryxdesign/core', async () => {
171
+ const fixtureDir = createIntegrationFixture();
172
+ try {
173
+ const result = await runCli(['component', 'Widget'], fixtureDir);
174
+ expect(result.code).toBe(0);
175
+ expect(result.stdout).toContain("from '@test/widgets';");
176
+ expect(result.stdout).not.toContain('@astryxdesign/core');
177
+ } finally {
178
+ fs.rmSync(fixtureDir, {recursive: true, force: true});
179
+ }
180
+ });
181
+
182
+ it('component <Name> --detail brief also shows the integration package', async () => {
183
+ const fixtureDir = createIntegrationFixture();
184
+ try {
185
+ const result = await runCli(
186
+ ['component', 'Widget', '--detail', 'brief'],
187
+ fixtureDir,
188
+ );
189
+ expect(result.code).toBe(0);
190
+ expect(result.stdout).toContain('@test/widgets');
191
+ expect(result.stdout).not.toContain('@astryxdesign/core');
192
+ } finally {
193
+ fs.rmSync(fixtureDir, {recursive: true, force: true});
194
+ }
195
+ });
196
+
197
+ it('resolves to a subpath when the integration exports one for the component', async () => {
198
+ const fixtureDir = createIntegrationFixture({
199
+ exports: {
200
+ '.': './index.js',
201
+ './Widget': './components/Widget/index.js',
202
+ },
203
+ });
204
+ try {
205
+ const result = await runCli(['component', 'Widget'], fixtureDir);
206
+ expect(result.code).toBe(0);
207
+ expect(result.stdout).toContain("from '@test/widgets/Widget';");
208
+ } finally {
209
+ fs.rmSync(fixtureDir, {recursive: true, force: true});
210
+ }
211
+ });
212
+ });
213
+
126
214
  describe('group names do NOT resolve to incorrect import paths', () => {
127
215
  const groups = ['Checkbox', 'Radio', 'Chat', 'Tabs', 'Resizable', 'Utilities'];
128
216
 
@@ -0,0 +1,88 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').CommandDoc} */
4
+ export const doc = {
5
+ type: 'command',
6
+ name: 'integration add',
7
+ displayName: 'astryx integration add',
8
+ namespace: 'cli',
9
+ summary: 'Add one working contribution to an integration package',
10
+ description:
11
+ 'Writes the complete minimum shape the selected contribution needs, creates the integration manifest on first use, declares the root only after a valid contribution exists, and verifies the result through the same discovery contract the packed-package check uses.',
12
+ fn: 'integrationAdd',
13
+ args: [
14
+ {
15
+ name: 'kind',
16
+ param: 'kind',
17
+ required: true,
18
+ description: 'component, doc, template, codemod, agent-doc, or theme',
19
+ },
20
+ {
21
+ name: 'name',
22
+ param: 'name',
23
+ required: true,
24
+ description:
25
+ 'Contribution name; for agent-doc this is the literal guidance line',
26
+ },
27
+ ],
28
+ options: [
29
+ {
30
+ flag: '--dry-run',
31
+ param: 'options.dryRun',
32
+ description: 'Validate and show planned writes without changing files',
33
+ },
34
+ {
35
+ flag: '--type <type>',
36
+ param: 'options.templateType',
37
+ choices: ['page', 'block'],
38
+ description: 'Template type (page or block); only valid for template',
39
+ },
40
+ {
41
+ flag: '--replaces <topic>',
42
+ param: 'options.replaces',
43
+ description: 'Replace an existing doc topic; only valid for doc',
44
+ },
45
+ {
46
+ flag: '--extends <topic>',
47
+ param: 'options.extends',
48
+ description: 'Extend an existing doc topic; only valid for doc',
49
+ },
50
+ {
51
+ flag: '--to <version>',
52
+ param: 'options.to',
53
+ description: 'Target version for a codemod; required for codemod',
54
+ },
55
+ ],
56
+ examples: [
57
+ {
58
+ label: 'Add a component',
59
+ cli: 'astryx integration add component AcmeWidget',
60
+ },
61
+ {label: 'Add a doc topic', cli: 'astryx integration add doc deploying'},
62
+ {
63
+ label: 'Add a page template',
64
+ cli: 'astryx integration add template dashboard',
65
+ },
66
+ {
67
+ label: 'Add a codemod',
68
+ cli: 'astryx integration add codemod rename-widget --to 1.2.0',
69
+ },
70
+ {
71
+ label: 'Add agent guidance',
72
+ cli: "astryx integration add agent-doc 'Run acme verify before finishing.'",
73
+ },
74
+ {label: 'Add a source theme', cli: 'astryx integration add theme ocean'},
75
+ {
76
+ label: 'Preview',
77
+ cli: 'astryx integration add component AcmeWidget --dry-run --json',
78
+ },
79
+ ],
80
+ exitCodes: [
81
+ {code: 0, when: 'the contribution is written or the dry run succeeds'},
82
+ {
83
+ code: 1,
84
+ when: 'the kind, name, options, package, or target files are invalid or conflict',
85
+ },
86
+ ],
87
+ related: ['integration pack', 'doctor integration validate', 'theme add'],
88
+ };