@astryxdesign/cli 0.7.0-canary.450c68d → 0.7.0-canary.4ec1f4e
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/README.md +30 -33
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.test.mjs +28 -0
- package/api/doctor/theme-checks.mjs +10 -10
- package/api/doctor/theme-checks.test.mjs +5 -4
- package/api/gap-report/gap-report.doc.mjs +1 -1
- package/api/gap-report/gap-report.mjs +15 -0
- package/api/gap-report/gap-report.test.mjs +1 -1
- package/api/index.d.mts +0 -2
- package/api/index.mjs +0 -2
- package/api/init/init.doc.mjs +5 -1
- package/api/init/init.mjs +22 -0
- package/api/init/init.type.d.mts +4 -1
- package/api/init/init.type.mjs +1 -1
- package/api/init/remove/remove.mjs +8 -3
- package/api/init/remove/remove.test.mjs +12 -0
- package/api/init/run/run.d.mts +1 -1
- package/api/init/run/run.mjs +3 -3
- package/api/integration/validate-integration.d.mts +4 -0
- package/api/integration/validate-integration.mjs +5 -2
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/json/index.ts +0 -1
- package/api/search/search.doc.mjs +1 -1
- package/api/search/search.mjs +1 -1
- package/api/search/search.test.mjs +1 -1
- package/api/search/search.type.d.mts +1 -1
- package/api/search/search.type.mjs +1 -1
- package/api/template/template-integration.test.mjs +37 -100
- package/api/template/template.doc.mjs +5 -1
- package/api/template/template.mjs +45 -0
- package/api/theme/_adapter.mjs +3 -3
- package/api/theme/add/add.d.mts +11 -5
- package/api/theme/add/add.mjs +19 -192
- package/api/theme/add/add.test.mjs +68 -258
- package/api/theme/add/add.types.test.mjs +0 -1
- package/api/theme/build/build.d.mts +3 -3
- package/api/theme/build/build.mjs +22 -36
- package/api/theme/build/build.test.mjs +11 -24
- package/api/theme/eject/eject.copy-compat.test.mjs +168 -0
- package/api/theme/integration-themes.test.mjs +3 -3
- package/api/theme/remove/remove.test.mjs +1 -1
- package/api/theme/targets/targets.test.mjs +0 -4
- package/api/theme/template/template.mjs +1 -1
- package/api/theme/theme.type.d.mts +1 -30
- package/api/theme/theme.type.mjs +3 -13
- package/api/theme/themeAdd.doc.mjs +19 -27
- package/api/theme/themeTargets.doc.mjs +3 -4
- package/api/theme/themeTemplate.doc.mjs +1 -1
- package/api/theme/use/use.test.mjs +1 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.mjs +19 -0
- package/assets/codemods/transforms/next/README.md +15 -17
- package/assets/codemods/transforms/next/__tests__/migrate-deprecated-theme-surface.test.mjs +322 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-deprecated-theme-surface-v0.6-data.mjs +229 -0
- package/assets/codemods/transforms/next/migrate-deprecated-theme-surface.mjs +624 -0
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +38 -18
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/getting-started.doc.mjs +2 -2
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +2 -2
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +2 -2
- package/assets/docs/tree/fonts-and-assets.doc.mjs +3 -3
- package/assets/docs/tree/styling-advanced.doc.mjs +21 -14
- package/assets/docs/tree/themes.doc.mjs +1 -1
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +2 -2
- package/assets/docs/tree/versioning.doc.mjs +1 -4
- package/assets/docs/use-a-theme.doc.mjs +16 -16
- package/authoring/debug/type.ts +2 -2
- package/authoring/doctypes/base/type.ts +0 -9
- package/authoring/integration/integration.doc.mjs +1 -1
- package/clients/cli/command-result-coverage.test.mjs +1 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +4 -0
- package/clients/cli/commands/build-theme.ascii-output.test.mjs +35 -8
- package/clients/cli/commands/build-theme.mjs +31 -67
- package/clients/cli/commands/build-theme.registry.test.mjs +0 -10
- package/clients/cli/commands/debug-result-summary.test.mjs +0 -16
- package/clients/cli/commands/discover.mjs +2 -1
- package/clients/cli/commands/doctor.mjs +5 -2
- package/clients/cli/commands/empty-argument.test.mjs +16 -0
- package/clients/cli/commands/gap-report.doc.mjs +1 -1
- package/clients/cli/commands/gap-report.test.mjs +2 -2
- package/clients/cli/commands/init.doc.mjs +4 -4
- package/clients/cli/commands/init.flag-help.test.mjs +7 -10
- package/clients/cli/commands/init.next-steps.test.mjs +1 -1
- package/clients/cli/commands/option-pair-refusals.test.mjs +37 -0
- package/clients/cli/commands/search.test.mjs +1 -1
- package/clients/cli/commands/swizzle.mjs +4 -1
- package/clients/cli/commands/template.doc.mjs +3 -3
- package/clients/cli/commands/template.flag-help.test.mjs +18 -11
- package/clients/cli/commands/template.mjs +7 -1
- package/clients/cli/commands/text-json-parity.test.mjs +0 -17
- package/clients/cli/commands/theme-add-lifecycle.test.mjs +142 -49
- package/clients/cli/commands/theme-add.doc.mjs +10 -17
- package/clients/cli/commands/theme-list.behavior.test.mjs +2 -1
- package/clients/cli/commands/theme-targets.behavior.test.mjs +8 -6
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +2 -2
- package/clients/cli/commands/upgrade.doc.mjs +1 -1
- package/clients/cli/commands/upgrade.flag-help.test.mjs +7 -11
- package/clients/cli/commands/validate-nothing-exits-nonzero.test.mjs +67 -0
- package/clients/cli/index.mjs +0 -4
- package/clients/cli/lib/cli-error.mjs +19 -0
- package/clients/cli/lib/component-format.mjs +111 -57
- package/clients/cli/lib/component-format.test.mjs +28 -39
- package/clients/cli/lib/doc-text-ascii.test.mjs +5 -2
- package/clients/cli/lib/exit-codes.test.mjs +0 -7
- package/clients/cli/lib/json-shim.test.mjs +0 -24
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +6 -1
- package/foundation/agent-docs/app-theme-workflow.test.mjs +3 -0
- package/foundation/config/theme-state.mjs +3 -3
- package/foundation/debug/debug-fields.test.mjs +13 -35
- package/foundation/debug/event.mjs +13 -78
- package/foundation/debug/privacy-contract.test.mjs +20 -12
- package/foundation/debug/redact.d.mts +2 -2
- package/foundation/debug/redact.mjs +2 -2
- package/foundation/discovery/theme-imports.mjs +1 -1
- package/foundation/discovery/theming-targets.d.mts +1 -20
- package/foundation/discovery/theming-targets.mjs +1 -38
- package/foundation/discovery/theming-targets.test.mjs +9 -175
- package/foundation/doc-compiler/doc-loads.test.mjs +0 -12
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +11 -30
- package/foundation/response/response-types.doc.test.mjs +36 -14
- package/foundation/response/response.doc.mjs +1 -1
- package/foundation/xle/browser.d.mts +2 -2
- package/foundation/xle/browser.mjs +2 -2
- package/foundation/xle/expand.mjs +1 -1
- package/foundation/xle/print.mjs +1 -1
- package/package.json +9 -9
- package/api/layout/_adapter.d.mts +0 -34
- package/api/layout/_adapter.mjs +0 -148
- package/api/layout/check/check.d.mts +0 -17
- package/api/layout/check/check.mjs +0 -41
- package/api/layout/expand/expand.d.mts +0 -23
- package/api/layout/expand/expand.mjs +0 -161
- package/api/layout/expand/expand.path-safety.test.mjs +0 -53
- package/api/layout/expand/expand.receipt.test.mjs +0 -74
- package/api/layout/grammar/grammar.d.mts +0 -14
- package/api/layout/grammar/grammar.mjs +0 -88
- package/api/layout/layout.d.mts +0 -6
- package/api/layout/layout.mjs +0 -17
- package/api/layout/layout.test.mjs +0 -297
- package/api/layout/layout.type.d.mts +0 -90
- package/api/layout/layout.type.mjs +0 -104
- package/api/layout/layoutCheck.doc.d.mts +0 -11
- package/api/layout/layoutCheck.doc.mjs +0 -85
- package/api/layout/layoutExpand.doc.d.mts +0 -11
- package/api/layout/layoutExpand.doc.mjs +0 -107
- package/api/layout/layoutGrammar.doc.d.mts +0 -11
- package/api/layout/layoutGrammar.doc.mjs +0 -57
- package/api/theme/add/add.binary.test.mjs +0 -157
- package/api/theme/add/add.rollback.test.mjs +0 -158
- package/api/theme/add/add.staging.test.mjs +0 -83
- package/clients/cli/commands/layout-check.doc.mjs +0 -67
- package/clients/cli/commands/layout-expand.doc.mjs +0 -87
- package/clients/cli/commands/layout-grammar.doc.mjs +0 -32
- package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +0 -140
- package/clients/cli/commands/layout.doc.mjs +0 -36
- package/clients/cli/commands/layout.error-codes.test.mjs +0 -66
- package/clients/cli/commands/layout.exit-parity.test.mjs +0 -41
- package/clients/cli/commands/layout.expand-receipt.test.mjs +0 -94
- package/clients/cli/commands/layout.mjs +0 -327
- package/clients/cli/commands/layout.path-help.test.mjs +0 -33
- package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
- package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
* @file Component doc formatting — render ComponentDoc objects to text
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
discoverComponents,
|
|
9
|
+
findComponentReadme,
|
|
10
|
+
resolveImportPath,
|
|
11
|
+
} from '../../../foundation/discovery/component-discovery.mjs';
|
|
8
12
|
import {loadDocs} from '../../../foundation/discovery/component-loader.mjs';
|
|
9
13
|
import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
|
|
10
14
|
|
|
@@ -26,15 +30,6 @@ function targetKey(target) {
|
|
|
26
30
|
return target.className.replace(/^astryx-/, '');
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
/**
|
|
30
|
-
* Keep deprecated targets visible in reference tables while excluding them from
|
|
31
|
-
* snippets readers copy into newly authored themes.
|
|
32
|
-
* @param {import('@astryxdesign/cli/authoring').ComponentThemingTarget[]} targets
|
|
33
|
-
*/
|
|
34
|
-
function canonicalTargets(targets) {
|
|
35
|
-
return targets.filter(target => target.deprecatedFor == null);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
33
|
/** @param {string} name @returns {string} */
|
|
39
34
|
function dataAttrForName(name) {
|
|
40
35
|
return `data-${name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()}`;
|
|
@@ -117,7 +112,9 @@ function formatSubComponent(comp) {
|
|
|
117
112
|
if (table) {
|
|
118
113
|
out.push(table + '\n');
|
|
119
114
|
} else {
|
|
120
|
-
out.push(
|
|
115
|
+
out.push(
|
|
116
|
+
`See \`${getCliInvocation()} component ${comp.name}\` for props and usage.\n`,
|
|
117
|
+
);
|
|
121
118
|
}
|
|
122
119
|
return out;
|
|
123
120
|
}
|
|
@@ -136,8 +133,10 @@ function getTargetVariants(target, docs) {
|
|
|
136
133
|
|
|
137
134
|
// If variant is a visualProp, try to resolve the actual variant values from props
|
|
138
135
|
if (target.visualProps.includes('variant')) {
|
|
139
|
-
const allProps = docs.props ||
|
|
140
|
-
const variantProp = allProps.find(
|
|
136
|
+
const allProps = docs.props || docs.components?.[0]?.props || [];
|
|
137
|
+
const variantProp = allProps.find(
|
|
138
|
+
(/** @type {any} */ p) => p.name === 'variant',
|
|
139
|
+
);
|
|
141
140
|
if (variantProp && variantProp.type.includes('|')) {
|
|
142
141
|
return variantProp.type
|
|
143
142
|
.replace(/['"]/g, '')
|
|
@@ -172,8 +171,12 @@ function formatTargetsTable(docs, themeData) {
|
|
|
172
171
|
|
|
173
172
|
/** @type {string[]} */
|
|
174
173
|
const lines = [];
|
|
175
|
-
lines.push(
|
|
176
|
-
|
|
174
|
+
lines.push(
|
|
175
|
+
'| Component class | Preferred data attributes | Props | States |',
|
|
176
|
+
);
|
|
177
|
+
lines.push(
|
|
178
|
+
'|-----------------|---------------------------|-------|--------|',
|
|
179
|
+
);
|
|
177
180
|
|
|
178
181
|
for (const target of docs.theming.targets) {
|
|
179
182
|
const coreVariants = getTargetVariants(target, docs);
|
|
@@ -194,11 +197,11 @@ function formatTargetsTable(docs, themeData) {
|
|
|
194
197
|
const statesStr = states.length > 0 ? states.join(', ') : '-';
|
|
195
198
|
const dataAttrs = getTargetDataAttributes(target);
|
|
196
199
|
const dataAttrsStr =
|
|
197
|
-
dataAttrs.length > 0
|
|
200
|
+
dataAttrs.length > 0
|
|
201
|
+
? dataAttrs.map(attr => `\`${attr}\``).join(', ')
|
|
202
|
+
: '-';
|
|
198
203
|
|
|
199
|
-
const className = target.
|
|
200
|
-
? `\`${target.className}\` _(deprecated; use \`${target.deprecatedFor}\`)_`
|
|
201
|
-
: `\`${target.className}\``;
|
|
204
|
+
const className = `\`${target.className}\``;
|
|
202
205
|
lines.push(
|
|
203
206
|
`| ${className} | ${dataAttrsStr} | ${variantsStr} | ${statesStr} |`,
|
|
204
207
|
);
|
|
@@ -229,7 +232,9 @@ export function formatFull(docs, options = {}) {
|
|
|
229
232
|
// agents to conflate the primary with a sub-component and hallucinate props
|
|
230
233
|
// (origin/main #2860). Bare name per the un-prefix migration (P5a).
|
|
231
234
|
const displayName = docs.name;
|
|
232
|
-
sections.push(
|
|
235
|
+
sections.push(
|
|
236
|
+
`**Import:** \`import {${displayName}} from '${options.importHint}';\`\n`,
|
|
237
|
+
);
|
|
233
238
|
}
|
|
234
239
|
|
|
235
240
|
if (docs.usage?.anatomy?.length) {
|
|
@@ -238,7 +243,9 @@ export function formatFull(docs, options = {}) {
|
|
|
238
243
|
sections.push('|---------|----------|-------------|');
|
|
239
244
|
for (const el of docs.usage.anatomy) {
|
|
240
245
|
const req = el.required ? 'Yes' : 'No';
|
|
241
|
-
sections.push(
|
|
246
|
+
sections.push(
|
|
247
|
+
`| ${mdCell(el.name)} | ${req} | ${mdCell(el.description)} |`,
|
|
248
|
+
);
|
|
242
249
|
}
|
|
243
250
|
sections.push('');
|
|
244
251
|
}
|
|
@@ -246,7 +253,7 @@ export function formatFull(docs, options = {}) {
|
|
|
246
253
|
if (docs.usage?.bestPractices?.length) {
|
|
247
254
|
sections.push('## Best Practices\n');
|
|
248
255
|
for (const bp of docs.usage.bestPractices) {
|
|
249
|
-
const badge = bp.guidance ? '**Do:**' :
|
|
256
|
+
const badge = bp.guidance ? '**Do:**' : "**Don't:**";
|
|
250
257
|
sections.push(`- ${badge} ${bp.description}`);
|
|
251
258
|
}
|
|
252
259
|
sections.push('');
|
|
@@ -283,24 +290,30 @@ export function formatFull(docs, options = {}) {
|
|
|
283
290
|
}
|
|
284
291
|
|
|
285
292
|
if (docs.theming) {
|
|
286
|
-
const {
|
|
293
|
+
const {themeData = null} = options;
|
|
287
294
|
sections.push('## Theming\n');
|
|
288
|
-
// Targets table with theme variant merging
|
|
295
|
+
// Targets table with theme variant merging
|
|
289
296
|
if (docs.theming.targets?.length) {
|
|
290
297
|
const targetsTable = formatTargetsTable(docs, themeData);
|
|
291
298
|
sections.push(targetsTable + '\n');
|
|
292
299
|
|
|
293
300
|
// Note about theme variants if any are present
|
|
294
301
|
if (themeData?.variants) {
|
|
295
|
-
const componentKeys = docs.theming.targets.map((/** @type {any} */ t) =>
|
|
296
|
-
|
|
302
|
+
const componentKeys = docs.theming.targets.map((/** @type {any} */ t) =>
|
|
303
|
+
targetKey(t),
|
|
304
|
+
);
|
|
305
|
+
const hasThemeVariants = componentKeys.some(
|
|
306
|
+
(/** @type {any} */ k) => themeData.variants[k]?.length > 0,
|
|
307
|
+
);
|
|
297
308
|
if (hasThemeVariants) {
|
|
298
|
-
sections.push(
|
|
309
|
+
sections.push(
|
|
310
|
+
`_\\* = custom variant from ${themeData.name || 'active'} theme_\n`,
|
|
311
|
+
);
|
|
299
312
|
}
|
|
300
313
|
}
|
|
301
314
|
|
|
302
315
|
// Generate defineTheme example with canonical component selectors only.
|
|
303
|
-
const exampleTargets =
|
|
316
|
+
const exampleTargets = docs.theming.targets;
|
|
304
317
|
if (exampleTargets.length > 0) {
|
|
305
318
|
const exampleLines = ['Override in defineTheme:\n```ts\ncomponents: {'];
|
|
306
319
|
const rootTarget = exampleTargets[0];
|
|
@@ -309,7 +322,9 @@ export function formatFull(docs, options = {}) {
|
|
|
309
322
|
exampleLines.push(` base: { /* CSS properties */ },`);
|
|
310
323
|
if (rootTarget.visualProps?.length) {
|
|
311
324
|
const firstVariant = rootTarget.visualProps[0];
|
|
312
|
-
exampleLines.push(
|
|
325
|
+
exampleLines.push(
|
|
326
|
+
` '${firstVariant}:value': { /* variant-specific */ },`,
|
|
327
|
+
);
|
|
313
328
|
}
|
|
314
329
|
if (rootTarget.states?.length) {
|
|
315
330
|
const firstState = rootTarget.states[0];
|
|
@@ -339,10 +354,14 @@ export function formatFull(docs, options = {}) {
|
|
|
339
354
|
|
|
340
355
|
// Component CSS vars — split into public (directly settable) and private (set via derived)
|
|
341
356
|
if (docs.theming?.vars?.length) {
|
|
342
|
-
const publicVars = docs.theming.vars.filter(
|
|
357
|
+
const publicVars = docs.theming.vars.filter(
|
|
358
|
+
(/** @type {any} */ v) => !v.private && !v.derived,
|
|
359
|
+
);
|
|
343
360
|
|
|
344
361
|
if (publicVars.length > 0) {
|
|
345
|
-
sections.push(
|
|
362
|
+
sections.push(
|
|
363
|
+
'**Themeable CSS variables** - additional properties that can be overridden in `defineTheme` component overrides.\n',
|
|
364
|
+
);
|
|
346
365
|
const varLines = [];
|
|
347
366
|
varLines.push('| CSS Variable | Default | Description |');
|
|
348
367
|
varLines.push('|-------------|---------|-------------|');
|
|
@@ -356,25 +375,37 @@ export function formatFull(docs, options = {}) {
|
|
|
356
375
|
|
|
357
376
|
// Show derived property examples — the recommended way to theme
|
|
358
377
|
if (docs.theming?.derived?.length) {
|
|
359
|
-
const canonical =
|
|
360
|
-
const varsKey = canonical.length
|
|
378
|
+
const canonical = docs.theming.targets || [];
|
|
379
|
+
const varsKey = canonical.length
|
|
380
|
+
? targetKey(canonical[0])
|
|
381
|
+
: docs.theming.componentKey || '';
|
|
361
382
|
const derivedExamples = docs.theming.derived
|
|
362
383
|
.filter((/** @type {any} */ d) => d.vars?.length)
|
|
363
384
|
.map((/** @type {any} */ d) => ` ${d.property}: '...',`)
|
|
364
385
|
.join('\n');
|
|
365
386
|
const expandExamples = docs.theming.derived
|
|
366
387
|
.filter((/** @type {any} */ d) => d.expand === 'container')
|
|
367
|
-
.map(
|
|
388
|
+
.map(
|
|
389
|
+
(/** @type {any} */ d) =>
|
|
390
|
+
` ${d.property}: '...', // expands to container layout tokens`,
|
|
391
|
+
)
|
|
392
|
+
.join('\n');
|
|
393
|
+
const allExamples = [derivedExamples, expandExamples]
|
|
394
|
+
.filter(Boolean)
|
|
368
395
|
.join('\n');
|
|
369
|
-
const allExamples = [derivedExamples, expandExamples].filter(Boolean).join('\n');
|
|
370
396
|
if (allExamples) {
|
|
371
|
-
sections.push(
|
|
397
|
+
sections.push(
|
|
398
|
+
'Some properties are set via standard CSS in component overrides:\n```ts\ncomponents: {\n ' +
|
|
399
|
+
varsKey +
|
|
400
|
+
': {\n base: {\n' +
|
|
401
|
+
allExamples +
|
|
402
|
+
'\n },\n },\n}\n```\n',
|
|
403
|
+
);
|
|
372
404
|
}
|
|
373
405
|
}
|
|
374
406
|
}
|
|
375
407
|
}
|
|
376
408
|
|
|
377
|
-
|
|
378
409
|
return sections.join('\n');
|
|
379
410
|
}
|
|
380
411
|
|
|
@@ -401,21 +432,29 @@ export function formatCompact(docs, componentName, importHint) {
|
|
|
401
432
|
sections.push(desc + '\n');
|
|
402
433
|
|
|
403
434
|
if (docs.usage?.anatomy?.length) {
|
|
404
|
-
sections.push(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
435
|
+
sections.push(
|
|
436
|
+
'Anatomy: ' +
|
|
437
|
+
docs.usage.anatomy
|
|
438
|
+
.map((/** @type {any} */ el) => {
|
|
439
|
+
const req = el.required ? '' : ' (optional)';
|
|
440
|
+
return `${el.name}${req}`;
|
|
441
|
+
})
|
|
442
|
+
.join(', ') +
|
|
443
|
+
'\n',
|
|
444
|
+
);
|
|
408
445
|
}
|
|
409
446
|
|
|
410
447
|
if (importHint) {
|
|
411
448
|
sections.push('## Import\n');
|
|
412
|
-
sections.push(
|
|
449
|
+
sections.push(
|
|
450
|
+
`\`\`\`tsx\nimport { ${displayName} } from '${importHint}';\n\`\`\`\n`,
|
|
451
|
+
);
|
|
413
452
|
}
|
|
414
453
|
|
|
415
454
|
if (docs.usage?.bestPractices?.length) {
|
|
416
455
|
sections.push('## Best Practices\n');
|
|
417
456
|
for (const bp of docs.usage.bestPractices) {
|
|
418
|
-
const badge = bp.guidance ? '**Do:**' :
|
|
457
|
+
const badge = bp.guidance ? '**Do:**' : "**Don't:**";
|
|
419
458
|
sections.push(`- ${badge} ${bp.description}`);
|
|
420
459
|
}
|
|
421
460
|
sections.push('');
|
|
@@ -453,7 +492,12 @@ export function formatCompact(docs, componentName, importHint) {
|
|
|
453
492
|
propLines.push('| CSS Property | Sets |');
|
|
454
493
|
propLines.push('|-------------|------|');
|
|
455
494
|
for (const d of docs.theming.derived) {
|
|
456
|
-
const target =
|
|
495
|
+
const target =
|
|
496
|
+
d.expand === 'container'
|
|
497
|
+
? 'container layout tokens'
|
|
498
|
+
: (d.vars || [])
|
|
499
|
+
.map((/** @type {any} */ v) => `\`${mdCell(v)}\``)
|
|
500
|
+
.join(', ');
|
|
457
501
|
propLines.push(`| \`${mdCell(d.property)}\` | ${target} |`);
|
|
458
502
|
}
|
|
459
503
|
sections.push(propLines.join('\n') + '\n');
|
|
@@ -504,7 +548,9 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
|
|
|
504
548
|
if ('props' in docs) {
|
|
505
549
|
props = docs.props;
|
|
506
550
|
} else if ('components' in docs) {
|
|
507
|
-
const entry = docs.components.find(
|
|
551
|
+
const entry = docs.components.find(
|
|
552
|
+
(/** @type {any} */ c) => c.name === displayName,
|
|
553
|
+
);
|
|
508
554
|
if (entry) {
|
|
509
555
|
props = entry.props;
|
|
510
556
|
description = entry.description;
|
|
@@ -549,9 +595,7 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
|
|
|
549
595
|
// Description (shortened)
|
|
550
596
|
if (description) {
|
|
551
597
|
const shortDesc =
|
|
552
|
-
description.length > 80
|
|
553
|
-
? description.slice(0, 77) + '...'
|
|
554
|
-
: description;
|
|
598
|
+
description.length > 80 ? description.slice(0, 77) + '...' : description;
|
|
555
599
|
output.push(` ${shortDesc}`);
|
|
556
600
|
}
|
|
557
601
|
|
|
@@ -569,25 +613,33 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
|
|
|
569
613
|
// Derived properties (if any)
|
|
570
614
|
if (docs.theming?.derived?.length) {
|
|
571
615
|
const derivedNames = docs.theming.derived
|
|
572
|
-
.map((/** @type {any} */ d) =>
|
|
616
|
+
.map((/** @type {any} */ d) =>
|
|
617
|
+
d.expand === 'container'
|
|
618
|
+
? `${d.property} -> container tokens`
|
|
619
|
+
: `${d.property} -> ${(d.vars || []).join(', ')}`,
|
|
620
|
+
)
|
|
573
621
|
.join('; ');
|
|
574
622
|
output.push(` Derived: ${derivedNames}`);
|
|
575
623
|
}
|
|
576
624
|
|
|
577
|
-
// Theme targets (component class, preferred data attrs, props, states) with theme variant merging
|
|
625
|
+
// Theme targets (component class, preferred data attrs, props, states) with theme variant merging
|
|
578
626
|
if (docs.theming?.targets?.length) {
|
|
579
|
-
const {
|
|
627
|
+
const {themeData = null} = options;
|
|
580
628
|
const targetParts = docs.theming.targets.map((/** @type {any} */ t) => {
|
|
581
629
|
const parts = [t.className];
|
|
582
|
-
if (t.deprecatedFor) parts.push(`deprecated->${t.deprecatedFor}`);
|
|
583
630
|
const dataAttrs = getTargetDataAttributes(t);
|
|
584
|
-
if (dataAttrs.length)
|
|
585
|
-
|
|
631
|
+
if (dataAttrs.length)
|
|
632
|
+
parts.push(`preferred attrs: ${dataAttrs.join(', ')}`);
|
|
633
|
+
if (t.visualProps?.length)
|
|
634
|
+
parts.push(`variants: ${t.visualProps.join(', ')}`);
|
|
586
635
|
if (t.states?.length) parts.push(`states: ${t.states.join(', ')}`);
|
|
587
636
|
// Merge theme variants
|
|
588
637
|
const componentKey = targetKey(t);
|
|
589
638
|
const themeVars = themeData?.variants?.[componentKey];
|
|
590
|
-
if (themeVars?.length)
|
|
639
|
+
if (themeVars?.length)
|
|
640
|
+
parts.push(
|
|
641
|
+
`theme: ${themeVars.map((/** @type {any} */ v) => v + '*').join(', ')}`,
|
|
642
|
+
);
|
|
591
643
|
return parts.join(' ');
|
|
592
644
|
});
|
|
593
645
|
output.push(` Targets: ${targetParts.join(' | ')}`);
|
|
@@ -602,7 +654,9 @@ export function formatBrief(docs, componentName, importHint, options = {}) {
|
|
|
602
654
|
if (examples.length > 0) {
|
|
603
655
|
const code = examples[0].code;
|
|
604
656
|
const codeLine =
|
|
605
|
-
code
|
|
657
|
+
code
|
|
658
|
+
.split('\n')
|
|
659
|
+
.find((/** @type {string} */ l) => l.trim().startsWith('<XDS')) ||
|
|
606
660
|
code.split('\n')[0];
|
|
607
661
|
output.push(` ${codeLine.trim()}`);
|
|
608
662
|
}
|
|
@@ -682,7 +736,7 @@ export async function formatBriefAll(
|
|
|
682
736
|
if (readmePath && readmePath.endsWith('.doc.mjs')) {
|
|
683
737
|
const docs = await loadDocs(readmePath, {zh, lang});
|
|
684
738
|
const importPath = resolveImportPath(coreDir, comp);
|
|
685
|
-
output.push(formatBrief(docs, comp, importPath, {
|
|
739
|
+
output.push(formatBrief(docs, comp, importPath, {themeData}));
|
|
686
740
|
} else {
|
|
687
741
|
output.push(`${comp}\n (no docs)\n`);
|
|
688
742
|
}
|
|
@@ -9,7 +9,10 @@ describe('component accessibility guidance', () => {
|
|
|
9
9
|
description: 'An action.',
|
|
10
10
|
usage: {
|
|
11
11
|
accessibility: [
|
|
12
|
-
{
|
|
12
|
+
{
|
|
13
|
+
name: 'Loading',
|
|
14
|
+
description: 'Expose aria-busy and block duplicate activation.',
|
|
15
|
+
},
|
|
13
16
|
],
|
|
14
17
|
},
|
|
15
18
|
props: [],
|
|
@@ -18,7 +21,9 @@ describe('component accessibility guidance', () => {
|
|
|
18
21
|
it('renders a dedicated section in full output', () => {
|
|
19
22
|
const out = formatFull(docs);
|
|
20
23
|
expect(out).toContain('## Accessibility');
|
|
21
|
-
expect(out).toContain(
|
|
24
|
+
expect(out).toContain(
|
|
25
|
+
'- **Loading:** Expose aria-busy and block duplicate activation.',
|
|
26
|
+
);
|
|
22
27
|
});
|
|
23
28
|
|
|
24
29
|
it('keeps accessibility guidance in compact agent output', () => {
|
|
@@ -32,11 +37,16 @@ describe('component accessibility guidance', () => {
|
|
|
32
37
|
});
|
|
33
38
|
|
|
34
39
|
it('ignores legacy non-array accessibility content', () => {
|
|
35
|
-
const legacyDocs = {
|
|
40
|
+
const legacyDocs = {
|
|
41
|
+
...docs,
|
|
42
|
+
usage: {accessibility: 'Follow WCAG guidance.'},
|
|
43
|
+
};
|
|
36
44
|
|
|
37
45
|
expect(() => formatFull(legacyDocs)).not.toThrow();
|
|
38
46
|
expect(formatFull(legacyDocs)).not.toContain('## Accessibility');
|
|
39
|
-
expect(formatCompact(legacyDocs, 'Button')).not.toContain(
|
|
47
|
+
expect(formatCompact(legacyDocs, 'Button')).not.toContain(
|
|
48
|
+
'## Accessibility',
|
|
49
|
+
);
|
|
40
50
|
});
|
|
41
51
|
});
|
|
42
52
|
|
|
@@ -56,7 +66,9 @@ describe('formatFull sub-component rendering', () => {
|
|
|
56
66
|
expect(out).toContain('### XDSRadioListItem');
|
|
57
67
|
expect(out).not.toContain('undefined');
|
|
58
68
|
// Points the reader at the sub-component's own docs instead of a blank.
|
|
59
|
-
expect(out).toMatch(
|
|
69
|
+
expect(out).toMatch(
|
|
70
|
+
/(?:astryx|@astryxdesign\/cli) component XDSRadioListItem/,
|
|
71
|
+
);
|
|
60
72
|
});
|
|
61
73
|
|
|
62
74
|
it('renders a full props table for a sub-component that has inline props', () => {
|
|
@@ -100,7 +112,9 @@ describe('formatFull theming override keys', () => {
|
|
|
100
112
|
const docs = {
|
|
101
113
|
name: 'Button',
|
|
102
114
|
description: 'A button.',
|
|
103
|
-
theming: {
|
|
115
|
+
theming: {
|
|
116
|
+
targets: [{className: 'astryx-button', visualProps: ['variant']}],
|
|
117
|
+
},
|
|
104
118
|
};
|
|
105
119
|
const out = formatFull(docs);
|
|
106
120
|
|
|
@@ -131,37 +145,6 @@ describe('formatFull theming override keys', () => {
|
|
|
131
145
|
});
|
|
132
146
|
});
|
|
133
147
|
|
|
134
|
-
describe('deprecated theming target guidance', () => {
|
|
135
|
-
const docs = {
|
|
136
|
-
name: 'Example',
|
|
137
|
-
description: 'An example.',
|
|
138
|
-
theming: {
|
|
139
|
-
targets: [
|
|
140
|
-
{className: 'astryx-old-target', deprecatedFor: 'new-target'},
|
|
141
|
-
{className: 'astryx-new-target'},
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
it('names the canonical replacement in full component docs', () => {
|
|
147
|
-
expect(formatFull(docs)).toContain(
|
|
148
|
-
'`astryx-old-target` _(deprecated; use `new-target`)_',
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('excludes deprecated targets from copyable defineTheme examples', () => {
|
|
153
|
-
const out = formatFull(docs);
|
|
154
|
-
expect(out).not.toContain("'old-target': {");
|
|
155
|
-
expect(out).toContain("'new-target': {");
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('keeps the replacement in brief agent guidance', () => {
|
|
159
|
-
expect(formatBrief(docs, 'Example')).toContain(
|
|
160
|
-
'astryx-old-target deprecated->new-target',
|
|
161
|
-
);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
148
|
/** Pipes that actually separate cells — a `\|` is content, not a separator. */
|
|
166
149
|
function cellPipes(row) {
|
|
167
150
|
return (row.match(/(?<!\\)\|/g) || []).length;
|
|
@@ -236,7 +219,11 @@ describe('formatBrief signature stays terse', () => {
|
|
|
236
219
|
type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10',
|
|
237
220
|
description: 'Gap.',
|
|
238
221
|
},
|
|
239
|
-
{
|
|
222
|
+
{
|
|
223
|
+
name: 'wrap',
|
|
224
|
+
type: "'nowrap' | 'wrap' | 'wrap-reverse'",
|
|
225
|
+
description: 'Wrap.',
|
|
226
|
+
},
|
|
240
227
|
{
|
|
241
228
|
name: 'hAlign',
|
|
242
229
|
type: "'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'",
|
|
@@ -248,7 +235,9 @@ describe('formatBrief signature stays terse', () => {
|
|
|
248
235
|
|
|
249
236
|
// Short enums still earn their place in the signature.
|
|
250
237
|
expect(signature).toContain('wrap: nowrap|wrap|wrap-reverse');
|
|
251
|
-
expect(signature).toContain(
|
|
238
|
+
expect(signature).toContain(
|
|
239
|
+
'hAlign: start|center|end|between|around|evenly',
|
|
240
|
+
);
|
|
252
241
|
// The long scale does not.
|
|
253
242
|
expect(signature).not.toContain('0|0.5|1|1.5|2|3|4|5|6|8|10');
|
|
254
243
|
// But the prop is still named, so it is not lost.
|
|
@@ -42,7 +42,7 @@ const componentDoc = {
|
|
|
42
42
|
{property: 'radius', vars: ['--widget-radius']},
|
|
43
43
|
],
|
|
44
44
|
targets: [
|
|
45
|
-
{className: 'astryx-widget'
|
|
45
|
+
{className: 'astryx-widget'},
|
|
46
46
|
{className: 'astryx-widget-v2', visualProps: ['variant']},
|
|
47
47
|
],
|
|
48
48
|
},
|
|
@@ -63,7 +63,10 @@ describe('component text output is ASCII', () => {
|
|
|
63
63
|
it.each([
|
|
64
64
|
['formatFull', () => formatFull(componentDoc)],
|
|
65
65
|
['formatCompact', () => formatCompact(componentDoc, 'Widget')],
|
|
66
|
-
[
|
|
66
|
+
[
|
|
67
|
+
'formatBrief',
|
|
68
|
+
() => formatBrief(componentDoc, 'Widget', '@astryxdesign/core/Widget'),
|
|
69
|
+
],
|
|
67
70
|
['formatProps', () => formatProps(componentDoc, 'Widget')],
|
|
68
71
|
])('%s', (_name, render) => {
|
|
69
72
|
expect(nonAscii(render())).toEqual([]);
|
|
@@ -70,13 +70,6 @@ describe('command exit codes', () => {
|
|
|
70
70
|
},
|
|
71
71
|
);
|
|
72
72
|
|
|
73
|
-
it('bare `astryx layout` exits 1 in both modes, as documented', async () => {
|
|
74
|
-
const doc = commandDocs.find((d) => d.name === 'layout');
|
|
75
|
-
expect(doc.exitCodes.find((e) => e.code === 1)?.when).toMatch(/^no subcommand/);
|
|
76
|
-
expect((await runCli(['layout'])).status).toBe(1);
|
|
77
|
-
expect((await runCli(['layout', '--json'])).status).toBe(1);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
73
|
it('`astryx discover` with a blank query exits 1 only when packages are discovered', async () => {
|
|
81
74
|
const doc = commandDocs.find((d) => d.name === 'discover');
|
|
82
75
|
expect(doc.exitCodes.find((e) => e.code === 1)?.when).toMatch(/blank query when packages are discovered/);
|
|
@@ -225,23 +225,6 @@ describe('--json shim: help shown for a failed invocation is an error envelope',
|
|
|
225
225
|
expect(parsed.error).toMatch(/bogus/);
|
|
226
226
|
});
|
|
227
227
|
|
|
228
|
-
it('astryx layout --json (group, no subcommand) emits ERR_MISSING_ARGUMENT, exit 1', async () => {
|
|
229
|
-
const {status, stdout, stderr} = await runCli(['layout', '--json']);
|
|
230
|
-
expect(status).toBe(1);
|
|
231
|
-
expect(stderr).toBe('');
|
|
232
|
-
const parsed = parseJson(stdout);
|
|
233
|
-
expect(parsed).not.toHaveProperty('type');
|
|
234
|
-
expect(parsed.code).toBe('ERR_MISSING_ARGUMENT');
|
|
235
|
-
expect(parsed.suggestions.map((s) => s.name)).toContain('layout expand');
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('astryx layout (no --json) still prints help to stderr, exit 1', async () => {
|
|
239
|
-
const {status, stdout, stderr} = await runCli(['layout']);
|
|
240
|
-
expect(status).toBe(1);
|
|
241
|
-
expect(stdout).toBe('');
|
|
242
|
-
expect(stderr).toMatch(/Usage: astryx layout/);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
228
|
it('the real binary emits the same envelope for help bogus --json', () => {
|
|
246
229
|
// One program per process, so the root's own outputHelp patch is used here.
|
|
247
230
|
const bin = fileURLToPath(new URL('../bin/astryx.mjs', import.meta.url));
|
|
@@ -282,11 +265,4 @@ describe('--json shim: help shown for a failed invocation is an error envelope',
|
|
|
282
265
|
expect(parsed.suggestions).toEqual([{name: 'late child', reason: 'available subcommand'}]);
|
|
283
266
|
});
|
|
284
267
|
|
|
285
|
-
it('astryx help layout --json still emits the help envelope, exit 0', async () => {
|
|
286
|
-
const {status, stdout} = await runCli(['help', 'layout', '--json']);
|
|
287
|
-
expect(status).toBe(0);
|
|
288
|
-
const parsed = parseJson(stdout);
|
|
289
|
-
expect(parsed.type).toBe('help');
|
|
290
|
-
expect(parsed.data.command).toBe('astryx layout');
|
|
291
|
-
});
|
|
292
268
|
});
|
|
@@ -183,10 +183,11 @@ export function removeXdsBlock(filePath: string, { deleteIfEmpty }?: {
|
|
|
183
183
|
/**
|
|
184
184
|
* Remove Astryx section from all known agent doc files.
|
|
185
185
|
* @param {string} targetDir
|
|
186
|
+
* @returns {string[]} the project-relative files a block was removed from.
|
|
186
187
|
* @throws {PathSafetyError} `ERR_PATH_TRAVERSAL` when a file it would change
|
|
187
188
|
* resolves outside `targetDir`; nothing is changed.
|
|
188
189
|
*/
|
|
189
|
-
export function removeAgentDocs(targetDir: string):
|
|
190
|
+
export function removeAgentDocs(targetDir: string): string[];
|
|
190
191
|
/**
|
|
191
192
|
* Programmatic entry point for installing agent docs.
|
|
192
193
|
* Used by the init command, upgrade command, and agent-docs command.
|
|
@@ -458,7 +458,7 @@ export function generateCompressedIndex(
|
|
|
458
458
|
} else {
|
|
459
459
|
lines.push("- Style with component props first, then tokens (var(--color-*|--spacing-*|--radius-*)). No raw hex/px. No StyleX/Tailwind compiler here — don't use xstyle/utility classes directly. Some templates use StyleX and need a compiler plugin; see `astryx docs styling-overview`.");
|
|
460
460
|
}
|
|
461
|
-
lines.push('- Palettes and custom colors go through the theme, never :root overrides. See `astryx docs theme`.');
|
|
461
|
+
lines.push('- Palettes and custom colors go through the theme, never :root overrides. Run `astryx theme add <slug>` to import; `theme eject <slug>` only forks source. See `astryx docs theme`.');
|
|
462
462
|
// Self-check — post-generation pass. Validated via vibe tests (internal/vibe-tests/
|
|
463
463
|
// prompt-purity-test): on complex multi-step UIs the rules above alone still leave raw
|
|
464
464
|
// CSS in ~11-13% of runs; a re-read-and-fix pass cuts that ~4x at negligible token cost.
|
|
@@ -773,6 +773,7 @@ function assertTargetsWithin(targetDir, relPaths) {
|
|
|
773
773
|
/**
|
|
774
774
|
* Remove Astryx section from all known agent doc files.
|
|
775
775
|
* @param {string} targetDir
|
|
776
|
+
* @returns {string[]} the project-relative files a block was removed from.
|
|
776
777
|
* @throws {PathSafetyError} `ERR_PATH_TRAVERSAL` when a file it would change
|
|
777
778
|
* resolves outside `targetDir`; nothing is changed.
|
|
778
779
|
*/
|
|
@@ -789,11 +790,14 @@ export function removeAgentDocs(targetDir) {
|
|
|
789
790
|
throw new PathSafetyError(err.message, ERROR_CODES.ERR_PATH_TRAVERSAL);
|
|
790
791
|
}
|
|
791
792
|
|
|
793
|
+
/** @type {string[]} */
|
|
794
|
+
const removedFrom = [];
|
|
792
795
|
for (const p of allPaths) {
|
|
793
796
|
const filePath = path.join(targetDir, p);
|
|
794
797
|
// Delete if empty for files we created (AGENTS.md, .claude/CLAUDE.md)
|
|
795
798
|
const deleteIfEmpty = p === AGENTS_MD || p === CLAUDE_DIR_MD;
|
|
796
799
|
if (removeXdsBlock(filePath, {deleteIfEmpty})) {
|
|
800
|
+
removedFrom.push(p);
|
|
797
801
|
if (!fs.existsSync(filePath)) {
|
|
798
802
|
humanLog(`[ok] Removed empty ${p}`);
|
|
799
803
|
} else {
|
|
@@ -801,6 +805,7 @@ export function removeAgentDocs(targetDir) {
|
|
|
801
805
|
}
|
|
802
806
|
}
|
|
803
807
|
}
|
|
808
|
+
return removedFrom;
|
|
804
809
|
}
|
|
805
810
|
|
|
806
811
|
/**
|
|
@@ -9,5 +9,8 @@ describe('generated agent docs app-theme workflow', () => {
|
|
|
9
9
|
|
|
10
10
|
expect(result).toContain('astryx docs theme');
|
|
11
11
|
expect(result).toContain('never :root overrides');
|
|
12
|
+
expect(result).toContain('theme add <slug>');
|
|
13
|
+
expect(result).toContain('theme eject <slug>');
|
|
14
|
+
expect(result).not.toContain('theme add <slug> --import');
|
|
12
15
|
});
|
|
13
16
|
});
|
|
@@ -106,7 +106,7 @@ export function themeModuleCandidates(projectDir) {
|
|
|
106
106
|
function validThemeRecord(value, label) {
|
|
107
107
|
if (!isRecord(value) || !isRecord(value.themes)) {
|
|
108
108
|
throw new ThemeStateError(
|
|
109
|
-
`${label} must carry a static ${THEME_RECORD_MARKER} header. Regenerate it with \`astryx theme add <slug
|
|
109
|
+
`${label} must carry a static ${THEME_RECORD_MARKER} header. Regenerate it with \`astryx theme add <slug>\`.`,
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
const keys = Object.keys(value);
|
|
@@ -159,7 +159,7 @@ export function parseThemeModuleRecord(source, label = 'theme module') {
|
|
|
159
159
|
.filter(line => /^\s*\*\s*@astryx-theme-record\s+/u.test(line));
|
|
160
160
|
if (recordLines.length !== 1) {
|
|
161
161
|
throw new ThemeStateError(
|
|
162
|
-
`${label} must carry exactly one static ${THEME_RECORD_MARKER} header. Regenerate it with \`astryx theme add <slug
|
|
162
|
+
`${label} must carry exactly one static ${THEME_RECORD_MARKER} header. Regenerate it with \`astryx theme add <slug>\`.`,
|
|
163
163
|
);
|
|
164
164
|
}
|
|
165
165
|
const payload = recordLines[0].replace(
|
|
@@ -318,7 +318,7 @@ export function readThemeState(cwd = process.cwd()) {
|
|
|
318
318
|
export function renderThemeModule(themes, defaultSlug, typescript) {
|
|
319
319
|
if (!themes.some(theme => theme.slug === defaultSlug)) {
|
|
320
320
|
throw new ThemeStateError(
|
|
321
|
-
`Default theme "${defaultSlug}" is not added. Run \`astryx theme add ${defaultSlug}
|
|
321
|
+
`Default theme "${defaultSlug}" is not added. Run \`astryx theme add ${defaultSlug}\` first.`,
|
|
322
322
|
);
|
|
323
323
|
}
|
|
324
324
|
/** @type {string[]} */
|