@astryxdesign/cli 0.1.6 → 0.1.7-canary.04cd8f7

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 (107) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +115 -19
  3. package/docs/cli-integrations.doc.mjs +150 -0
  4. package/docs/getting-started.doc.mjs +9 -9
  5. package/docs/internationalization.doc.mjs +243 -0
  6. package/docs/layout.doc.dense.mjs +5 -0
  7. package/docs/migration.doc.mjs +18 -18
  8. package/docs/principles.doc.dense.mjs +5 -5
  9. package/docs/principles.doc.mjs +6 -6
  10. package/docs/principles.doc.zh.mjs +5 -5
  11. package/docs/styling-libraries.doc.mjs +3 -3
  12. package/docs/styling.doc.mjs +4 -4
  13. package/docs/theme.doc.dense.mjs +12 -12
  14. package/docs/theme.doc.mjs +7 -7
  15. package/docs/theme.doc.zh.mjs +10 -10
  16. package/docs/tokens.doc.dense.mjs +6 -7
  17. package/docs/tokens.doc.mjs +1 -1
  18. package/docs/tokens.doc.zh.mjs +6 -7
  19. package/docs/working-with-ai.doc.mjs +18 -18
  20. package/package.json +13 -10
  21. package/src/api/docOverlays.test.mjs +133 -0
  22. package/src/api/docs.mjs +14 -2
  23. package/src/api/doctor.mjs +3 -3
  24. package/src/api/integration-block-exports.test.mjs +240 -0
  25. package/src/api/template-suffix.test.mjs +246 -0
  26. package/src/api/template.mjs +104 -28
  27. package/src/api/validate-integration.mjs +0 -8
  28. package/src/codemods/__tests__/registry.test.mjs +1 -0
  29. package/src/codemods/ensure-jscodeshift.mjs +11 -27
  30. package/src/codemods/registry.mjs +1 -0
  31. package/src/codemods/run-codemod.mjs +1 -1
  32. package/src/codemods/runner.mjs +2 -2
  33. package/src/codemods/transforms/v0.1.7/__tests__/migrate-table-tableprops-to-direct-props.test.mjs +120 -0
  34. package/src/codemods/transforms/v0.1.7/__tests__/rename-table-renderprops-styles-to-xstyle.test.mjs +112 -0
  35. package/src/codemods/transforms/v0.1.7/index.mjs +27 -0
  36. package/src/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +188 -0
  37. package/src/codemods/transforms/v0.1.7/rename-table-renderprops-styles-to-xstyle.mjs +197 -0
  38. package/src/commands/agent-docs.mjs +21 -8
  39. package/src/commands/agent-docs.test.mjs +31 -4
  40. package/src/commands/build-theme.mjs +10 -71
  41. package/src/commands/build.mjs +15 -15
  42. package/src/commands/component/index.mjs +4 -4
  43. package/src/commands/discover.mjs +7 -5
  44. package/src/commands/docs.mjs +4 -4
  45. package/src/commands/hook/index.mjs +4 -4
  46. package/src/commands/init.mjs +48 -152
  47. package/src/commands/init.next-steps.test.mjs +1 -1
  48. package/src/commands/interactive-guard.test.mjs +19 -22
  49. package/src/commands/json-contract.test.mjs +1 -1
  50. package/src/commands/layout.mjs +1 -1
  51. package/src/commands/search.mjs +4 -4
  52. package/src/commands/swizzle.mjs +11 -34
  53. package/src/commands/template.mjs +11 -31
  54. package/src/commands/upgrade.mjs +9 -6
  55. package/src/commands/upgrade.test.mjs +1 -1
  56. package/src/config.mjs +5 -14
  57. package/src/doc.mjs +27 -0
  58. package/src/doc.test.mjs +383 -0
  59. package/src/index.mjs +5 -6
  60. package/src/integration.mjs +4 -15
  61. package/src/lib/component-discovery.importpath.test.mjs +59 -0
  62. package/src/lib/component-discovery.mjs +15 -5
  63. package/src/lib/component-format.mjs +47 -14
  64. package/src/lib/component-format.test.mjs +95 -1
  65. package/src/lib/component-loader.mjs +104 -2
  66. package/src/lib/componentDocOverlay.test.mjs +111 -0
  67. package/src/lib/config-schema.mjs +0 -30
  68. package/src/lib/hook-format.mjs +8 -3
  69. package/src/lib/term-log.mjs +48 -0
  70. package/src/lib/xle/registry.mjs +0 -5
  71. package/src/schemas/doc-schema.mjs +226 -0
  72. package/src/schemas/template-schema.mjs +47 -0
  73. package/src/template.mjs +9 -67
  74. package/src/types/config.d.ts +11 -66
  75. package/src/types/doc.d.ts +23 -0
  76. package/src/types/integration.d.ts +7 -18
  77. package/src/types/template-api.d.ts +14 -50
  78. package/src/utils/package-manager.mjs +78 -0
  79. package/src/utils/package-manager.test.mjs +108 -1
  80. package/src/utils/path-safety.mjs +0 -18
  81. package/src/utils/update-check.mjs +2 -1
  82. package/templates/blocks/components/Avatar/AvatarGroup.tsx +5 -7
  83. package/templates/blocks/components/Avatar/AvatarShowcase.tsx +4 -6
  84. package/templates/blocks/components/Avatar/AvatarUserCard.tsx +3 -5
  85. package/templates/blocks/components/Avatar/AvatarWithImage.tsx +8 -6
  86. package/templates/blocks/components/Avatar/AvatarWithStatus.tsx +3 -5
  87. package/templates/blocks/components/ChatComposerInput/ChatComposerInputControlledInput.tsx +1 -1
  88. package/templates/blocks/components/ChatComposerInput/ChatComposerInputDisabled.tsx +1 -1
  89. package/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +1 -1
  90. package/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +1 -1
  91. package/templates/blocks/components/ChatComposerInput/ChatComposerInputShowcase.tsx +1 -1
  92. package/templates/blocks/components/ChatComposerInput/ChatComposerInputSlashCommands.tsx +1 -1
  93. package/templates/blocks/components/TabList/TabListTabsWithActions.doc.mjs +1 -1
  94. package/templates/blocks/components/TabList/TabListTabsWithActions.tsx +2 -7
  95. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.doc.mjs +14 -0
  96. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.tsx +41 -0
  97. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.doc.mjs +13 -0
  98. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.tsx +78 -0
  99. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.doc.mjs +14 -0
  100. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.tsx +38 -0
  101. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.doc.mjs +14 -0
  102. package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.tsx +47 -0
  103. package/templates/pages/ide/page.tsx +35 -41
  104. package/templates/pages/theme-showcase/page.tsx +7 -7
  105. package/templates/themes/neutral/neutralTheme.ts +63 -32
  106. package/src/utils/interactive.mjs +0 -76
  107. package/src/utils/interactive.test.mjs +0 -70
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @xds/cli
2
2
 
3
+ # 0.1.7
4
+
5
+ #### New Features
6
+
7
+ - Export the authoring factories from `@astryxdesign/core`: `createConfig` at `@astryxdesign/core/config` and `createIntegration`/`createPageTemplate`/`createBlockTemplate`/`createComponentDoc`/`createFunctionDoc`/`createDoc` at `@astryxdesign/core/authoring`. Authoring a config or integration no longer requires depending on the CLI. Existing `@astryxdesign/cli/*` imports keep working via re-export.
8
+ - Add the finalized doc-authoring API to `@astryxdesign/cli/doc`: `createComponentDoc`, `createFunctionDoc` (any function, including hooks), and `createDoc` (generic reference/topic docs). Each factory stamps a `type` discriminant and is validated at the load boundary against a matching per-kind schema. The legacy loose `export const docs = {...}` format keeps loading unchanged, and `.ts`-authored hook/function sources now derive their import path to a tree-shakeable subpath instead of the bare package root.
9
+ - New codemod for the Table `tableProps` deprecation: lifts object-literal `tableProps` keys into direct props on `<Table>`, keeps colliding or dynamic values in place with a TODO note. **Codemod:** `npx astryx upgrade --codemod migrate-table-tableprops-to-direct-props` (#3679)
10
+ - New docs topic `internationalization` covering how to localize astryx components, provide translation catalogs, override default strings, coexist with existing i18n libraries (react-intl, i18next, next-intl), swap languages at runtime, and validate coverage with the shipped pseudo locale. Run `npx astryx docs internationalization` or read it at https://astryx.atmeta.com/docs/internationalization.
11
+ - template: accept `.template.{ts,mjs,js}` as the canonical suffix for template-spec files, alongside the legacy `.doc.*` suffix. Template specs export `createBlockTemplate`/`createPageTemplate` — a scaffoldable template, not documentation — so they now get a descriptive name. Core, external-package, and integration discovery (`findShowcase`, `--blocks`, `astryx template <id>` scaffolding) all treat `Foo.template.ts` identically to a legacy `Foo.doc.mjs`; same-stem `.tsx` source resolves for either suffix, and `.template.ts` authoring is loaded via jiti. Additive only — no existing files are renamed.
12
+
13
+ #### Fixes
14
+
15
+ - Translated component docs no longer drop props
16
+ A `docsZh` / `docsDense` block that carried its own `props` array replaced the English component doc **wholesale** rather than overlaying it, so any prop the translation had not caught up with simply ceased to exist. `astryx component Button --zh` silently omitted `isInterruptible` and `isIconOnly`; ten components were affected, including `MobileNav`, `Popover` and `Stack` through the multi-component `components[]` shape.
17
+ - Anchor --dense / --zh doc overlays to their base sections (#2182)
18
+ The compressed and translated reference docs were merged into the base doc **by array position**, so an overlay whose sections were ordered differently — or which omitted one — grafted every title onto the wrong body.
19
+ - template: inline full demo-image URLs in the Avatar blocks and theme-showcase page so scaffolding strips them to a clean placeholder. Templates that stored only the CDN base in a `const` and appended the filename via interpolation (`` `${CDN}/File.png` ``) previously scaffolded a malformed `src` — the placeholder data URI with the filename glued onto the end — plus a dead `const CDN = 'data:…'`. (#4027)
20
+
21
+ #### Documentation
22
+
23
+ - Document the minimal `package.json#exports` recipe an integration needs so its block templates are importable by a bundler-resolution consumer and type-check under `moduleResolution: bundler`: `"./templates/*.tsx": "./templates/*.tsx"` plus an extensionful `import('@acme/widgets/templates/…/…Showcase.tsx')`. Adds `packages/cli/docs/integration-authoring.md` and a fixture test proving the recipe against the repo's own `tsc` and `esbuild`.
24
+
25
+ #### Contributors
26
+
27
+ Thanks to everyone who contributed to this release:
28
+
29
+ - @AKnassa
30
+ - @ejhammond
31
+ - @imdreamrunner
32
+ - @nynexman4464
33
+
34
+ ---
35
+
3
36
  # 0.1.6
4
37
 
5
38
  ---
package/README.md CHANGED
@@ -2,15 +2,19 @@
2
2
 
3
3
  The CLI is the primary interface for working with the design system, for humans and machines alike. It provides component documentation, design tokens, page templates, theming tools, and upgrade codemods, all accessible via terminal commands, a typed JSON API, or programmatic imports. AI agents and build tools use the same API that powers the CLI, enabling end-to-end frontend development loops.
4
4
 
5
+ Run it one-off with the scoped package (works whether or not it's installed):
6
+
5
7
  ```bash
6
- npx astryx --help
7
- npx astryx search button
8
- npx astryx component Button
9
- npx astryx docs tokens
10
- npx astryx docs migration
11
- npx astryx template --list
8
+ npx @astryxdesign/cli --help
9
+ npx @astryxdesign/cli search button
10
+ npx @astryxdesign/cli component Button
11
+ npx @astryxdesign/cli docs tokens
12
+ npx @astryxdesign/cli docs migration
13
+ npx @astryxdesign/cli template --list
12
14
  ```
13
15
 
16
+ Once it's a project dependency (`npm install -D @astryxdesign/cli`), drop the scope and use the shorter `astryx` — e.g. `npx astryx component Button` or `pnpm exec astryx component Button`. Bare `astryx` resolves to an unrelated npm package until the CLI is installed, so prefer the scoped form above for first-run/one-off use.
17
+
14
18
  ## Finding things: `astryx search`
15
19
 
16
20
  When you don't know whether what you need is a component, a hook, a docs topic,
@@ -20,27 +24,29 @@ fuzzy matching for typos) and tagged with their domain plus the follow-up
20
24
  command to run:
21
25
 
22
26
  ```bash
23
- $ npx astryx search button
27
+ $ astryx search button
24
28
 
25
29
  Results for "button" (20):
26
30
 
27
31
  [component] Button
28
32
  Button triggers an action when clicked. Use it for form submissions…
29
- npx astryx component Button
33
+ → astryx component Button
30
34
 
31
35
  [component] IconButton
32
36
  A button that shows only an icon with no visible text…
33
- npx astryx component IconButton
37
+ → astryx component IconButton
34
38
 
35
39
  [hook] useClickableContainer
36
40
  Makes a container element clickable while preserving nested…
37
- npx astryx hook useClickableContainer
41
+ → astryx hook useClickableContainer
38
42
 
39
43
  [template] Banner — Collapsible
40
44
  Combine an action button, dismiss control, and expandable detail area…
41
- npx astryx template BannerCollapsibleContent
45
+ → astryx template BannerCollapsibleContent
42
46
  ```
43
47
 
48
+ (The CLI prints the follow-up commands with your actual runner — `npx astryx …` when installed, or `npx @astryxdesign/cli …` when run one-off.)
49
+
44
50
  Options:
45
51
 
46
52
  - `--type <component|hook|doc|template>`: restrict to a single domain
@@ -415,7 +421,7 @@ failures (warnings are fine) and `1` when any check fails. That makes it
415
421
  usable directly as a CI step:
416
422
 
417
423
  ```yaml
418
- - run: npx astryx doctor
424
+ - run: npx @astryxdesign/cli doctor
419
425
  ```
420
426
 
421
427
  Use `--json` for a structured envelope (`{ apiVersion, type: "doctor",
@@ -423,13 +429,103 @@ data: { checks, summary } }`) that AI agents and scripts can parse.
423
429
 
424
430
  ## Configuration
425
431
 
426
- The CLI reads from an optional `astryx.config.mjs` in your project root:
432
+ The CLI reads an optional `astryx.config.{ts,mjs,js}` from your project root
433
+ (a sibling of `package.json`). Every field is optional; with no config file the
434
+ CLI runs on defaults.
427
435
 
428
- ```javascript
429
- export default {
430
- templates: {
431
- get: async id => fetchTemplateFromAPI(id),
432
- },
436
+ ```typescript
437
+ import {createConfig} from '@astryxdesign/core/config';
438
+
439
+ export default createConfig({
440
+ integrations: ['@acme/astryx-widgets'],
433
441
  issuesUrl: 'https://github.com/your-org/your-repo/issues',
434
- };
442
+ });
443
+ ```
444
+
445
+ `createConfig` is a type-preserving helper: it returns its argument unchanged
446
+ and exists only to give the config file editor autocomplete and type-checking. A
447
+ plain `export default {}` object works identically. It's exported from
448
+ `@astryxdesign/core` (not the CLI) so your config file gets type feedback
449
+ without depending on the CLI; the same helper is re-exported from
450
+ `@astryxdesign/cli/config` for back-compat.
451
+
452
+ | Field | Type | Purpose |
453
+ | ----------------------------- | ------------------------------ | ----------------------------------------------------------------------------------------------- |
454
+ | `integrations` | `string[]` | Integration package names to load (see [Integrations](#integrations)). |
455
+ | `issuesUrl` | `string` | Where "report an issue" links point for your project. Defaults to the core issue tracker. |
456
+ | `hooks.postCodemod` | `PostCodemodHook[]` | Commands to run after `astryx upgrade` applies codemods (e.g. reinstall, rebuild, reformat). |
457
+ | `experimental.xle.components` | `Record<string, XleComponent>` | Register app-local components so layout (XLE) expressions can reference them by name. Unstable. |
458
+
459
+ The config is validated against a strict schema when the CLI loads it, so an
460
+ unknown field is a hard error rather than a silent no-op. `astryx doctor`
461
+ reports whether the config loads cleanly.
462
+
463
+ ## Integrations
464
+
465
+ An **integration** is any npm package that contributes its own components,
466
+ templates, and upgrade codemods to Astryx. The CLI surfaces them next to core's,
467
+ through the same commands, so a consumer can `astryx component`,
468
+ `astryx template`, and `astryx upgrade` across core and every integration
469
+ uniformly. Use it to ship a first-party add-on, publish a third-party component
470
+ library, or share an internal design-system package across apps.
471
+
472
+ The system runs on two files, each with a small typed API:
473
+
474
+ | File | Written by | Role |
475
+ | -------------------------------- | ---------- | ----------------------------------------- |
476
+ | `astryx.config.{ts,mjs,js}` | Consumer | Lists which integration packages to load. |
477
+ | `astryx.integration.{ts,mjs,js}` | Author | Declares what a package contributes. |
478
+
479
+ The consumer side is the `integrations` field of [`astryx.config`](#configuration).
480
+ The author side is the integration manifest below.
481
+
482
+ ### The integration manifest
483
+
484
+ A package becomes an integration by exporting a manifest from
485
+ `astryx.integration.{ts,mjs,js}` at its root (a sibling of `package.json`). The
486
+ manifest points at where each kind of contribution lives; identity (name,
487
+ version) comes from `package.json`, not the manifest.
488
+
489
+ ```typescript
490
+ import {createIntegration} from '@astryxdesign/core/authoring';
491
+
492
+ export default createIntegration({
493
+ components: './components',
494
+ templates: './templates',
495
+ codemods: './codemods',
496
+ issuesUrl: 'https://github.com/acme/widgets/issues',
497
+ });
498
+ ```
499
+
500
+ | Field | Type | Purpose |
501
+ | ------------ | -------- | --------------------------------------------------------------------- |
502
+ | `components` | `string` | Directory holding the package's components and their `.doc.*` files. |
503
+ | `templates` | `string` | Directory holding the package's page/block templates. |
504
+ | `codemods` | `string` | Directory holding upgrade codemods run by `astryx upgrade`. |
505
+ | `issuesUrl` | `string` | Where "report an issue" links for this package's contributions point. |
506
+
507
+ Every field is optional; declare only the roots the package ships.
508
+ `createIntegration` is a type-preserving helper (editor autocomplete and
509
+ type-checking); it lives in `@astryxdesign/core/authoring` and is re-exported
510
+ from `@astryxdesign/cli/integration` for back-compat.
511
+
512
+ ### How it works
513
+
514
+ Every command loads the consumer's `astryx.config`, resolves each listed
515
+ integration's manifest from `node_modules`, and discovers its contributions.
516
+ Everything is validated against one strict schema at the load boundary, so the
517
+ CLI presents core and integration contributions through a single, uniform
518
+ surface.
519
+
520
+ Discovery is resilient: a broken or misconfigured integration is skipped with a
521
+ one-line warning on stderr instead of crashing the CLI, and it never corrupts a
522
+ `--json` envelope. To inspect problems, run
523
+ `astryx validate-integration <package>` for a detailed report on one package, or
524
+ `astryx doctor` for an overall health check.
525
+
526
+ For the full authoring walkthrough (component doc format, template packaging
527
+ and `exports` requirements, and codemod authoring), see the guide:
528
+
529
+ ```bash
530
+ astryx docs cli-integrations
435
531
  ```
@@ -0,0 +1,150 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('../../core/src/docs-types').ReferenceDoc} */
4
+
5
+ export const docs = {
6
+ name: 'cli-integrations',
7
+ title: 'CLI Integrations',
8
+ category: 'guide',
9
+ description:
10
+ 'Author an npm package that contributes components, templates, and upgrade codemods to Astryx.',
11
+
12
+ sections: [
13
+ {
14
+ title: 'Overview',
15
+ category: 'guide',
16
+ content: [
17
+ {
18
+ type: 'prose',
19
+ text: 'An integration is an npm package that contributes components, templates, and/or upgrade codemods to a consumer\u2019s design-system workflow. Consumers install the package and add it to their `astryx.config`; from then on the integration\u2019s contributions show up alongside core\u2019s in the same CLI commands.',
20
+ },
21
+ {
22
+ type: 'prose',
23
+ text: 'The system runs on two files. The consumer writes `astryx.config.{ts,mjs,js}` at their project root to list which packages to load. The author writes `astryx.integration.{ts,mjs,js}` at the package root to declare what the package contributes. This page is the author\u2019s guide. For the consumer side, run `npx astryx docs getting-started`.',
24
+ },
25
+ {
26
+ type: 'prose',
27
+ text: 'On the consumer side, adding your package is one line:',
28
+ },
29
+ {
30
+ type: 'code',
31
+ lang: 'typescript',
32
+ code: "import {createConfig} from '@astryxdesign/core/config';\n\nexport default createConfig({\n integrations: ['@acme/astryx-widgets'],\n});",
33
+ },
34
+ {
35
+ type: 'prose',
36
+ text: 'Your components and templates then appear next to core\u2019s:',
37
+ },
38
+ {
39
+ type: 'code',
40
+ lang: 'bash',
41
+ code: 'astryx component --list --package @acme/astryx-widgets\nastryx component AcmeCarousel --props',
42
+ },
43
+ ],
44
+ },
45
+ {
46
+ title: 'The Integration File',
47
+ category: 'guide',
48
+ content: [
49
+ {
50
+ type: 'prose',
51
+ text: 'To register your package as an integration, add an `astryx.integration.{ts,mjs,js}` file as a sibling of your `package.json`. It tells the CLI where to find your components, templates, and codemods. Identity (name, version) comes from your `package.json`, not this file.',
52
+ },
53
+ {
54
+ type: 'code',
55
+ lang: 'typescript',
56
+ code: "// astryx.integration.ts\nimport {createIntegration} from '@astryxdesign/core/authoring';\n\nexport default createIntegration({\n components: './components',\n templates: './templates',\n codemods: './codemods',\n issuesUrl: 'https://github.com/acme/widgets/issues',\n});",
57
+ },
58
+ {
59
+ type: 'prose',
60
+ text: 'Every field is optional. Declare only the contribution roots your package ships. `createIntegration` is a type-preserving helper for editor autocomplete and type-checking. It lives in `@astryxdesign/core/authoring` and is also re-exported from `@astryxdesign/cli/integration` for back-compat.',
61
+ },
62
+ ],
63
+ },
64
+ {
65
+ title: 'Components',
66
+ category: 'guide',
67
+ content: [
68
+ {
69
+ type: 'prose',
70
+ text: 'Export your components from your library however you like, and consumers still import them from your package. For each component the CLI should document, ship a `.doc.{ts,mjs,js}` file with the same stem, for example `AcmeCarousel.tsx` alongside `AcmeCarousel.doc.ts`.',
71
+ },
72
+ {
73
+ type: 'code',
74
+ lang: 'typescript',
75
+ code: "// AcmeCarousel.doc.ts\nimport {createComponentDoc} from '@astryxdesign/core/authoring';\n\nexport default createComponentDoc({\n name: 'AcmeCarousel',\n description: 'A carousel that cycles through slides.',\n // props, usage, examples, ...\n});",
76
+ },
77
+ ],
78
+ },
79
+ {
80
+ title: 'Templates',
81
+ category: 'guide',
82
+ content: [
83
+ {
84
+ type: 'prose',
85
+ text: 'Templates are usually not exported from the package directly. Instead, consumers browse them through the CLI and materialize them into their app. Define a template with `createPageTemplate` (full pages) or `createBlockTemplate` (smaller chunks) in a `.template.{ts,mjs,js}` file next to the source, for example `AcmeLandingPage.tsx` and `AcmeLandingPage.template.ts`.',
86
+ },
87
+ {
88
+ type: 'code',
89
+ lang: 'typescript',
90
+ code: "// AcmeLandingPage.template.ts\nimport {createPageTemplate} from '@astryxdesign/core/authoring';\n\nexport default createPageTemplate({\n // name, description, preview, ...\n});",
91
+ },
92
+ {
93
+ type: 'prose',
94
+ text: 'The CLI needs the template source at consume time, so make sure it is included in your published package. This is typically done via the `exports` key in `package.json`. It also lets the docsite render template previews in the future.',
95
+ },
96
+ {
97
+ type: 'code',
98
+ lang: 'jsonc',
99
+ code: '{\n "exports": {\n // ...\n "./templates/*.tsx": "./templates/*.tsx"\n }\n}',
100
+ },
101
+ {
102
+ type: 'prose',
103
+ text: 'To verify it resolves, try importing the template component with its `.tsx` extension. An extensionless specifier will not resolve under `moduleResolution: bundler`, and the extensionful export above is what lets this type-check without consumers enabling `allowImportingTsExtensions`.',
104
+ },
105
+ {
106
+ type: 'code',
107
+ lang: 'typescript',
108
+ code: "import('@acme/astryx-widgets/templates/AcmeLandingPage.tsx');",
109
+ },
110
+ ],
111
+ },
112
+ {
113
+ title: 'Codemods',
114
+ category: 'guide',
115
+ content: [
116
+ {
117
+ type: 'prose',
118
+ text: 'Ship codemods so `astryx upgrade` can migrate consumers across breaking changes in your package. Point the integration file\u2019s `codemods` field at your codemods root, and author each one with `createCodemod` (transforms source files) or `createConfigCodemod` (rewrites the consumer\u2019s `astryx.config`).',
119
+ },
120
+ {
121
+ type: 'code',
122
+ lang: 'typescript',
123
+ code: "// codemods/v2-rename-prop.ts\nimport {createCodemod} from '@astryxdesign/cli/codemod';\n\nexport default createCodemod({\n // version, description, transform, ...\n});",
124
+ },
125
+ {
126
+ type: 'prose',
127
+ text: 'The codemod helpers live in `@astryxdesign/cli/codemod`, not `@astryxdesign/core/authoring` like the doc, integration, and template helpers. Consumers can also run their own post-codemod hooks, such as a reinstall or rebuild, via `hooks.postCodemod` in their `astryx.config`.',
128
+ },
129
+ ],
130
+ },
131
+ {
132
+ title: 'How It Works',
133
+ category: 'guide',
134
+ content: [
135
+ {
136
+ type: 'prose',
137
+ text: 'Every CLI command loads the consumer\u2019s `astryx.config`, resolves each listed integration\u2019s manifest from `node_modules`, and discovers its contributions. Everything is validated against one strict schema at the load boundary. The `create*` helpers do not validate. They are identity functions whose value is their TypeScript surface, so validation happens when the CLI loads the file, not when you author it.',
138
+ },
139
+ {
140
+ type: 'prose',
141
+ text: 'Discovery is resilient. A broken or misconfigured integration is skipped with a single non-blocking warning on stderr instead of crashing the CLI, and it never corrupts a `--json` stdout envelope. Everyday commands keep working with the remaining valid contributions.',
142
+ },
143
+ {
144
+ type: 'prose',
145
+ text: 'To inspect problems, run `astryx validate-integration <package>` for a detailed report on one package, or `astryx doctor` for an overall health check of the setup.',
146
+ },
147
+ ],
148
+ },
149
+ ],
150
+ };
@@ -21,7 +21,7 @@ export const docs = {
21
21
  type: 'code',
22
22
  lang: 'text',
23
23
  label: 'Paste this into your AI',
24
- code: 'Install @astryxdesign/core, @astryxdesign/theme-neutral, and @astryxdesign/cli in this project. Run `npx astryx init` to set up agent docs. Read the generated files to learn the conventions.',
24
+ code: 'Install @astryxdesign/core, @astryxdesign/theme-neutral, and @astryxdesign/cli in this project, then run `npx @astryxdesign/cli init` to set up agent docs. Read the generated files to learn the conventions.',
25
25
  },
26
26
  ],
27
27
  },
@@ -40,7 +40,7 @@ export const docs = {
40
40
  },
41
41
  {
42
42
  type: 'prose',
43
- text: 'Then run the init wizard to set up AI agent docs, pick a starter template, and learn about theming.',
43
+ text: "Then run `astryx init` to install the AI agent cheat sheet (AGENTS.md/CLAUDE.md). It's non-interactive — no prompts — so it's safe for AI agents, CI, and scripts. Add `--all` for pointers to the theme and page-building workflows.",
44
44
  },
45
45
  {
46
46
  type: 'code',
@@ -67,11 +67,11 @@ export const docs = {
67
67
  },
68
68
  {
69
69
  type: 'prose',
70
- text: 'Available themes: @astryxdesign/theme-neutral (muted minimal, a good starting point), @astryxdesign/theme-butter, @astryxdesign/theme-chocolate, @astryxdesign/theme-gothic (dark-only), @astryxdesign/theme-matcha, @astryxdesign/theme-stone, and @astryxdesign/theme-y2k. See `npx astryx docs theme` for the full theming guide.',
70
+ text: 'Available themes: @astryxdesign/theme-neutral (muted minimal, a good starting point), @astryxdesign/theme-butter, @astryxdesign/theme-chocolate, @astryxdesign/theme-gothic (dark-only), @astryxdesign/theme-matcha, @astryxdesign/theme-stone, and @astryxdesign/theme-y2k. See `astryx docs theme` for the full theming guide.',
71
71
  },
72
72
  {
73
73
  type: 'prose',
74
- text: 'These stylesheets are cascade-layered: the reset loads in @layer reset and component styles in @layer astryx-base. If your project has existing global CSS, a legacy reset, or Tailwind, declare the layer order explicitly and assign every stylesheet to a layer deliberately: unlayered styles and later layers both override astryx-base regardless of specificity. See the Cascade Layer Safety section in `npx astryx docs migration` before building screens.',
74
+ text: 'These stylesheets are cascade-layered: the reset loads in @layer reset and component styles in @layer astryx-base. If your project has existing global CSS, a legacy reset, or Tailwind, declare the layer order explicitly and assign every stylesheet to a layer deliberately: unlayered styles and later layers both override astryx-base regardless of specificity. See the Cascade Layer Safety section in `astryx docs migration` before building screens.',
75
75
  },
76
76
  ],
77
77
  },
@@ -172,11 +172,11 @@ pnpm dev`,
172
172
  type: 'code',
173
173
  lang: 'bash',
174
174
  label: 'Terminal',
175
- code: `npx astryx component # list all components
176
- npx astryx component Button # props, usage, theming for Button
177
- npx astryx docs # list all doc topics
178
- npx astryx template --list # available page templates
179
- npx astryx docs tokens # spacing, color, radius reference`,
175
+ code: `astryx component # list all components
176
+ astryx component Button # props, usage, theming for Button
177
+ astryx docs # list all doc topics
178
+ astryx template --list # available page templates
179
+ astryx docs tokens # spacing, color, radius reference`,
180
180
  },
181
181
  ],
182
182
  },
@@ -0,0 +1,243 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('../../core/src/docs-types').ReferenceDoc} */
4
+
5
+ export const docs = {
6
+ name: 'internationalization',
7
+ title: 'Internationalization',
8
+ category: 'guide',
9
+ description:
10
+ 'Localize astryx component strings, provide translation catalogs, override default text, coexist with your own i18n library, swap languages at runtime, and test translations with the pseudo locale.',
11
+
12
+ sections: [
13
+ {
14
+ title: 'Quick Start',
15
+ category: 'guide',
16
+ content: [
17
+ {
18
+ type: 'prose',
19
+ text: 'Internationalization ships with `@astryxdesign/core`. There is nothing to install. Wrap your app in `<InternationalizationProvider>` and set a `locale`, and astryx components pick up localized strings automatically.',
20
+ },
21
+ {
22
+ type: 'code',
23
+ lang: 'tsx',
24
+ label: 'Wrap your app',
25
+ code: `import {InternationalizationProvider} from '@astryxdesign/core';
26
+
27
+ function App() {
28
+ return (
29
+ <InternationalizationProvider locale="en">
30
+ <YourApp />
31
+ </InternationalizationProvider>
32
+ );
33
+ }`,
34
+ },
35
+ {
36
+ type: 'code',
37
+ lang: 'tsx',
38
+ label: 'Read strings inside a component',
39
+ code: `import {useTranslator} from '@astryxdesign/core';
40
+
41
+ function SaveButton() {
42
+ const t = useTranslator();
43
+ return <button>{t('@myapp.actions.save')}</button>;
44
+ }`,
45
+ },
46
+ {
47
+ type: 'prose',
48
+ text: 'The hook is available to consumer components too, but using it is entirely optional: many teams keep their app strings on their existing i18n library (react-intl, i18next, next-intl, LinguiJS) and only use `useTranslator` when reading astryx keys. If you do route your own strings through it, we recommend namespacing them (`@myapp.*` or your npm scope) to keep them separated from `@astryx.*`, but this is a convention, not a requirement; the resolver treats every key as an opaque string.',
49
+ },
50
+ {
51
+ type: 'prose',
52
+ text: "Astryx ships translations only for English today. First-party translations for other locales are on the roadmap; track https://github.com/facebook/astryx/issues/3641. In the meantime, if you want astryx UI translated into another locale, you can ship your own catalog through the `messages` prop (covered in the next section). If you're using `useTranslator` for your own strings, you'll want to ship your own catalog either way, since astryx only carries the fallback for `@astryx.*` keys, not the ones you author.",
53
+ },
54
+ ],
55
+ },
56
+ {
57
+ title: 'Providing locale catalogs',
58
+ category: 'guide',
59
+ content: [
60
+ {
61
+ type: 'prose',
62
+ text: 'Astryx bundles only the English catalog today. To render in any other locale, provide a translation catalog through the `messages` prop and set `locale` accordingly. This matches how MUI, Ant Design, and AG Grid work: the consumer app supplies the catalogs it actually needs so unused translations stay out of the bundle.',
63
+ },
64
+ {
65
+ type: 'code',
66
+ lang: 'tsx',
67
+ label: 'Add French',
68
+ code: `import {InternationalizationProvider} from '@astryxdesign/core';
69
+ import fr from './locales/astryx/fr.json';
70
+
71
+ <InternationalizationProvider locale="fr" messages={{fr}}>
72
+ <App />
73
+ </InternationalizationProvider>;`,
74
+ },
75
+ {
76
+ type: 'prose',
77
+ text: "See `@astryxdesign/core/locales/en.json` for the full inventory of keys to translate. Copy it as the starting point: every key you translate replaces the English default; anything you omit falls back through the locale chain to English (e.g. `pt-BR` walks to `pt` then to shipped `en`), so a partial translation renders as a mix rather than empty text or raw key names.",
78
+ },
79
+ {
80
+ type: 'prose',
81
+ text: 'A community-maintained set of astryx translations is on the roadmap but not shipped yet. For now, consumer apps that ship in multiple languages own their astryx catalogs alongside their app catalogs. Contributions to a first-party set are welcome; track discussion at https://github.com/facebook/astryx/issues/3641.',
82
+ },
83
+ ],
84
+ },
85
+ {
86
+ title: "Overriding astryx's default text",
87
+ category: 'guide',
88
+ content: [
89
+ {
90
+ type: 'prose',
91
+ text: 'Use `overrides` to change individual strings without shipping a full catalog. Overrides are keyed by locale and merged on top of the built-in and user-supplied catalogs.',
92
+ },
93
+ {
94
+ type: 'code',
95
+ lang: 'tsx',
96
+ label: 'Change one string in English',
97
+ code: `<InternationalizationProvider
98
+ locale="en"
99
+ overrides={{en: {'@astryx.pagination.next': 'Next →'}}}
100
+ >
101
+ <App />
102
+ </InternationalizationProvider>`,
103
+ },
104
+ {
105
+ type: 'prose',
106
+ text: 'Overrides win over both bundled English and any `messages` catalog for the same key. Use them for brand voice tweaks or one-off wording changes.',
107
+ },
108
+ ],
109
+ },
110
+ {
111
+ title: 'Using astryx with your own i18n library',
112
+ category: 'guide',
113
+ content: [
114
+ {
115
+ type: 'prose',
116
+ text: "Astryx components render astryx strings through astryx's provider. Consumer components render consumer strings through whatever i18n library you already use: react-intl, i18next, next-intl, LinguiJS, and so on. The two systems coexist and read from the same source of truth for the active locale.",
117
+ },
118
+ {
119
+ type: 'code',
120
+ lang: 'tsx',
121
+ label: 'Astryx + react-intl side by side',
122
+ code: `import {InternationalizationProvider} from '@astryxdesign/core';
123
+ import {Selector} from '@astryxdesign/core/Selector';
124
+ import {Button} from '@astryxdesign/core/Button';
125
+ import {FormattedMessage, IntlProvider, useIntl} from 'react-intl';
126
+ import astryxFr from './locales/astryx/fr.json'; // astryx's UI, in French
127
+ import appFr from './locales/app/fr.json'; // your app strings, in French
128
+
129
+ function Pricing() {
130
+ // Consumer strings — resolved by react-intl.
131
+ const intl = useIntl();
132
+
133
+ return (
134
+ <section>
135
+ <h1><FormattedMessage id="pricing.heading" /></h1>
136
+
137
+ {/* Astryx Selector — trigger placeholder, search-box placeholder,
138
+ clear-button aria-label all resolved by
139
+ <InternationalizationProvider>. Options come from react-intl. */}
140
+ <Selector
141
+ label={intl.formatMessage({id: 'pricing.region.label'})}
142
+ options={[
143
+ {value: 'na', label: intl.formatMessage({id: 'pricing.region.na'})},
144
+ {value: 'eu', label: intl.formatMessage({id: 'pricing.region.eu'})},
145
+ ]}
146
+ hasSearch
147
+ hasClear
148
+ />
149
+
150
+ <Button label={intl.formatMessage({id: 'pricing.cta.subscribe'})} />
151
+ </section>
152
+ );
153
+ }
154
+
155
+ export default function App() {
156
+ return (
157
+ // Same locale, two providers reading their own catalogs.
158
+ <IntlProvider locale="fr" messages={appFr}>
159
+ <InternationalizationProvider locale="fr" messages={{fr: astryxFr}}>
160
+ <Pricing />
161
+ </InternationalizationProvider>
162
+ </IntlProvider>
163
+ );
164
+ }`,
165
+ },
166
+ {
167
+ type: 'prose',
168
+ text: 'Keep the two providers in sync on locale, and each library owns its own catalog. Astryx never sees your app strings, and your i18n library never sees astryx internals. Runtime locale swap works the same way: re-render both providers with a new `locale` prop and the whole tree updates live.',
169
+ },
170
+ {
171
+ type: 'prose',
172
+ text: "Single-catalog usage (where an external i18n runtime like react-intl or i18next resolves both your app strings AND astryx's strings through one provider) is on the roadmap via a `Translator` adapter. Track https://github.com/facebook/astryx/issues/4029. For now, run the two providers side by side as shown above.",
173
+ },
174
+ ],
175
+ },
176
+ {
177
+ title: 'Runtime language swap',
178
+ category: 'guide',
179
+ content: [
180
+ {
181
+ type: 'prose',
182
+ text: 'Re-render `<InternationalizationProvider>` with a new `locale` prop and every astryx string updates live. No reload, no separate API call.',
183
+ },
184
+ {
185
+ type: 'code',
186
+ lang: 'tsx',
187
+ label: 'Toggle between locales',
188
+ code: `const [locale, setLocale] = useState<'en' | 'fr'>('en');
189
+
190
+ <InternationalizationProvider locale={locale} messages={{fr}}>
191
+ <Button
192
+ label={locale === 'en' ? 'Français' : 'English'}
193
+ onClick={() => setLocale(l => (l === 'en' ? 'fr' : 'en'))}
194
+ />
195
+ <App />
196
+ </InternationalizationProvider>;`,
197
+ },
198
+ {
199
+ type: 'prose',
200
+ text: "Persisting the user's choice (localStorage, cookie, URL segment, account setting) is up to the consumer. Astryx reads whatever `locale` you pass in.",
201
+ },
202
+ ],
203
+ },
204
+ {
205
+ title: 'Testing your translations',
206
+ category: 'guide',
207
+ content: [
208
+ {
209
+ type: 'prose',
210
+ text: 'Astryx generates a `pseudo` locale that wraps every string in `⟦…⟧` and replaces letters with accented look-alikes. Switching to it in development instantly reveals any astryx string that isn\'t going through the translator, plus any layout that breaks under longer text.',
211
+ },
212
+ {
213
+ type: 'code',
214
+ lang: 'tsx',
215
+ label: 'Turn on pseudo-localization',
216
+ code: `import pseudo from '@astryxdesign/core/locales/pseudo.json';
217
+
218
+ <InternationalizationProvider locale="pseudo" messages={{pseudo}}>
219
+ <App />
220
+ </InternationalizationProvider>;`,
221
+ },
222
+ {
223
+ type: 'prose',
224
+ text: 'Any bare English text you still see on screen is a hardcoded string that needs to be routed through `useTranslator`.',
225
+ },
226
+ {
227
+ type: 'prose',
228
+ text: "Pseudoloc also has a subtle caveat worth knowing: the pseudo catalog is complete (astryx generates it from every shipped key), so a component using an astryx-shipped key will always render its pseudo version. Your handwritten translation catalogs, on the other hand, only cover the keys you translated; anything missing falls back to English. That means \"looks perfect in pseudo\" is not the same guarantee as \"looks perfect in French.\" Check each real locale by hand for coverage gaps.",
229
+ },
230
+ ],
231
+ },
232
+ {
233
+ title: 'For contributors',
234
+ category: 'guide',
235
+ content: [
236
+ {
237
+ type: 'prose',
238
+ text: "Astryx's own strings live in `packages/core/locales/en.json`. New user-facing strings must go through `useTranslator`; this is enforced by the `@astryx/no-hardcoded-i18n-string` ESLint rule. See the AI contribution guide for the alias-and-resolve pattern used when adding new keys.",
239
+ },
240
+ ],
241
+ },
242
+ ],
243
+ };