@astryxdesign/cli 0.6.6-canary.e1dda17 → 0.6.6-canary.ee02ce2

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 (68) hide show
  1. package/README.md +83 -83
  2. package/api/build/_adapter.d.mts +15 -0
  3. package/api/build/_adapter.mjs +22 -0
  4. package/api/build/build.doc.mjs +1 -1
  5. package/api/build/build.type.d.mts +4 -0
  6. package/api/build/build.type.mjs +1 -0
  7. package/api/build/help/help.mjs +1 -1
  8. package/api/build/kit/kit.mjs +12 -1
  9. package/api/doctor/_adapter.d.mts +7 -0
  10. package/api/doctor/_adapter.mjs +48 -0
  11. package/api/doctor/doctor.mjs +5 -3
  12. package/api/doctor/theme-checks.d.mts +12 -0
  13. package/api/doctor/theme-checks.mjs +115 -1
  14. package/api/doctor/theme-checks.test.mjs +142 -1
  15. package/api/init/run/run.mjs +1 -0
  16. package/api/layout/check/check.d.mts +1 -0
  17. package/api/layout/check/check.mjs +1 -0
  18. package/api/layout/expand/expand.d.mts +1 -0
  19. package/api/layout/expand/expand.mjs +1 -0
  20. package/api/layout/grammar/grammar.d.mts +1 -0
  21. package/api/layout/grammar/grammar.mjs +1 -0
  22. package/api/layout/layoutCheck.doc.mjs +1 -1
  23. package/api/layout/layoutExpand.doc.mjs +1 -1
  24. package/api/layout/layoutGrammar.doc.mjs +1 -1
  25. package/api/template/copy/copy.mjs +12 -0
  26. package/api/template/template.doc.mjs +1 -1
  27. package/api/template/template.type.d.mts +3 -0
  28. package/api/template/template.type.mjs +3 -0
  29. package/api/theme/build/build.d.mts +70 -0
  30. package/api/theme/build/build.mjs +205 -41
  31. package/api/theme/build/font-warning.d.mts +11 -0
  32. package/api/theme/build/font-warning.mjs +28 -3
  33. package/assets/docs/author-a-theme.doc.mjs +4 -4
  34. package/assets/docs/styling-overview.doc.mjs +211 -0
  35. package/assets/docs/theme.doc.dense.mjs +1 -1
  36. package/assets/docs/theme.doc.mjs +5 -5
  37. package/assets/docs/theme.doc.zh.mjs +1 -1
  38. package/assets/docs/use-a-theme.doc.mjs +159 -47
  39. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -1
  40. package/authoring/doctypes/template/type.ts +1 -0
  41. package/clients/cli/commands/build-theme.adaptations.test.mjs +1 -1
  42. package/clients/cli/commands/build-theme.ascii-output.test.mjs +11 -1
  43. package/clients/cli/commands/build-theme.batch-report.test.mjs +335 -0
  44. package/clients/cli/commands/build-theme.font-warning.test.mjs +36 -7
  45. package/clients/cli/commands/build-theme.import-path.test.mjs +3 -3
  46. package/clients/cli/commands/build-theme.mjs +68 -18
  47. package/clients/cli/commands/build-theme.watch.test.mjs +33 -0
  48. package/clients/cli/commands/build.mjs +1 -0
  49. package/clients/cli/commands/docs.test.mjs +1 -1
  50. package/clients/cli/commands/doctor.doc.mjs +1 -1
  51. package/clients/cli/commands/import-hint-correctness.test.mjs +23 -0
  52. package/clients/cli/commands/layout-check.doc.mjs +1 -0
  53. package/clients/cli/commands/layout-expand.doc.mjs +1 -0
  54. package/clients/cli/commands/layout-grammar.doc.mjs +1 -0
  55. package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +140 -0
  56. package/clients/cli/commands/layout.doc.mjs +1 -0
  57. package/clients/cli/commands/layout.mjs +6 -11
  58. package/clients/cli/commands/template.mjs +4 -3
  59. package/clients/cli/commands/theme-build.doc.mjs +3 -1
  60. package/clients/cli/index.mjs +1 -1
  61. package/clients/cli/lib/define-command.mjs +4 -0
  62. package/foundation/agent-docs/agent-docs.mjs +4 -1
  63. package/foundation/agent-docs/agent-docs.test.mjs +18 -0
  64. package/foundation/discovery/template-needs.d.mts +31 -0
  65. package/foundation/discovery/template-needs.mjs +156 -0
  66. package/foundation/discovery/template-needs.test.mjs +203 -0
  67. package/foundation/response/response-types.doc.mjs +4 -4
  68. package/package.json +9 -9
@@ -11,7 +11,7 @@ export const docsZh = {
11
11
  content: [
12
12
  {
13
13
  type: 'prose',
14
- text: '安装主题包,用 `<Theme>` 包裹应用,选择浅色或深色模式。完整指南——可用主题、集成主题、深色模式、嵌套主题和生产构建——请参阅 {@link generic:use-a-theme}。',
14
+ text: "安装主题包,用 `<Theme>`(`import {Theme} from '@astryxdesign/core'`)包裹应用,选择浅色或深色模式。完整指南——可用主题、集成主题、深色模式、嵌套主题和生产构建——请参阅 {@link generic:use-a-theme}。",
15
15
  },
16
16
  ],
17
17
  },
@@ -6,91 +6,203 @@ export const docs = {
6
6
  name: 'use-a-theme',
7
7
  title: 'Use a theme',
8
8
  category: 'guide',
9
- keywords: ['theme', 'Theme', 'dark mode', 'light', 'nested', 'provider', 'SSR', 'built', 'runtime', 'neutralTheme', 'available themes'],
10
- description: 'Apply a theme to your app: wrap in a provider, pick a theme, switch dark mode, nest themes, and choose runtime or built for production.',
9
+ keywords: ['theme', 'Theme', 'dark mode', 'light', 'nested', 'provider', 'SSR', 'built', 'runtime', 'neutralTheme', 'available themes', 'theme add', 'import', 'astryx-themes', 'eject'],
10
+ description:
11
+ 'Apply a theme to your app: install, import with the CLI, wire the generated module, switch dark mode, nest themes, and choose runtime or built for production.',
12
+
11
13
  sections: [
12
14
  {
13
15
  id: 'quick-start',
14
16
  title: 'Wrap your app in a theme',
15
17
  content: [
16
- {type: 'code', lang: 'bash', label: 'Install a theme package', code: 'npm install @astryxdesign/theme-neutral'},
17
- {type: 'code', lang: 'tsx', label: 'Basic theme setup (runtime injection)', code: "import {Theme} from '@astryxdesign/core';\nimport {neutralTheme} from '@astryxdesign/theme-neutral';\n\nfunction App() {\n return (\n <Theme theme={neutralTheme}>\n <YourApp />\n </Theme>\n );\n}"},
18
- {type: 'code', lang: 'tsx', label: 'Optimized setup (pre-built CSS)', code: "import {Theme} from '@astryxdesign/core';\nimport {neutralTheme} from '@astryxdesign/theme-neutral/built';\nimport '@astryxdesign/theme-neutral/theme.css';\n\nfunction App() {\n return (\n <Theme theme={neutralTheme}>\n <YourApp />\n </Theme>\n );\n}"},
19
- {type: 'prose', text: 'Each theme ships as its own npm package. Install the one you want, then wrap your app in `<Theme>`. The same pattern works for every theme; just swap the package and import name.'},
20
- {type: 'prose', text: 'The default import uses runtime style injection, which works everywhere with no build step. The `/built` import skips injection and relies on the pre-compiled CSS file for better performance and SSR support.'},
18
+ {
19
+ type: 'code',
20
+ lang: 'bash',
21
+ label: 'Install and add a theme',
22
+ code: 'npm install @astryxdesign/theme-neutral\nastryx theme add neutral --import',
23
+ },
24
+ {
25
+ type: 'code',
26
+ lang: 'tsx',
27
+ label: 'Wire the generated module once',
28
+ code: "import {Theme} from '@astryxdesign/core';\nimport {themes, defaultThemeSlug} from './astryx-themes';\n\nfunction App() {\n return (\n <Theme theme={themes[defaultThemeSlug]}>\n <YourApp />\n </Theme>\n );\n}",
29
+ },
30
+ {
31
+ type: 'code',
32
+ lang: 'tsx',
33
+ label: 'Switch among added themes',
34
+ code: "import {useState} from 'react';\nimport {Theme} from '@astryxdesign/core';\nimport {themes, type ThemeSlug} from './astryx-themes';\n\nconst [slug, setSlug] = useState<ThemeSlug>('neutral');\nconst app = <Theme theme={themes[slug]}><YourApp /></Theme>;",
35
+ },
36
+ {
37
+ type: 'prose',
38
+ text: '`theme add --import` records an installed package theme and regenerates `src/astryx-themes.ts` or `.js` with its built module, production CSS, and optional font CSS. In a project without `src`, the module is at the project root. The first imported theme becomes the default. `theme use <slug>` changes that default, and `theme remove <slug>` removes a non-default theme.',
39
+ },
40
+ {
41
+ type: 'prose',
42
+ text: 'Customize a package theme with `defineTheme({extends: importedTheme, ...})`, then build and add that local theme. Use `theme eject` only when you want an independent source fork that no longer receives the package owner\'s updates. For the full authoring guide, see {@link generic:author-a-theme}.',
43
+ },
44
+ ],
45
+ },
46
+ {
47
+ title: 'Migrating Earlier Theme Copies',
48
+ content: [
49
+ {
50
+ type: 'prose',
51
+ text: 'A theme copied by the released `theme add` stays app source. The upgrade does not move, delete, or rewrite it. It only writes the missing same-stem descriptor with `maintained: false`, so the copy becomes a local theme.',
52
+ },
53
+ {
54
+ type: 'code',
55
+ lang: 'bash',
56
+ label: 'Add descriptors to earlier copies',
57
+ code: 'astryx upgrade --from 0.6.4 --path . --apply',
58
+ },
59
+ {
60
+ type: 'prose',
61
+ text: 'Before the upgrade runs, theme commands skip a descriptor-less copy in `src/themes`. `theme list` and doctor name it as unmigrated and show the upgrade command. A script that meant to copy source now runs `theme eject` with the same arguments. A script that meant to make the app use a theme runs `theme add --import`.',
62
+ },
63
+ {
64
+ type: 'prose',
65
+ text: '`ASTRYX_THEME` is no longer read. Run `theme add <slug> --import` and `theme use <slug>` to choose the default in a generated app theme module. When that module exists, component metadata reads its recorded default theme. Without the module, the released `package.json#astryx.theme` lookup keeps its meaning.',
66
+ },
21
67
  ],
22
68
  },
23
69
  {
24
70
  title: 'Available Themes',
25
71
  content: [
26
- {type: 'prose', text: 'Install the theme package you want with `npm install @astryxdesign/theme-{name}`, then import its theme object as shown below.'},
27
- {type: 'table', headers: ['Theme', 'Import', 'Description'], rows: [
28
- ['Neutral', "import {neutralTheme} from '@astryxdesign/theme-neutral'", 'Muted, minimal aesthetic with Figtree typography. A good starting point.'],
29
- ['Butter', "import {butterTheme} from '@astryxdesign/theme-butter'", 'Golden, buttery surfaces with blue accents; Sarina + Outfit type.'],
30
- ['Chocolate', "import {chocolateTheme} from '@astryxdesign/theme-chocolate'", 'Warm brown tones and cozy beige; Fraunces + Albert Sans type.'],
31
- ['Gothic', "import {gothicTheme} from '@astryxdesign/theme-gothic'", 'Dark-only atmospheric theme; deep blue-gray surfaces, distressed display type.'],
32
- ['Matcha', "import {matchaTheme} from '@astryxdesign/theme-matcha'", 'Earthy greens; DM Sans + Playwrite US Trad type.'],
33
- ['Stone', "import {stoneTheme} from '@astryxdesign/theme-stone'", 'Warm stone and slate tones; Montserrat + Figtree type.'],
34
- ['Y2K', "import {y2kTheme} from '@astryxdesign/theme-y2k'", 'Playful Y2K pop; periwinkle body, holographic accents, Poppins + Crimson Text.'],
35
- ]},
36
- {type: 'prose', text: "All theme packages export from two subpaths:\n- `@astryxdesign/theme-{name}`: source theme (runtime injection)\n- `@astryxdesign/theme-{name}/built`: pre-built theme (pair with `theme.css`)"},
72
+ {
73
+ type: 'prose',
74
+ text: 'Install the theme package you want with `npm install @astryxdesign/theme-{name}`, then import its slug with `theme add <slug> --import`. The CLI imports the package\'s built outputs for you.',
75
+ },
76
+ {
77
+ type: 'table',
78
+ headers: ['Theme', 'Add command', 'Description'],
79
+ rows: [
80
+ ['Neutral', 'astryx theme add neutral --import', 'Muted, minimal aesthetic with Figtree typography. A good starting point.'],
81
+ ['Butter', 'astryx theme add butter --import', 'Golden, buttery surfaces with blue accents; Sarina + Outfit type.'],
82
+ ['Chocolate', 'astryx theme add chocolate --import', 'Warm brown tones and cozy beige; Fraunces + Albert Sans type.'],
83
+ ['Gothic', 'astryx theme add gothic --import', 'Dark-only atmospheric theme; deep blue-gray surfaces, distressed display type.'],
84
+ ['Matcha', 'astryx theme add matcha --import', 'Earthy greens; DM Sans + Playwrite US Trad type.'],
85
+ ['Stone', 'astryx theme add stone --import', 'Warm stone and slate tones; Montserrat + Figtree type.'],
86
+ ['Y2K', 'astryx theme add y2k --import', 'Playful Y2K pop; periwinkle body, holographic accents, Poppins + Crimson Text.'],
87
+ ],
88
+ },
89
+ {
90
+ type: 'prose',
91
+ text: 'Every first-party package exports its built theme at `@astryxdesign/theme-{name}/built`, production CSS at `/theme.css`, and font loading CSS at `/fonts.css`. `theme add --import` writes those imports into the generated app module.',
92
+ },
37
93
  ],
38
94
  },
39
95
  {
40
96
  title: 'Theme Props',
41
97
  content: [
42
- {type: 'prose', text: "`<Theme>` takes `theme` (required), `mode` (`'system'` by default, or `'light'`/`'dark'`), and `children`. For every prop, run `astryx component Theme`."},
98
+ {
99
+ type: 'prose',
100
+ text: "`<Theme>` takes `theme` (required), `mode` (`'system'` by default, or `'light'`/`'dark'`), and `children`. For every prop, run `astryx component Theme`.",
101
+ },
43
102
  ],
44
103
  },
45
104
  {
46
105
  id: 'integration-themes',
47
106
  title: 'Using a Theme from an Integration',
48
107
  content: [
49
- {type: 'prose', text: 'Install the integration as a direct dependency and Astryx discovers its source themes and guide topics without an `astryx.config` file. Install Core too because the copied source imports `defineTheme` from `@astryxdesign/core/theme`.'},
50
- {type: 'code', lang: 'bash', label: 'Install, inspect, copy, and build', code: 'npm install @astryxdesign/core @acme/brand-integration\nastryx theme list --package @acme/brand-integration\nastryx docs brand-theme\nastryx theme add ocean --package @acme/brand-integration\nastryx theme build src/themes/ocean/oceanTheme.ts'},
51
- {type: 'prose', text: "The copy is editable project source, not a reference back into node_modules. The complete theme directory comes with it, including its typed `.doc.mjs`, nested token and palette modules, and receipts. A second add refuses to overwrite those files unless you pass `--overwrite`."},
108
+ {
109
+ type: 'prose',
110
+ text: 'Install the integration as a direct dependency. Astryx discovers its themes and guides without an `astryx.config` entry. A theme can be added only when the installed package exports its built module and production stylesheet.',
111
+ },
112
+ {
113
+ type: 'code',
114
+ lang: 'bash',
115
+ label: 'Install, inspect, and add',
116
+ code: 'npm install @astryxdesign/core @acme/brand-integration\nastryx theme list --package @acme/brand-integration\nastryx docs brand-theme\nastryx theme add ocean --import --package @acme/brand-integration',
117
+ },
118
+ {
119
+ type: 'prose',
120
+ text: '`theme add --import` keeps the owner package in the app record and imports its built module, stylesheet, and optional font stylesheet. Package updates continue to reach the app. Run `theme eject ocean --package @acme/brand-integration` only to copy the source and descriptor into `src/themes/ocean` as an independent local fork.',
121
+ },
52
122
  ],
53
123
  },
54
124
  {
55
125
  id: 'light-dark-mode',
56
126
  title: 'Dark mode',
57
127
  content: [
58
- {type: 'prose', text: "Use [light, dark] tuples in token values for automatic mode switching. Use mode='system' (default) on Theme to follow OS preference."},
59
- {type: 'code', lang: 'tsx', label: 'Light/dark tuple', code: "'--color-accent': ['#0064E0', '#2694FE'],\n// ^light ^dark"},
60
- {type: 'code', lang: 'tsx', label: 'Toggle with a button', code: "const [mode, setMode] = useState<'light' | 'dark'>('light');\n\n<Theme theme={myTheme} mode={mode}>\n <Button\n label={mode === 'light' ? 'Switch to Dark' : 'Switch to Light'}\n onClick={() => setMode(m => (m === 'light' ? 'dark' : 'light'))}\n />\n</Theme>;"},
61
- {type: 'prose', text: 'To create a theme with custom dark mode colors, see {@link generic:author-a-theme}.'},
128
+ {
129
+ type: 'prose',
130
+ text: "Use [light, dark] tuples in token values for automatic mode switching. Use mode='system' (default) on Theme to follow OS preference.",
131
+ },
132
+ {
133
+ type: 'code',
134
+ lang: 'tsx',
135
+ label: 'Light/dark tuple',
136
+ code: "'--color-accent': ['#0064E0', '#2694FE'],\n// ^light ^dark",
137
+ },
138
+ {
139
+ type: 'code',
140
+ lang: 'tsx',
141
+ label: 'Toggle with a button',
142
+ code: "const [mode, setMode] = useState<'light' | 'dark'>('light');\n\n<Theme theme={myTheme} mode={mode}>\n <Button\n label={mode === 'light' ? 'Switch to Dark' : 'Switch to Light'}\n onClick={() => setMode(m => (m === 'light' ? 'dark' : 'light'))}\n />\n</Theme>;",
143
+ },
144
+ {
145
+ type: 'prose',
146
+ text: 'To create a theme with custom dark mode colors, see {@link generic:author-a-theme}.',
147
+ },
62
148
  ],
63
149
  },
64
150
  {
65
151
  id: 'nesting-themes',
66
152
  title: 'Nested themes',
67
153
  content: [
68
- {type: 'prose', text: 'Wrap different sections in separate `<Theme>` providers.'},
69
- {type: 'code', lang: 'tsx', label: 'Dark sidebar with light content', code: "<Theme theme={lightTheme} mode=\"light\">\n <Layout\n header={<LayoutHeader>...</LayoutHeader>}\n start={\n <Theme theme={darkTheme} mode=\"dark\">\n <LayoutPanel>{/* Dark sidebar */}</LayoutPanel>\n </Theme>\n }\n content={<LayoutContent>{/* Light content */}</LayoutContent>}\n />\n</Theme>"},
154
+ {
155
+ type: 'prose',
156
+ text: 'Wrap different sections in separate `<Theme>` providers.',
157
+ },
158
+ {
159
+ type: 'code',
160
+ lang: 'tsx',
161
+ label: 'Dark sidebar with light content',
162
+ code: "<Theme theme={lightTheme} mode=\"light\">\n <Layout\n header={<LayoutHeader>...</LayoutHeader>}\n start={\n <Theme theme={darkTheme} mode=\"dark\">\n <LayoutPanel>{/* Dark sidebar */}</LayoutPanel>\n </Theme>\n }\n content={<LayoutContent>{/* Light content */}</LayoutContent>}\n />\n</Theme>",
163
+ },
70
164
  ],
71
165
  },
72
166
  {
73
167
  title: 'Runtime vs Built Themes',
74
168
  content: [
75
- {type: 'prose', text: 'Themes work in two modes:'},
76
- {type: 'table', headers: ['', 'Runtime (source)', 'Built'], rows: [
77
- ['Import (published theme)', '@astryxdesign/theme-{name}', '@astryxdesign/theme-{name}/built + theme.css'],
78
- ['Import (custom theme)', 'defineTheme() directly', 'Built .js + .css from `astryx theme build`'],
79
- ['How it works', 'useInsertionEffect injects <style> at hydration', 'Pre-compiled .css file loaded with the page'],
80
- ['Component overrides', 'Injected client-only', 'In static CSS: present during SSR'],
81
- ['SSR safe', 'Tokens yes, component overrides flash on hydration', 'Fully SSR safe: no flash'],
82
- ['Best for', 'Dev, prototyping, client-only SPAs', 'Production, SSR apps (Next.js, Remix)'],
83
- ]},
84
- {type: 'list', style: 'do', items: [
85
- 'Use the /built subpath + theme.css for production SSR apps.',
86
- 'Use runtime themes during development for fast iteration.',
87
- 'Run `astryx theme build` for custom themes to get the built artifacts.',
88
- ]},
89
- {type: 'list', style: 'dont', items: [
90
- 'Use runtime themes in production SSR apps; component overrides will flash on hydration.',
91
- "Import /built without the CSS file; component overrides won't apply.",
92
- ]},
93
- {type: 'prose', text: 'To build a custom theme for production, see the Build section of {@link generic:author-a-theme}.'},
169
+ {
170
+ type: 'prose',
171
+ text: 'Themes work in two modes:',
172
+ },
173
+ {
174
+ type: 'table',
175
+ headers: ['', 'Runtime (source)', 'Built'],
176
+ rows: [
177
+ ['Import (published theme)', '@astryxdesign/theme-{name}', '@astryxdesign/theme-{name}/built + theme.css'],
178
+ ['Import (custom theme)', 'defineTheme() directly', 'Built .js + .css from `astryx theme build`'],
179
+ ['How it works', 'useInsertionEffect injects <style> at hydration', 'Pre-compiled .css file loaded with the page'],
180
+ ['Component overrides', 'Injected client-only', 'In static CSS: present during SSR'],
181
+ ['SSR safe', 'Tokens yes, component overrides flash on hydration', 'Fully SSR safe: no flash'],
182
+ ['Best for', 'Dev, prototyping, client-only SPAs', 'Production, SSR apps (Next.js, Remix)'],
183
+ ],
184
+ },
185
+ {
186
+ type: 'list',
187
+ style: 'do',
188
+ items: [
189
+ 'Use `theme add --import` for production apps; it wires the built module and CSS.',
190
+ 'Use runtime themes during development for fast iteration.',
191
+ 'Run `astryx theme build` for custom themes to get the built artifacts.',
192
+ ],
193
+ },
194
+ {
195
+ type: 'list',
196
+ style: 'dont',
197
+ items: [
198
+ 'Use runtime themes in production SSR apps; component overrides will flash on hydration.',
199
+ "Import /built without the CSS file; component overrides won't apply.",
200
+ ],
201
+ },
202
+ {
203
+ type: 'prose',
204
+ text: 'To build a custom theme for production, see the Build section of {@link generic:author-a-theme}.',
205
+ },
94
206
  ],
95
207
  },
96
208
  ],
@@ -8,5 +8,5 @@ export const doc = {
8
8
  description:
9
9
  'Transposed matrix that puts candidates in the columns and criteria in grouped rows, with a pinned label column that survives horizontal scroll, columns you can swap or add, and best-in-row marks you can toggle. Compare, comparison, matrix, spec sheet, feature grid, pricing table, benchmark, frozen column, sticky column, or side-by-side.',
10
10
  isReady: true,
11
- category: 'Table - Frozen Column',
11
+ category: 'Table - Comparison',
12
12
  };
@@ -132,6 +132,7 @@ export type TemplateCategory =
132
132
  | 'Table - Filtering'
133
133
  | 'Table - Tree/Hierarchical List'
134
134
  | 'Table - Frozen Column'
135
+ | 'Table - Comparison'
135
136
  | 'Table - Chart'
136
137
  | 'Table - Heatmap'
137
138
  // Form
@@ -353,7 +353,7 @@ describe('theme build adaptations', () => {
353
353
  expect(rebuiltCss).toContain('light-dark(#111111, #eeeeee)');
354
354
  expect(rebuiltCss).toContain(':root { color-scheme: light dark; }');
355
355
  expect(`${rebuilt.stdout}${rebuilt.stderr}`).toContain(
356
- 'Font "Revision Webfont" is named by this theme but not loaded',
356
+ '[note] Fonts named but not loaded: "Revision Webfont".',
357
357
  );
358
358
  });
359
359
 
@@ -72,7 +72,17 @@ function run(args) {
72
72
 
73
73
  describe('theme command human output is plain ASCII', () => {
74
74
  it('a standalone build: ok, warning, error, notice, and font help lines', async () => {
75
- const result = await run(['build', 'ocean.mjs']);
75
+ const short = await run(['build', 'ocean.mjs']);
76
+ expect(short.code).toBe(0);
77
+ expect(short.stdout).toContain(
78
+ '[note] Fonts named but not loaded: "Inter"',
79
+ );
80
+ expect(nonAscii(short)).toEqual([]);
81
+
82
+ const result = await runCli(
83
+ ['--detail', 'full', 'theme', 'build', 'ocean.mjs'],
84
+ dir,
85
+ );
76
86
 
77
87
  expect(result.code).toBe(0);
78
88
  expect(result.stdout).toContain('[ok] ocean.css');
@@ -0,0 +1,335 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The human report of `astryx theme build`.
5
+ *
6
+ * By default the report is one line per built theme, one line naming the
7
+ * fonts the themes do not load, and a hint. `--detail full` adds the install
8
+ * example and the font recipe: once for one theme, as the report always had,
9
+ * and once for a batch instead of once per theme. `--detail compact|brief`
10
+ * prints the short report without the hint. `--json` and `--check` keep their
11
+ * output at every detail level.
12
+ *
13
+ * `astryx theme build` needs a compiled @astryxdesign/core, so this suite
14
+ * builds core once via the shared ensureCoreBuilt() helper.
15
+ */
16
+
17
+ import {describe, it, expect, beforeAll, afterEach} from 'vitest';
18
+ import * as fs from 'node:fs';
19
+ import * as path from 'node:path';
20
+ import * as os from 'node:os';
21
+ import {ensureCoreBuilt} from './ensure-core-built.mjs';
22
+ import {runCli} from '../../../test-utils/run-cli.mjs';
23
+
24
+ const GOLDEN = path.resolve(import.meta.dirname, '../../../test/__golden__');
25
+
26
+ const NAMES = [
27
+ 'amber',
28
+ 'basil',
29
+ 'cedar',
30
+ 'dune',
31
+ 'ember',
32
+ 'fjord',
33
+ 'grove',
34
+ 'harbor',
35
+ 'iris',
36
+ 'juniper',
37
+ 'kelp',
38
+ 'lagoon',
39
+ 'meadow',
40
+ 'nimbus',
41
+ 'orchid',
42
+ ];
43
+ const BODY_FONTS = [
44
+ '"Space Grotesk", sans-serif',
45
+ '"Space Grotesk", sans-serif',
46
+ 'Figtree, sans-serif',
47
+ '"JetBrains Mono", monospace',
48
+ 'system-ui, sans-serif',
49
+ ];
50
+ const FILES = NAMES.map(name => `themes/${name}.mjs`);
51
+ const FONT_NOTE =
52
+ '[note] Fonts named but not loaded: ' +
53
+ '"Space Grotesk" (amber, basil, fjord, grove, kelp, lagoon), ' +
54
+ '"JetBrains Mono" (amber, dune, grove, iris, juniper, meadow, nimbus), ' +
55
+ '"Figtree" (cedar, harbor, meadow). Load them in your app (recipe: astryx docs typography).';
56
+ const HINT = 'Run with --detail full for the install example and font recipe.';
57
+ const OK_LINE =
58
+ /^\[ok\] themes\/([a-z]+)\.css \(\d+(\.\d+)? KB, \d+ token overrides, \d+ component overrides\)$/;
59
+
60
+ /** @type {string[]} */
61
+ const dirs = [];
62
+
63
+ /** A fresh project holding the fifteen theme sources. */
64
+ function project() {
65
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-theme-batch-'));
66
+ fs.mkdirSync(path.join(dir, 'themes'));
67
+ NAMES.forEach((name, i) => {
68
+ /** @type {Record<string, string>} */
69
+ const tokens = {
70
+ '--color-bg': `#${[13, 29, 47]
71
+ .map(n => ((i * n) % 256).toString(16).padStart(2, '0'))
72
+ .join('')}`,
73
+ '--font-family-body': BODY_FONTS[i % BODY_FONTS.length],
74
+ };
75
+ if (i % 3 === 0) {
76
+ tokens['--font-family-code'] = '"JetBrains Mono", monospace';
77
+ }
78
+ fs.writeFileSync(
79
+ path.join(dir, 'themes', `${name}.mjs`),
80
+ `export default ${JSON.stringify({name, tokens})};\n`,
81
+ );
82
+ });
83
+ dirs.push(dir);
84
+ return dir;
85
+ }
86
+
87
+ /** @param {string} text @param {string} pattern */
88
+ function count(text, pattern) {
89
+ return text.split(pattern).length - 1;
90
+ }
91
+
92
+ /** @param {string} stdout */
93
+ function lines(stdout) {
94
+ return stdout.split('\n').filter(Boolean);
95
+ }
96
+
97
+ /** @param {string} stdout The sizes follow Core's CSS, so goldens keep the shape. */
98
+ function normalized(stdout) {
99
+ return stdout.replace(/\d+(\.\d+)? KB/g, '<size> KB');
100
+ }
101
+
102
+ /** Bytes of the full report printed by one invocation per theme. */
103
+ async function separateFullReports(dir) {
104
+ let bytes = 0;
105
+ for (const file of FILES) {
106
+ const one = await runCli(['--detail', 'full', 'theme', 'build', file], dir);
107
+ expect(one.status).toBe(0);
108
+ expect(one.stdout).toContain('Install in your app');
109
+ bytes += Buffer.byteLength(one.stdout);
110
+ }
111
+ return bytes;
112
+ }
113
+
114
+ beforeAll(() => {
115
+ ensureCoreBuilt();
116
+ }, 200_000);
117
+
118
+ afterEach(() => {
119
+ for (const dir of dirs.splice(0)) {
120
+ fs.rmSync(dir, {recursive: true, force: true});
121
+ }
122
+ });
123
+
124
+ describe('theme build report', () => {
125
+ it('prints one line per theme, one font note and a hint by default', async () => {
126
+ const dir = project();
127
+ const batch = await runCli(['theme', 'build', ...FILES], dir);
128
+ expect(batch.status).toBe(0);
129
+
130
+ const out = lines(batch.stdout);
131
+ expect(out).toHaveLength(NAMES.length + 3);
132
+ NAMES.forEach((name, i) => {
133
+ expect(out[i]).toMatch(OK_LINE);
134
+ expect(out[i]).toContain(`themes/${name}.css`);
135
+ });
136
+ expect(out.slice(NAMES.length)).toEqual([
137
+ FONT_NOTE,
138
+ HINT,
139
+ '[ok] Built 15 themes.',
140
+ ]);
141
+ expect(batch.stdout).not.toContain('Building theme from');
142
+ expect(batch.stdout).not.toContain('Install in your app');
143
+ expect(batch.stdout).not.toContain('fonts.googleapis.com');
144
+ expect(fs.existsSync(path.join(dir, 'themes', 'orchid.js'))).toBe(true);
145
+ await expect(normalized(batch.stdout)).toMatchFileSnapshot(
146
+ path.join(GOLDEN, 'theme-build-batch.txt'),
147
+ );
148
+
149
+ const separate = await separateFullReports(dir);
150
+ expect(Buffer.byteLength(batch.stdout)).toBeLessThan(separate * 0.1);
151
+ }, 300_000);
152
+
153
+ it('--detail full prints the install example once and each unloaded font once', async () => {
154
+ const dir = project();
155
+ const batch = await runCli(
156
+ ['--detail', 'full', 'theme', 'build', ...FILES],
157
+ dir,
158
+ );
159
+ expect(batch.status).toBe(0);
160
+ const out = batch.stdout;
161
+
162
+ for (const name of NAMES) {
163
+ expect(out).toContain(`Building theme from themes/${name}.mjs...`);
164
+ expect(out).toContain(`[ok] themes/${name}.css\n`);
165
+ expect(out).toContain(
166
+ ` import { ${name}Theme } from './themes/${name}'; import './themes/${name}.css';`,
167
+ );
168
+ }
169
+ expect(count(out, 'Install in your app')).toBe(1);
170
+ expect(count(out, 'Or with a <link> tag:')).toBe(1);
171
+ expect(count(out, "import { Theme } from '@astryxdesign/core';")).toBe(2);
172
+ expect(count(out, '[note]')).toBe(1);
173
+ expect(count(out, 'note: Font')).toBe(0);
174
+ expect(count(out, 'fonts.googleapis.com/css2')).toBe(1);
175
+ expect(out).toContain(
176
+ ' "Space Grotesk" (amber, basil, fjord, grove, kelp, lagoon)\n' +
177
+ ' "JetBrains Mono" (amber, dune, grove, iris, juniper, meadow, nimbus)\n' +
178
+ ' "Figtree" (cedar, harbor, meadow)\n',
179
+ );
180
+ expect(out).toContain(
181
+ 'family=Space+Grotesk&family=JetBrains+Mono&family=Figtree&display=swap',
182
+ );
183
+ expect(out).not.toContain(HINT);
184
+ expect(out.trimEnd().endsWith('[ok] Built 15 themes.')).toBe(true);
185
+ await expect(normalized(out)).toMatchFileSnapshot(
186
+ path.join(GOLDEN, 'theme-build-batch-full.txt'),
187
+ );
188
+
189
+ const separate = await separateFullReports(dir);
190
+ expect(Buffer.byteLength(out)).toBeLessThan(separate * 0.3);
191
+ }, 300_000);
192
+
193
+ it.each(['compact', 'brief'])(
194
+ '--detail %s prints the short report without the hint',
195
+ async detail => {
196
+ const dir = project();
197
+ const r = await runCli(
198
+ ['--detail', detail, 'theme', 'build', ...FILES],
199
+ dir,
200
+ );
201
+ expect(r.status).toBe(0);
202
+ const out = lines(r.stdout);
203
+ expect(out).toHaveLength(NAMES.length + 2);
204
+ NAMES.forEach((_, i) => expect(out[i]).toMatch(OK_LINE));
205
+ expect(out.slice(NAMES.length)).toEqual([
206
+ FONT_NOTE,
207
+ '[ok] Built 15 themes.',
208
+ ]);
209
+ },
210
+ 120_000,
211
+ );
212
+
213
+ it('prints one line for one theme, and a font note only when fonts are missing', async () => {
214
+ const dir = project();
215
+ const ember = await runCli(
216
+ ['--detail', 'brief', 'theme', 'build', 'themes/ember.mjs'],
217
+ dir,
218
+ );
219
+ expect(ember.status).toBe(0);
220
+ expect(lines(ember.stdout)).toHaveLength(1);
221
+ expect(ember.stdout).toMatch(
222
+ /^\[ok\] themes\/ember\.css \(\d+(\.\d+)? KB, 2 token overrides, 0 component overrides\)\n$/,
223
+ );
224
+
225
+ const amber = await runCli(['theme', 'build', 'themes/amber.mjs'], dir);
226
+ expect(amber.status).toBe(0);
227
+ expect(lines(amber.stdout).slice(1)).toEqual([
228
+ '[note] Fonts named but not loaded: "Space Grotesk", "JetBrains Mono". Load them in your app (recipe: astryx docs typography).',
229
+ HINT,
230
+ ]);
231
+ }, 120_000);
232
+
233
+ it('--detail full keeps the standalone report for one theme', async () => {
234
+ const dir = project();
235
+ const r = await runCli(
236
+ ['--detail', 'full', 'theme', 'build', 'themes/amber.mjs'],
237
+ dir,
238
+ );
239
+ expect(r.status).toBe(0);
240
+ expect(r.stdout).toContain('Building theme from themes/amber.mjs...');
241
+ expect(r.stdout).toContain("import { amberTheme } from './themes/amber';");
242
+ expect(r.stdout).toContain('Or with a <link> tag:');
243
+ expect(r.stdout).toContain('note: Font "Space Grotesk"');
244
+ expect(r.stdout).toContain(
245
+ '[note] Theme "amber" names fonts it does not load: "Space Grotesk", "JetBrains Mono"',
246
+ );
247
+ expect(r.stdout).not.toContain('Each built theme imports the same way');
248
+ expect(r.stdout).not.toContain(HINT);
249
+ }, 120_000);
250
+
251
+ it('keeps the guidance for themes already written when a batch fails', async () => {
252
+ const dir = project();
253
+ fs.writeFileSync(
254
+ path.join(dir, 'themes', 'broken.mjs'),
255
+ 'export default {\n',
256
+ );
257
+ const files = ['themes/amber.mjs', 'themes/basil.mjs', 'themes/broken.mjs'];
258
+
259
+ const short = await runCli(['theme', 'build', ...files], dir);
260
+ expect(short.status).toBe(1);
261
+ expect(short.stderr).toContain('themes/broken.mjs: ');
262
+ expect(short.stdout).toContain(
263
+ '[note] Fonts named but not loaded: "Space Grotesk" (amber, basil), "JetBrains Mono" (amber).',
264
+ );
265
+ expect(short.stdout).not.toContain('Built 3 themes');
266
+
267
+ const full = await runCli(
268
+ ['--detail', 'full', 'theme', 'build', ...files],
269
+ dir,
270
+ );
271
+ expect(full.status).toBe(1);
272
+ expect(count(full.stdout, 'Install in your app')).toBe(1);
273
+ expect(full.stdout).toContain(
274
+ " import { basilTheme } from './themes/basil'; import './themes/basil.css';",
275
+ );
276
+ expect(full.stdout).toContain(' "Space Grotesk" (amber, basil)\n');
277
+ expect(full.stdout).not.toContain('Built 3 themes');
278
+ }, 120_000);
279
+
280
+ it('names the file on each warning in the short report', async () => {
281
+ const dir = project();
282
+ fs.writeFileSync(
283
+ path.join(dir, 'themes', 'warny.mjs'),
284
+ `export default ${JSON.stringify({
285
+ name: 'warny',
286
+ tokens: {'--color-bg': '#123456'},
287
+ components: {notAComponent: {base: {color: 'red'}}},
288
+ })};\n`,
289
+ );
290
+ const short = await runCli(
291
+ ['theme', 'build', 'themes/amber.mjs', 'themes/warny.mjs'],
292
+ dir,
293
+ );
294
+ expect(short.status).toBe(0);
295
+ expect(short.stderr).toMatch(
296
+ /\[warn\] themes\/warny\.mjs: Unknown component "notAComponent"/,
297
+ );
298
+
299
+ const full = await runCli(
300
+ ['--detail', 'full', 'theme', 'build', 'themes/warny.mjs'],
301
+ dir,
302
+ );
303
+ expect(full.stderr).toContain(' [warn] Unknown component "notAComponent"');
304
+ }, 120_000);
305
+
306
+ it('keeps --json and --check the same at every detail level', async () => {
307
+ const dir = project();
308
+ const plain = await runCli(['--json', 'theme', 'build', ...FILES], dir);
309
+ expect(plain.status).toBe(0);
310
+ for (const detail of ['full', 'compact', 'brief']) {
311
+ const r = await runCli(
312
+ ['--json', '--detail', detail, 'theme', 'build', ...FILES],
313
+ dir,
314
+ );
315
+ expect(r.status).toBe(0);
316
+ expect(JSON.parse(r.stdout)).toEqual(JSON.parse(plain.stdout));
317
+ }
318
+ expect(
319
+ JSON.parse(plain.stdout).data.results[0].receipt.data.notices,
320
+ ).toEqual([
321
+ 'Font "Space Grotesk" is named by this theme but not loaded; add a <link> or @font-face in your app (recipe: astryx docs typography)',
322
+ 'Font "JetBrains Mono" is named by this theme but not loaded; add a <link> or @font-face in your app (recipe: astryx docs typography)',
323
+ ]);
324
+
325
+ const check = await runCli(['theme', 'build', '--check', ...FILES], dir);
326
+ expect(check.status).toBe(0);
327
+ for (const detail of ['full', 'brief']) {
328
+ const r = await runCli(
329
+ ['--detail', detail, 'theme', 'build', '--check', ...FILES],
330
+ dir,
331
+ );
332
+ expect(r.stdout).toBe(check.stdout);
333
+ }
334
+ }, 180_000);
335
+ });