@astryxdesign/cli 0.7.3-canary.b74cf21 → 0.7.3-canary.cbe384c
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.
- package/api/integration/pack-check.mjs +110 -4
- package/api/integration/pack-check.test.mjs +69 -0
- package/api/integration/validate-integration-gaps.test.mjs +292 -0
- package/api/integration/validate-integration.mjs +4 -1
- package/api/integration/validate-integration.type.d.mts +1 -0
- package/api/integration/validate-integration.type.mjs +1 -0
- package/assets/docs/is-my-code-good.doc.mjs +287 -0
- package/assets/docs/tree/template-grading-rubric.doc.mjs +16 -37
- package/foundation/config/project.test.mjs +26 -0
- package/foundation/discovery/template-adapter.mjs +18 -1
- package/foundation/discovery/theme-discovery.mjs +147 -3
- package/foundation/doc-compiler/read.mjs +59 -1
- package/foundation/doc-compiler/read.test.mjs +11 -2
- package/foundation/integrations/integrations.d.mts +9 -1
- package/foundation/integrations/integrations.mjs +38 -1
- package/foundation/integrations/validate-contributions.d.mts +19 -0
- package/foundation/integrations/validate-contributions.mjs +172 -3
- package/package.json +9 -9
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx docs is-my-code-good`: one evidence-first guide for checking
|
|
5
|
+
* whether a product surface uses Astryx well and improving it with an agent.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** @type {import('@astryxdesign/cli/authoring').ReferenceDoc} */
|
|
9
|
+
export const docs = {
|
|
10
|
+
type: 'generic',
|
|
11
|
+
name: 'is-my-code-good',
|
|
12
|
+
title: 'Is my Astryx code good?',
|
|
13
|
+
category: 'guide',
|
|
14
|
+
keywords: [
|
|
15
|
+
'is my code good',
|
|
16
|
+
'review my code',
|
|
17
|
+
'code review',
|
|
18
|
+
'check my code',
|
|
19
|
+
'evaluate my code',
|
|
20
|
+
'review astryx code',
|
|
21
|
+
'rubric',
|
|
22
|
+
'astryx quality rubric',
|
|
23
|
+
'custom code audit',
|
|
24
|
+
],
|
|
25
|
+
description:
|
|
26
|
+
'Check whether a product surface fits its app and uses Astryx well, require evidence for every claim, and improve it with a repeatable agent review.',
|
|
27
|
+
sections: [
|
|
28
|
+
{
|
|
29
|
+
id: 'understand-the-app',
|
|
30
|
+
title: 'Understand the app',
|
|
31
|
+
content: [
|
|
32
|
+
{
|
|
33
|
+
type: 'prose',
|
|
34
|
+
text: 'Do not judge a file or surface in isolation. First learn the app context that makes a pattern correct, inconsistent, or incomplete.',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'list',
|
|
38
|
+
style: 'ordered',
|
|
39
|
+
items: [
|
|
40
|
+
'Name what the app is for, who uses it, and the task this surface helps them complete.',
|
|
41
|
+
'Trace where the surface sits: its route, entry point, navigation path, parent shell, and the page or block pattern it is meant to use.',
|
|
42
|
+
'Inspect sibling surfaces that do the same or adjacent jobs. Record their shared headers, actions, layout primitives, spacing, density, states, and narrow-screen behavior.',
|
|
43
|
+
'Read project guidance, including the root and relevant nested `AGENTS.md` files. Record app-owned wrapper components and intentional app conventions.',
|
|
44
|
+
'Record the installed `@astryxdesign/core`, `@astryxdesign/cli`, and integration-package versions from the project manifest and lockfile. Run the installed invocation of `astryx component --list` to see core and integration components, then inspect app-owned wrappers that do not appear in that catalog.',
|
|
45
|
+
'List the real data states, roles and permissions, supported locales and RTL behavior, and mobile or narrow-width needs that affect the task.',
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'prose',
|
|
50
|
+
text: 'Keep this context with the review. Mark anything you could not learn as `not inspected`. Do not flag a documented, intentional app convention merely because it differs from a generic pattern; cite the convention and verify that the user task and accessibility requirements still work.',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'choose-the-review',
|
|
56
|
+
title: 'Choose the review',
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: 'prose',
|
|
60
|
+
text: 'Review one exact revision and one named product surface, route, or component in its app context. Pick the smallest review that can answer your question.',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: 'table',
|
|
64
|
+
headers: ['Review', 'Use it for', 'What it can prove'],
|
|
65
|
+
rows: [
|
|
66
|
+
[
|
|
67
|
+
'Source check',
|
|
68
|
+
'A fast check for raw elements, direct icons, custom styles, and unsupported imports',
|
|
69
|
+
'Source findings plus app context visible in the project. It cannot call the rendered product good.',
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
'Full product review',
|
|
73
|
+
'Calling a surface done',
|
|
74
|
+
'App fit and task completion plus source quality, rendered layout, states, assets, project checks, and accessibility evidence.',
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
'Template publication grade',
|
|
78
|
+
'An integration template that people copy',
|
|
79
|
+
'The shared criteria plus versioned scoring, metadata, packaging, copy, and clean-app checks in {@link generic:grade-template-with-agent}.',
|
|
80
|
+
],
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: 'prose',
|
|
85
|
+
text: 'If all you have is one source file, run the source check anyway and use any project context that is available. Report clear source blockers; list missing app purpose, route, sibling patterns, shell, theme and density, installed components and versions, real states and roles, locale and mobile needs, revision, runnable app, rendered states, and project checks; and do not call the full product good.',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: 'prose',
|
|
89
|
+
text: "`astryx` in this guide means the project's installed CLI invocation, such as its local binary or existing package script. If the project has no installed invocation, report that evidence gap instead of downloading a different CLI version for the review.",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: 'prose',
|
|
93
|
+
text: 'A screenshot can prove a visible result, but it cannot prove which imports, components, or styles produced it. Source alone cannot prove responsive behavior, interaction, color modes, or whether an asset loads. Mark anything outside the supplied evidence as `not inspected`.',
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: 'apply-the-rubric',
|
|
99
|
+
title: 'Apply the shared rubric',
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: 'prose',
|
|
103
|
+
text: 'Mark each category `good`, `needs work`, or `not inspected`. Cite the route, sibling surface, project guidance, theme, component catalog, or user requirement behind every context-dependent result; cite a file and line for every source result; and name the rendered state for every visual result. Never turn missing evidence into a pass. A blocker is a finding that prevents the surface from building, rendering, operating, letting the target user complete the task, or meeting an accessibility requirement. Other departures from the rubric are `needs work`.',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
type: 'table',
|
|
107
|
+
headers: ['Category', 'What good means'],
|
|
108
|
+
rows: [
|
|
109
|
+
[
|
|
110
|
+
'App fit and task completion',
|
|
111
|
+
"The surface uses the app's established shell, page pattern, theme, density, wrappers, integrations, and interaction conventions unless a deviation is intentional and evidenced. The target user can complete the surface's job across the real states and permissions in scope.",
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
'Astryx components',
|
|
115
|
+
'Astryx owns each visible or interactive pattern for which it has a suitable component. Raw elements remain only when their native semantics are necessary or Astryx has no equivalent.',
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
'Icons',
|
|
119
|
+
'Icons render through `Icon`, `IconButton`, or the receiving component icon prop, not as raw SVG or a library component used directly.',
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
'Styling',
|
|
123
|
+
'Component props and design tokens do the work before custom StyleX declarations, inline styles, or classes. Each custom rule has a reason because no supported Astryx surface fits.',
|
|
124
|
+
],
|
|
125
|
+
[
|
|
126
|
+
'Layout',
|
|
127
|
+
'Astryx layout primitives express the visible structure, hierarchy, spacing, and responsive behavior without rebuilding the same patterns in raw containers or CSS.',
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
'Images and assets',
|
|
131
|
+
'Every image, font, and other asset is intentional, accessible, stable, and working from the product build path.',
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
'Code health',
|
|
135
|
+
'Public imports resolve, client boundaries are necessary, reachable states are handled, and no dead code or wrapper hides a finding.',
|
|
136
|
+
],
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
type: 'prose',
|
|
141
|
+
text: "Before calling a pattern custom or wrong, compare sibling surfaces and the installed component catalog. Reuse an app-owned wrapper or integration component when it already owns the job. A documented app convention is not a finding merely because it differs from a generic pattern; cite the convention and verify the user's task and accessibility requirements.",
|
|
142
|
+
},
|
|
143
|
+
{type: 'heading', level: 3, text: 'Common component replacements'},
|
|
144
|
+
{
|
|
145
|
+
type: 'table',
|
|
146
|
+
headers: ['Raw pattern', 'Common Astryx owner'],
|
|
147
|
+
rows: [
|
|
148
|
+
[
|
|
149
|
+
'Layout `div`',
|
|
150
|
+
'`VStack`, `HStack`, `Grid`, `Card`, `Section`, or `Center`',
|
|
151
|
+
],
|
|
152
|
+
['`span`, `p`, or `h1` through `h6`', '`Text` or `Heading`'],
|
|
153
|
+
['`button` or linked action', '`Button`, `IconButton`, or `Link`'],
|
|
154
|
+
['In-page `nav` or `aside`', '`LayoutPanel`'],
|
|
155
|
+
[
|
|
156
|
+
'`header` or `main`',
|
|
157
|
+
'`LayoutHeader` or `LayoutContent` inside `Layout`',
|
|
158
|
+
],
|
|
159
|
+
['`ul`, `ol`, or `li`', '`List` and `ListItem`'],
|
|
160
|
+
[
|
|
161
|
+
'`input`, `textarea`, or `select`',
|
|
162
|
+
'The matching Astryx form control',
|
|
163
|
+
],
|
|
164
|
+
['`table`, `tr`, or `td`', '`Table`'],
|
|
165
|
+
[
|
|
166
|
+
'`hr`, `dialog`, `details`, or `summary`',
|
|
167
|
+
'`Divider`, `Dialog`, or `Collapsible`',
|
|
168
|
+
],
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
type: 'prose',
|
|
173
|
+
text: 'Keep a native element when its semantics are necessary and Astryx has no equivalent. Common examples are a `form` that provides native submission, `input type="hidden"` for native form state, and an `img` when no general Astryx image component fits.',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
type: 'list',
|
|
177
|
+
style: 'unordered',
|
|
178
|
+
items: [
|
|
179
|
+
"Compare the route with sibling surfaces that do the same job. Identify the app's shared header, actions, shell, page pattern, spacing, and density before judging the target.",
|
|
180
|
+
'Inspect every JSX opening tag. Moving raw HTML behind a PascalCase helper does not make the underlying pattern an Astryx component.',
|
|
181
|
+
'Count every raw SVG element used as an icon, including `svg`, `path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`, and `g`. For an inline SVG helper, count its raw SVG elements once in the helper definition, not again at each render. Count each icon-library component rendered directly outside an Astryx icon surface.',
|
|
182
|
+
'Look up a possible replacement with `astryx component <Name> --dense`. Do not invent a component or prop that the installed version does not provide.',
|
|
183
|
+
'Run the installed `astryx component --list` and inspect app-owned wrappers before rebuilding a pattern. Prefer the component the app or one of its installed integrations already uses for the job.',
|
|
184
|
+
'Inspect every `stylex.create` declaration, inline style, `className`, and `stylex.props` use. Look for a component prop or token first.',
|
|
185
|
+
"When replacing a literal spacing value, read `astryx docs spacing --full` for the matching step or token and the target component doc for the prop's accepted scale. Do not guess a pixel-to-step mapping.",
|
|
186
|
+
'Choose the root that matches the surface. Use `Layout` for a page, `Center` for centered content, and `AppShell` only when the surface owns global application chrome.',
|
|
187
|
+
'Render realistic empty, loading, error, long-content, and interactive states. Check narrow and wide widths plus each supported color mode.',
|
|
188
|
+
'Verify the target roles and permissions, supported locales and RTL behavior, and mobile needs. Follow the real task from entry to completion instead of judging only the static page.',
|
|
189
|
+
'Run the product build, type check, tests, and accessibility checks. Keep a missing or failed check visible instead of calling the result good.',
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
type: 'prose',
|
|
194
|
+
text: 'This shared rubric has no numeric score. It answers whether ordinary product code uses Astryx well without pretending that an inapplicable template field or missing browser state earned points. Integration templates add a versioned score in {@link generic:template-grading-rubric}.',
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: 'collect-the-evidence',
|
|
200
|
+
title: 'Collect the evidence',
|
|
201
|
+
content: [
|
|
202
|
+
{
|
|
203
|
+
type: 'list',
|
|
204
|
+
style: 'ordered',
|
|
205
|
+
items: [
|
|
206
|
+
'Record the exact revision, named surface, route, and source files in scope. If the files are outside version control, record a content hash for each file and say that no project revision was available.',
|
|
207
|
+
"Write down the app's purpose, target users, surface task, entry point, navigation path, parent shell, expected page pattern, and sibling surfaces used for comparison.",
|
|
208
|
+
'Record project guidance, theme, density, installed Astryx and integration versions, the relevant output of `astryx component --list`, and app-owned wrappers or conventions.',
|
|
209
|
+
'List the states and context that matter, including real data shapes, roles and permissions, empty, loading, error, long content, interaction, narrow width, wide width, supported color modes, locales, and RTL behavior when they apply.',
|
|
210
|
+
'Run the product and capture each named rendered state. Use screenshots or a live browser result for visible claims, and follow the target user task from entry to completion.',
|
|
211
|
+
'Run the build, type check, tests, and accessibility checks. Keep their commands and results with the review.',
|
|
212
|
+
'For each Astryx component whose replacement, prop, or composition is in question, read `astryx component <Name> --dense`.',
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
id: 'ask-an-agent',
|
|
219
|
+
title: 'Ask an agent',
|
|
220
|
+
content: [
|
|
221
|
+
{
|
|
222
|
+
type: 'prose',
|
|
223
|
+
text: 'Start with a read-only pass so the original findings stay visible. Replace every angle-bracket value in this prompt.',
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
type: 'code',
|
|
227
|
+
lang: 'text',
|
|
228
|
+
label: 'Agent evaluation prompt',
|
|
229
|
+
code: `Evaluate how well <surface> at <revision> fits <app> and uses Astryx. Do not edit files during this first pass.
|
|
230
|
+
|
|
231
|
+
\`astryx\` below means the project's installed CLI invocation, such as its local binary or existing package script. If none is installed, report that evidence gap instead of downloading a different version.
|
|
232
|
+
|
|
233
|
+
Before evaluating:
|
|
234
|
+
1. Read \`astryx docs is-my-code-good --full\`.
|
|
235
|
+
2. Read the root and relevant nested \`AGENTS.md\` files plus other project guidance. State what the app is for, who uses it, and the task this surface supports.
|
|
236
|
+
3. Trace the surface's route, entry point, navigation path, parent shell, and expected page or block pattern.
|
|
237
|
+
4. Inspect at least two sibling surfaces that do the same or adjacent jobs. Record their shared headers, actions, layout, spacing, density, states, and narrow-screen behavior.
|
|
238
|
+
5. Record the app's theme, density, app-owned wrappers, and documented intentional conventions.
|
|
239
|
+
6. Read the project manifest and lockfile for the installed Astryx, CLI, and integration versions. Run \`astryx component --list\`, then identify relevant integration components and app-owned wrappers.
|
|
240
|
+
7. List the real data states, roles and permissions, supported locales and RTL behavior, and mobile or narrow-width needs.
|
|
241
|
+
8. Inspect every source file in scope and its public imports.
|
|
242
|
+
9. Run \`astryx component <Name> --dense\` for each Astryx component whose replacement, prop, or composition you question.
|
|
243
|
+
10. Read \`astryx docs spacing --full\` and the target component's docs before mapping a literal spacing value to a prop or token.
|
|
244
|
+
11. Render every supplied state at narrow and wide widths and in each supported color mode.
|
|
245
|
+
12. Read the build, type-check, test, and accessibility-check results.
|
|
246
|
+
|
|
247
|
+
If only source is supplied, continue with a source check. Report blockers visible in the source, list every missing app-context and product-evidence item, and do not call the full product good. Do not leave the blocker list empty only because no checks were supplied.
|
|
248
|
+
|
|
249
|
+
Judge the code against the app as well as Astryx. Ask whether it matches sibling surfaces, uses the right shell and page pattern, reuses app or integration components instead of rebuilding them, preserves intentional app conventions, and lets the target user complete the task.
|
|
250
|
+
|
|
251
|
+
For each rubric category, return \`good\`, \`needs work\`, or \`not inspected\`. Every context-dependent finding must cite the route, sibling file, project guidance, theme, component catalog, wrapper, or user requirement it relies on. Cite file and line evidence for source findings and name the rendered state for visual findings. Mark context you could not learn as \`not inspected\`. Do not flag a documented intentional app convention merely because it differs from a generic pattern. Never turn missing evidence into a pass. Do not hide raw HTML or custom styles behind a helper. Do not calculate a template score for ordinary product code.
|
|
252
|
+
|
|
253
|
+
Return:
|
|
254
|
+
- app purpose, target users, surface job, route, and entry path
|
|
255
|
+
- app context inspected and app context missing
|
|
256
|
+
- product evidence inspected and product evidence missing
|
|
257
|
+
- one row per rubric category with result, evidence, and fix
|
|
258
|
+
- task-completion, functional, or accessibility blockers visible in the source or found by the supplied checks
|
|
259
|
+
- the top three fixes in order
|
|
260
|
+
- every claim that still needs a person to verify`,
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: 'verify-and-repeat',
|
|
266
|
+
title: 'Verify, improve, and repeat',
|
|
267
|
+
content: [
|
|
268
|
+
{
|
|
269
|
+
type: 'list',
|
|
270
|
+
style: 'ordered',
|
|
271
|
+
items: [
|
|
272
|
+
'Reject a `good` result without app-context, source, and rendered evidence. Open every cited route, sibling file, guidance file, and source location, and reproduce every named visible state.',
|
|
273
|
+
'Check that documented intentional app conventions were not flagged merely for differing from a generic pattern, and that context the reviewer could not learn stayed `not inspected`.',
|
|
274
|
+
'Fix task-completion, build, functional, and accessibility blockers first.',
|
|
275
|
+
'Reuse the app shell, page pattern, wrappers, and installed integration components before replacing unnecessary raw elements, direct icons, and custom styles.',
|
|
276
|
+
'Follow the target user task again, render the full state set, and rerun the project checks.',
|
|
277
|
+
'Repeat the read-only review on the new revision. Keep the first report so the improvement and every remaining tradeoff stay visible.',
|
|
278
|
+
],
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
type: 'prose',
|
|
282
|
+
text: 'For an integration template, finish with the scored package and copy workflow in {@link generic:grade-template-with-agent}. Ordinary product code stops with the evidence-backed category report and does not receive a template publication grade.',
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
};
|
|
@@ -102,7 +102,11 @@ const gradeRows = TEMPLATE_RUBRIC.grades.map(({grade, min, max, meaning}) => [
|
|
|
102
102
|
export const docs = {
|
|
103
103
|
type: 'generic',
|
|
104
104
|
name: 'template-grading-rubric',
|
|
105
|
-
placement: {
|
|
105
|
+
placement: {
|
|
106
|
+
parent: 'namespace:write-good-templates',
|
|
107
|
+
slot: 'guides',
|
|
108
|
+
order: 10,
|
|
109
|
+
},
|
|
106
110
|
title: 'Full grading rubric',
|
|
107
111
|
category: 'guide',
|
|
108
112
|
description:
|
|
@@ -112,6 +116,10 @@ export const docs = {
|
|
|
112
116
|
id: 'understand-the-score',
|
|
113
117
|
title: 'Understand the score',
|
|
114
118
|
content: [
|
|
119
|
+
{
|
|
120
|
+
type: 'prose',
|
|
121
|
+
text: 'Start with {@link generic:is-my-code-good}: it owns the shared Astryx quality criteria. This rubric adds template weights, counting rules, and template-only checks, and each category that scores a shared criterion names it.',
|
|
122
|
+
},
|
|
115
123
|
{
|
|
116
124
|
type: 'prose',
|
|
117
125
|
text: `Template rubric ${TEMPLATE_RUBRIC.version} scores seven categories for 100 points. Aim for 100; ${TEMPLATE_RUBRIC.minimumGrade} (${TEMPLATE_RUBRIC.minimumScore}) is the publication floor, not the target. Each category below lists its weight. Never award points for anything you did not inspect.`,
|
|
@@ -137,11 +145,11 @@ export const docs = {
|
|
|
137
145
|
content: [
|
|
138
146
|
{
|
|
139
147
|
type: 'prose',
|
|
140
|
-
text: 'Count every JSX opening tag in the copied `.tsx` source. An Astryx element is a component imported from `@astryxdesign/core` or from a public component export of the integration package. A raw HTML element is any lowercase intrinsic JSX tag. Count occurrences, not only unique tag names.',
|
|
148
|
+
text: 'This category scores the Astryx components criterion in {@link generic:is-my-code-good}. Count every JSX opening tag in the copied `.tsx` source. An Astryx element is a component imported from `@astryxdesign/core` or from a public component export of the integration package. A raw HTML element is any lowercase intrinsic JSX tag. Count occurrences, not only unique tag names.',
|
|
141
149
|
},
|
|
142
150
|
{
|
|
143
151
|
type: 'prose',
|
|
144
|
-
text: 'Do not count fragments or a PascalCase helper defined in the same file. Inspect that helper and count the raw HTML inside it. For each raw element, decide whether it is necessary because Astryx has no equivalent, or unnecessary because an Astryx component can replace it.',
|
|
152
|
+
text: 'Do not count fragments or a PascalCase helper defined in the same file. Inspect that helper and count the raw HTML inside it. For each raw element, decide with that guide whether it is necessary because Astryx has no equivalent, or unnecessary because an Astryx component can replace it.',
|
|
145
153
|
},
|
|
146
154
|
{
|
|
147
155
|
type: 'table',
|
|
@@ -156,35 +164,6 @@ export const docs = {
|
|
|
156
164
|
['21 or more', '0'],
|
|
157
165
|
],
|
|
158
166
|
},
|
|
159
|
-
{
|
|
160
|
-
type: 'table',
|
|
161
|
-
headers: ['Raw HTML use', 'Astryx replacement'],
|
|
162
|
-
rows: [
|
|
163
|
-
[
|
|
164
|
-
'`div` for layout',
|
|
165
|
-
'`VStack`, `HStack`, `Card`, `Section`, or `Center`',
|
|
166
|
-
],
|
|
167
|
-
['`div` for a grid', '`Grid`'],
|
|
168
|
-
['`span` or `p` for text', '`Text`'],
|
|
169
|
-
['`h1` through `h6`', '`Heading level={N}`'],
|
|
170
|
-
['`button`', '`Button` or `IconButton`'],
|
|
171
|
-
['`a`', '`Link`'],
|
|
172
|
-
['In-page `nav` or `aside`', '`LayoutPanel` in the start slot'],
|
|
173
|
-
[
|
|
174
|
-
'`header` or `main`',
|
|
175
|
-
'`LayoutHeader` or `LayoutContent` in `Layout`',
|
|
176
|
-
],
|
|
177
|
-
['`ul`, `ol`, or `li`', '`List` and `ListItem`'],
|
|
178
|
-
[
|
|
179
|
-
'`input`, `textarea`, or `select`',
|
|
180
|
-
'The matching Astryx form control',
|
|
181
|
-
],
|
|
182
|
-
['`table`, `tr`, or `td`', '`Table`'],
|
|
183
|
-
['`hr`', '`Divider`'],
|
|
184
|
-
['`dialog`', '`Dialog`'],
|
|
185
|
-
['`details` or `summary`', '`Collapsible`'],
|
|
186
|
-
],
|
|
187
|
-
},
|
|
188
167
|
{
|
|
189
168
|
type: 'list',
|
|
190
169
|
style: 'unordered',
|
|
@@ -202,7 +181,7 @@ export const docs = {
|
|
|
202
181
|
content: [
|
|
203
182
|
{
|
|
204
183
|
type: 'prose',
|
|
205
|
-
text: 'Count raw icon markup in the copied file. {@link generic:template-icons} shows how to render icons through Astryx instead.',
|
|
184
|
+
text: 'This category scores the Icons criterion in {@link generic:is-my-code-good}. Count raw icon markup in the copied file. {@link generic:template-icons} shows how to render icons through Astryx instead.',
|
|
206
185
|
},
|
|
207
186
|
{
|
|
208
187
|
type: 'list',
|
|
@@ -231,7 +210,7 @@ export const docs = {
|
|
|
231
210
|
content: [
|
|
232
211
|
{
|
|
233
212
|
type: 'prose',
|
|
234
|
-
text: '
|
|
213
|
+
text: 'This category scores the Styling criterion in {@link generic:is-my-code-good}. Count individual CSS properties inside `stylex.create` and inline `style` objects. Count each `className` and `stylex.props` use once. Do not count Astryx props such as `gap`, `padding`, `variant`, `size`, `color`, `level`, `columns`, `contentPadding`, or `height`.',
|
|
235
214
|
},
|
|
236
215
|
{
|
|
237
216
|
type: 'table',
|
|
@@ -260,7 +239,7 @@ export const docs = {
|
|
|
260
239
|
type: 'list',
|
|
261
240
|
style: 'ordered',
|
|
262
241
|
items: [
|
|
263
|
-
'
|
|
242
|
+
'Choose the page root with the Layout criterion in {@link generic:is-my-code-good}. In a template, only a category that starts with `Shell -` owns global chrome, so it uses `AppShell`; every other page template uses `Layout` or `Center`.',
|
|
264
243
|
'Outside a `Shell -` template, leave global navigation to the host app. Put in-page navigation in a `LayoutPanel` and page headings in `LayoutHeader`.',
|
|
265
244
|
'Use `Grid` with `columns={{minWidth: 280}}` for responsive collections. Do not fix the column count or rebuild the grid in raw CSS.',
|
|
266
245
|
'Use `Center` for centered content instead of custom flexbox workarounds.',
|
|
@@ -385,7 +364,7 @@ export const docs = {
|
|
|
385
364
|
content: [
|
|
386
365
|
{
|
|
387
366
|
type: 'prose',
|
|
388
|
-
text: 'Inspect every image reference in the copied file against {@link generic:template-images-media}.',
|
|
367
|
+
text: 'This category scores the Images and assets criterion in {@link generic:is-my-code-good}. Inspect every image reference in the copied file against {@link generic:template-images-media}.',
|
|
389
368
|
},
|
|
390
369
|
{
|
|
391
370
|
type: 'table',
|
|
@@ -413,7 +392,7 @@ export const docs = {
|
|
|
413
392
|
content: [
|
|
414
393
|
{
|
|
415
394
|
type: 'prose',
|
|
416
|
-
text: 'Award 2 points for each condition. Grade the copied file, not only the package source.',
|
|
395
|
+
text: 'This category scores the Code health criterion in {@link generic:is-my-code-good}, plus conditions only a template has. Award 2 points for each condition. Grade the copied file, not only the package source.',
|
|
417
396
|
},
|
|
418
397
|
{
|
|
419
398
|
type: 'table',
|
|
@@ -291,6 +291,32 @@ describe('Project.load', () => {
|
|
|
291
291
|
});
|
|
292
292
|
});
|
|
293
293
|
|
|
294
|
+
describe('Project.issues and a near-miss manifest key', () => {
|
|
295
|
+
it.each([
|
|
296
|
+
[
|
|
297
|
+
'alone, while the loaded integration fills providerId from the package name',
|
|
298
|
+
{providerID: '@acme/widgets'},
|
|
299
|
+
'Fix: rename "providerID" to "providerId" in astryx.integration.mjs.',
|
|
300
|
+
],
|
|
301
|
+
[
|
|
302
|
+
'beside the key it suggests',
|
|
303
|
+
{providerID: '@acme/widgets', providerId: '@acme/widgets'},
|
|
304
|
+
'Fix: remove "providerID" from astryx.integration.mjs; it already sets "providerId".',
|
|
305
|
+
],
|
|
306
|
+
])(
|
|
307
|
+
'reads the keys the manifest declares: providerID %s',
|
|
308
|
+
async (_label, unknownKeys, fix) => {
|
|
309
|
+
scaffold({unknownKeys});
|
|
310
|
+
const project = await Project.load(tmpDir);
|
|
311
|
+
const keys = (await project.issues()).filter(
|
|
312
|
+
issue => issue.code === 'unknown_manifest_key',
|
|
313
|
+
);
|
|
314
|
+
expect(keys).toHaveLength(1);
|
|
315
|
+
expect(keys[0].message).toContain(fix);
|
|
316
|
+
},
|
|
317
|
+
);
|
|
318
|
+
});
|
|
319
|
+
|
|
294
320
|
describe('Project.load and the cliCommand an integration declares', () => {
|
|
295
321
|
it('records it, so the picker prints commands with it', async () => {
|
|
296
322
|
scaffold({cliCommand: 'acme astryx'});
|
|
@@ -1192,6 +1192,23 @@ function reportSamePackageReplacements(pkg, autolinked, templates, errors) {
|
|
|
1192
1192
|
}
|
|
1193
1193
|
}
|
|
1194
1194
|
|
|
1195
|
+
/**
|
|
1196
|
+
* The fix for a template doc with no same-stem `.tsx`: rename a same-stem
|
|
1197
|
+
* source written in another extension, or add the `.tsx`.
|
|
1198
|
+
* @param {string} docPath
|
|
1199
|
+
* @param {string} sourcePath the `.tsx` it needs
|
|
1200
|
+
*/
|
|
1201
|
+
function missingTemplateSourceFix(docPath, sourcePath) {
|
|
1202
|
+
const source = path.basename(sourcePath);
|
|
1203
|
+
const stem = source.slice(0, -'.tsx'.length);
|
|
1204
|
+
const other = ['.jsx', '.js', '.ts', '.mjs']
|
|
1205
|
+
.map(extension => `${stem}${extension}`)
|
|
1206
|
+
.find(file => fs.existsSync(path.join(path.dirname(sourcePath), file)));
|
|
1207
|
+
return other
|
|
1208
|
+
? `Found ${other}, but a template source must be a .tsx file. Fix: rename ${other} to ${source}.`
|
|
1209
|
+
: `Fix: add ${source} beside ${path.basename(docPath)}, with the template as its default export.`;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1195
1212
|
/**
|
|
1196
1213
|
* Discover the templates contributed by a SINGLE integration. Same per-template
|
|
1197
1214
|
* rules as {@link discoverIntegrationTemplates} (same-stem source required,
|
|
@@ -1225,7 +1242,7 @@ export async function discoverIntegrationTemplatesForOne(integration) {
|
|
|
1225
1242
|
errors.push({
|
|
1226
1243
|
package: pkgLabel,
|
|
1227
1244
|
template: id,
|
|
1228
|
-
message: `Template "${id}" is missing its same-stem source file ${path.basename(sourcePath)}
|
|
1245
|
+
message: `Template "${id}" is missing its same-stem source file ${path.basename(sourcePath)}. ${missingTemplateSourceFix(docPath, sourcePath)}`,
|
|
1229
1246
|
});
|
|
1230
1247
|
// A replacement this unusable template declares still counts, so its
|
|
1231
1248
|
// target fails closed instead of going to a sibling.
|
|
@@ -22,6 +22,7 @@ import * as path from 'node:path';
|
|
|
22
22
|
import {lowerDoc} from '../doc-compiler/compile.mjs';
|
|
23
23
|
import {packageSource} from '../doc-compiler/source.mjs';
|
|
24
24
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
25
|
+
import {formatCliCommand} from '../env/package-manager.mjs';
|
|
25
26
|
import {LOCAL_THEME_ROOT} from '../config/theme-state.mjs';
|
|
26
27
|
import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
27
28
|
|
|
@@ -958,6 +959,126 @@ function declaresThemeDoc(ast, exportDefault) {
|
|
|
958
959
|
});
|
|
959
960
|
}
|
|
960
961
|
|
|
962
|
+
/**
|
|
963
|
+
* Whether a file is the module `astryx theme build` writes rather than a
|
|
964
|
+
* theme source: plain JavaScript that carries the build's generated header
|
|
965
|
+
* and never calls defineTheme.
|
|
966
|
+
* @param {string} file
|
|
967
|
+
*/
|
|
968
|
+
function isBuiltThemeModule(file) {
|
|
969
|
+
if (!/\.m?js$/u.test(file)) return false;
|
|
970
|
+
let text;
|
|
971
|
+
try {
|
|
972
|
+
text = fs.readFileSync(file, 'utf8');
|
|
973
|
+
} catch {
|
|
974
|
+
return false;
|
|
975
|
+
}
|
|
976
|
+
return (
|
|
977
|
+
/@generated by `astryx theme build`/u.test(text) &&
|
|
978
|
+
!/\bdefineTheme\b/u.test(text)
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* The fix when a descriptor's stem names both a theme source and the module
|
|
984
|
+
* `astryx theme build` writes beside it (`brand.ts` and its built `brand.js`):
|
|
985
|
+
* the build names its output after the theme, so the source and descriptor
|
|
986
|
+
* take the `<name>Theme` stem instead. Null when no built module is among
|
|
987
|
+
* the matches, or the stem already ends in `Theme`.
|
|
988
|
+
* @param {string} sourceDir
|
|
989
|
+
* @param {string[]} sources same-stem module file names
|
|
990
|
+
* @param {string} doc the descriptor's file name
|
|
991
|
+
* @param {string} exportName the descriptor's stem
|
|
992
|
+
* @returns {string | null}
|
|
993
|
+
*/
|
|
994
|
+
function builtThemeSourceFix(sourceDir, sources, doc, exportName) {
|
|
995
|
+
if (exportName.endsWith('Theme')) return null;
|
|
996
|
+
const built = sources.filter(file =>
|
|
997
|
+
isBuiltThemeModule(path.join(sourceDir, file)),
|
|
998
|
+
);
|
|
999
|
+
const source = sources.filter(file => !built.includes(file));
|
|
1000
|
+
if (built.length === 0 || source.length !== 1) return null;
|
|
1001
|
+
const extension = source[0].slice(exportName.length);
|
|
1002
|
+
const stem = `${exportName}Theme`;
|
|
1003
|
+
return `Fix: ${built.map(file => `"${file}"`).join(', ')} is the module \`${formatCliCommand('theme build', sourceDir)}\` writes, which takes the theme's name; rename ${source[0]} to ${stem}${extension} and ${doc} to ${stem}${THEME_DOC_SUFFIX}, export \`${stem}\` from it, and build again.`;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* Why a descriptor pairs with the built module and the built module lacks
|
|
1008
|
+
* the export the descriptor's stem names (`ocean.doc.mjs` beside a built
|
|
1009
|
+
* `ocean.js` that exports `oceanTheme`): the descriptor is named for the
|
|
1010
|
+
* build's output, not the theme's source. The source is named only when the
|
|
1011
|
+
* built module's `Source:` header, or a source whose defineTheme gives the
|
|
1012
|
+
* theme's name, confirms it; otherwise the message stays generic. Null when
|
|
1013
|
+
* the entry is not a built module.
|
|
1014
|
+
* @param {string} label the descriptor, as messages name it
|
|
1015
|
+
* @param {string} sourceDir
|
|
1016
|
+
* @param {string} entry the file the descriptor pairs with
|
|
1017
|
+
* @param {string} exportName the descriptor's stem
|
|
1018
|
+
* @param {string} doc the descriptor's file name
|
|
1019
|
+
* @param {string} slug the theme's name
|
|
1020
|
+
* @param {string[]} files the theme folder's files
|
|
1021
|
+
* @returns {string | null}
|
|
1022
|
+
*/
|
|
1023
|
+
function builtModuleDescriptorMessage(
|
|
1024
|
+
label,
|
|
1025
|
+
sourceDir,
|
|
1026
|
+
entry,
|
|
1027
|
+
exportName,
|
|
1028
|
+
doc,
|
|
1029
|
+
slug,
|
|
1030
|
+
files,
|
|
1031
|
+
) {
|
|
1032
|
+
if (!isBuiltThemeModule(path.join(sourceDir, entry))) return null;
|
|
1033
|
+
const source = confirmedThemeSource(sourceDir, entry, slug, files);
|
|
1034
|
+
const head = `${label} shares its stem with the built module "${entry}", which does not export "${exportName}": a descriptor must share its stem with the source that calls defineTheme.`;
|
|
1035
|
+
if (source == null) {
|
|
1036
|
+
return `${head} Fix: rename ${doc} to share its stem with the theme's source (the module that calls defineTheme, such as ${exportName}Theme.ts).`;
|
|
1037
|
+
}
|
|
1038
|
+
const stem = source.replace(/\.[^.]+$/u, '');
|
|
1039
|
+
return `${head} The theme's source is "${source}". Fix: rename ${doc} to ${stem}${THEME_DOC_SUFFIX}.`;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* The theme's source, when something confirms it: the file the built
|
|
1044
|
+
* module's `Source:` header names, if it is in the folder, else the one
|
|
1045
|
+
* module in the folder whose defineTheme gives the theme's name as a
|
|
1046
|
+
* literal. Null otherwise: a `<name>Theme` file alone may be a helper.
|
|
1047
|
+
* @param {string} sourceDir
|
|
1048
|
+
* @param {string} built the built module's file name
|
|
1049
|
+
* @param {string} slug
|
|
1050
|
+
* @param {string[]} files
|
|
1051
|
+
* @returns {string | null}
|
|
1052
|
+
*/
|
|
1053
|
+
function confirmedThemeSource(sourceDir, built, slug, files) {
|
|
1054
|
+
const own = files.filter(
|
|
1055
|
+
file =>
|
|
1056
|
+
!file.includes('/') &&
|
|
1057
|
+
file !== built &&
|
|
1058
|
+
THEME_MODULE_EXTENSIONS.some(extension => file.endsWith(extension)),
|
|
1059
|
+
);
|
|
1060
|
+
/** @param {string} file */
|
|
1061
|
+
const read = file => {
|
|
1062
|
+
try {
|
|
1063
|
+
return fs.readFileSync(path.join(sourceDir, file), 'utf8');
|
|
1064
|
+
} catch {
|
|
1065
|
+
return '';
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
const header = /^\s*\*?\s*Source:\s*(\S+)\s*$/mu.exec(read(built));
|
|
1069
|
+
if (header) {
|
|
1070
|
+
const named = path.posix.basename(header[1].replace(/\\/gu, '/'));
|
|
1071
|
+
if (own.includes(named)) return named;
|
|
1072
|
+
}
|
|
1073
|
+
const quoted = slug.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
1074
|
+
const naming = new RegExp(
|
|
1075
|
+
`\\bdefineTheme\\s*\\(\\s*\\{[^}]*\\bname\\s*:\\s*['"\`]${quoted}['"\`]`,
|
|
1076
|
+
'u',
|
|
1077
|
+
);
|
|
1078
|
+
const matches = own.filter(file => naming.test(read(file)));
|
|
1079
|
+
return matches.length === 1 ? matches[0] : null;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
961
1082
|
/** A module named for the theme it exports, such as `oceanTheme.ts`. */
|
|
962
1083
|
const THEME_SOURCE_RE = /^[$A-Z_a-z][$\w]*Theme\.(?:mjs|js|mts|ts|tsx|jsx)$/u;
|
|
963
1084
|
|
|
@@ -1240,8 +1361,17 @@ export function discoverThemeDirectory(
|
|
|
1240
1361
|
: evidence.includes('/')
|
|
1241
1362
|
? `; "${evidence}" is in a subfolder`
|
|
1242
1363
|
: ` beside "${evidence}"`;
|
|
1364
|
+
const themeDoc = formatCliCommand('docs authoring theme-doc', sourceDir);
|
|
1365
|
+
const fix =
|
|
1366
|
+
docs.length > 1
|
|
1367
|
+
? `Fix: keep the one descriptor that shares its stem with the theme's source and delete the rest.`
|
|
1368
|
+
: evidence.includes('/')
|
|
1369
|
+
? `Fix: move "${evidence}" up into ${slug}/, beside where its descriptor goes.`
|
|
1370
|
+
: THEME_SOURCE_RE.test(evidence)
|
|
1371
|
+
? `Fix: add ${evidence.replace(/\.[^.]+$/u, '')}${THEME_DOC_SUFFIX} beside it with type: 'theme' and name: '${slug}'; \`${themeDoc}\` lists its fields.`
|
|
1372
|
+
: `Fix: add a descriptor that shares its stem with the theme's source, with type: 'theme' and name: '${slug}'; \`${themeDoc}\` lists its fields.`;
|
|
1243
1373
|
throw new Error(
|
|
1244
|
-
`${theme} must contain exactly one same-stem .doc.mjs descriptor; found ${docs.length}${detail}
|
|
1374
|
+
`${theme} must contain exactly one same-stem .doc.mjs descriptor; found ${docs.length}${detail}. ${fix}`,
|
|
1245
1375
|
);
|
|
1246
1376
|
}
|
|
1247
1377
|
const nested = descriptors.find(file => file.includes('/'));
|
|
@@ -1267,8 +1397,13 @@ export function discoverThemeDirectory(
|
|
|
1267
1397
|
extension => `${exportName}${extension}`,
|
|
1268
1398
|
).filter(file => listing.files.includes(file));
|
|
1269
1399
|
if (sources.length !== 1) {
|
|
1400
|
+
const fix =
|
|
1401
|
+
sources.length > 1
|
|
1402
|
+
? (builtThemeSourceFix(sourceDir, sources, docs[0], exportName) ??
|
|
1403
|
+
`Fix: keep one of them; the theme's source is a single module.`)
|
|
1404
|
+
: `Fix: add ${exportName}.ts beside ${docs[0]}, exporting \`${exportName}\` from defineTheme.`;
|
|
1270
1405
|
throw new Error(
|
|
1271
|
-
`${theme} must contain exactly one same-stem source for ${docs[0]}; found ${sources.length}${sources.length > 1 ? `: ${quoted(sources)}` : ''}
|
|
1406
|
+
`${theme} must contain exactly one same-stem source for ${docs[0]}; found ${sources.length}${sources.length > 1 ? `: ${quoted(sources)}` : ''}. ${fix}`,
|
|
1272
1407
|
);
|
|
1273
1408
|
}
|
|
1274
1409
|
|
|
@@ -1314,7 +1449,16 @@ export function discoverThemeDirectory(
|
|
|
1314
1449
|
)
|
|
1315
1450
|
) {
|
|
1316
1451
|
throw new ThemeRuntimeExportError(
|
|
1317
|
-
|
|
1452
|
+
builtModuleDescriptorMessage(
|
|
1453
|
+
label,
|
|
1454
|
+
sourceDir,
|
|
1455
|
+
entry,
|
|
1456
|
+
exportName,
|
|
1457
|
+
docs[0],
|
|
1458
|
+
slug,
|
|
1459
|
+
listing.files,
|
|
1460
|
+
) ??
|
|
1461
|
+
`Theme "${slug}" for ${owner} entry "${entry}" does not export "${exportName}".`,
|
|
1318
1462
|
);
|
|
1319
1463
|
}
|
|
1320
1464
|
} catch (error) {
|