@astryxdesign/cli 0.1.6 → 0.1.7-canary.04cd8f7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +115 -19
- package/docs/cli-integrations.doc.mjs +150 -0
- package/docs/getting-started.doc.mjs +9 -9
- package/docs/internationalization.doc.mjs +243 -0
- package/docs/layout.doc.dense.mjs +5 -0
- package/docs/migration.doc.mjs +18 -18
- package/docs/principles.doc.dense.mjs +5 -5
- package/docs/principles.doc.mjs +6 -6
- package/docs/principles.doc.zh.mjs +5 -5
- package/docs/styling-libraries.doc.mjs +3 -3
- package/docs/styling.doc.mjs +4 -4
- package/docs/theme.doc.dense.mjs +12 -12
- package/docs/theme.doc.mjs +7 -7
- package/docs/theme.doc.zh.mjs +10 -10
- package/docs/tokens.doc.dense.mjs +6 -7
- package/docs/tokens.doc.mjs +1 -1
- package/docs/tokens.doc.zh.mjs +6 -7
- package/docs/working-with-ai.doc.mjs +18 -18
- package/package.json +13 -10
- package/src/api/docOverlays.test.mjs +133 -0
- package/src/api/docs.mjs +14 -2
- package/src/api/doctor.mjs +3 -3
- package/src/api/integration-block-exports.test.mjs +240 -0
- package/src/api/template-suffix.test.mjs +246 -0
- package/src/api/template.mjs +104 -28
- package/src/api/validate-integration.mjs +0 -8
- package/src/codemods/__tests__/registry.test.mjs +1 -0
- package/src/codemods/ensure-jscodeshift.mjs +11 -27
- package/src/codemods/registry.mjs +1 -0
- package/src/codemods/run-codemod.mjs +1 -1
- package/src/codemods/runner.mjs +2 -2
- package/src/codemods/transforms/v0.1.7/__tests__/migrate-table-tableprops-to-direct-props.test.mjs +120 -0
- package/src/codemods/transforms/v0.1.7/__tests__/rename-table-renderprops-styles-to-xstyle.test.mjs +112 -0
- package/src/codemods/transforms/v0.1.7/index.mjs +27 -0
- package/src/codemods/transforms/v0.1.7/migrate-table-tableprops-to-direct-props.mjs +188 -0
- package/src/codemods/transforms/v0.1.7/rename-table-renderprops-styles-to-xstyle.mjs +197 -0
- package/src/commands/agent-docs.mjs +21 -8
- package/src/commands/agent-docs.test.mjs +31 -4
- package/src/commands/build-theme.mjs +10 -71
- package/src/commands/build.mjs +15 -15
- package/src/commands/component/index.mjs +4 -4
- package/src/commands/discover.mjs +7 -5
- package/src/commands/docs.mjs +4 -4
- package/src/commands/hook/index.mjs +4 -4
- package/src/commands/init.mjs +48 -152
- package/src/commands/init.next-steps.test.mjs +1 -1
- package/src/commands/interactive-guard.test.mjs +19 -22
- package/src/commands/json-contract.test.mjs +1 -1
- package/src/commands/layout.mjs +1 -1
- package/src/commands/search.mjs +4 -4
- package/src/commands/swizzle.mjs +11 -34
- package/src/commands/template.mjs +11 -31
- package/src/commands/upgrade.mjs +9 -6
- package/src/commands/upgrade.test.mjs +1 -1
- package/src/config.mjs +5 -14
- package/src/doc.mjs +27 -0
- package/src/doc.test.mjs +383 -0
- package/src/index.mjs +5 -6
- package/src/integration.mjs +4 -15
- package/src/lib/component-discovery.importpath.test.mjs +59 -0
- package/src/lib/component-discovery.mjs +15 -5
- package/src/lib/component-format.mjs +47 -14
- package/src/lib/component-format.test.mjs +95 -1
- package/src/lib/component-loader.mjs +104 -2
- package/src/lib/componentDocOverlay.test.mjs +111 -0
- package/src/lib/config-schema.mjs +0 -30
- package/src/lib/hook-format.mjs +8 -3
- package/src/lib/term-log.mjs +48 -0
- package/src/lib/xle/registry.mjs +0 -5
- package/src/schemas/doc-schema.mjs +226 -0
- package/src/schemas/template-schema.mjs +47 -0
- package/src/template.mjs +9 -67
- package/src/types/config.d.ts +11 -66
- package/src/types/doc.d.ts +23 -0
- package/src/types/integration.d.ts +7 -18
- package/src/types/template-api.d.ts +14 -50
- package/src/utils/package-manager.mjs +78 -0
- package/src/utils/package-manager.test.mjs +108 -1
- package/src/utils/path-safety.mjs +0 -18
- package/src/utils/update-check.mjs +2 -1
- package/templates/blocks/components/Avatar/AvatarGroup.tsx +5 -7
- package/templates/blocks/components/Avatar/AvatarShowcase.tsx +4 -6
- package/templates/blocks/components/Avatar/AvatarUserCard.tsx +3 -5
- package/templates/blocks/components/Avatar/AvatarWithImage.tsx +8 -6
- package/templates/blocks/components/Avatar/AvatarWithStatus.tsx +3 -5
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputControlledInput.tsx +1 -1
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputDisabled.tsx +1 -1
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +1 -1
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +1 -1
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputShowcase.tsx +1 -1
- package/templates/blocks/components/ChatComposerInput/ChatComposerInputSlashCommands.tsx +1 -1
- package/templates/blocks/components/TabList/TabListTabsWithActions.doc.mjs +1 -1
- package/templates/blocks/components/TabList/TabListTabsWithActions.tsx +2 -7
- package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.doc.mjs +14 -0
- package/templates/blocks/components/VisuallyHidden/VisuallyHiddenLiveRegion.tsx +41 -0
- package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.doc.mjs +13 -0
- package/templates/blocks/components/VisuallyHidden/VisuallyHiddenShowcase.tsx +78 -0
- package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.doc.mjs +14 -0
- package/templates/blocks/components/VisuallyHidden/VisuallyHiddenStructuralHeading.tsx +38 -0
- package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.doc.mjs +14 -0
- package/templates/blocks/components/VisuallyHidden/VisuallyHiddenSupplementaryContext.tsx +47 -0
- package/templates/pages/ide/page.tsx +35 -41
- package/templates/pages/theme-showcase/page.tsx +7 -7
- package/templates/themes/neutral/neutralTheme.ts +63 -32
- package/src/utils/interactive.mjs +0 -76
- package/src/utils/interactive.test.mjs +0 -70
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
import {describe, it, expect} from 'vitest';
|
|
4
|
-
import {formatFull} from './component-format.mjs';
|
|
4
|
+
import {formatBrief, formatFull} from './component-format.mjs';
|
|
5
5
|
|
|
6
6
|
describe('formatFull sub-component rendering', () => {
|
|
7
7
|
// Regression guard: sub-components are sometimes declared as a bare
|
|
@@ -93,3 +93,97 @@ describe('formatFull theming override keys', () => {
|
|
|
93
93
|
expect(out).not.toContain("'astryx-table-cell': {");
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
|
+
|
|
97
|
+
/** Pipes that actually separate cells — a `\|` is content, not a separator. */
|
|
98
|
+
function cellPipes(row) {
|
|
99
|
+
return (row.match(/(?<!\\)\|/g) || []).length;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
describe('markdown table cells escape their pipes', () => {
|
|
103
|
+
// A prop type is a union, and a union is spelled with `|` — the very
|
|
104
|
+
// character GFM uses to separate cells. Backticks do not protect it: a row
|
|
105
|
+
// with more cells than the header has columns gets its excess *discarded*,
|
|
106
|
+
// so an unescaped `gap: 0 | 0.5 | ...` silently eats its own Default and
|
|
107
|
+
// Description columns. See packages/core/src/Markdown/parser.ts, which
|
|
108
|
+
// splits on unescaped pipes and preserves `\|` as literal.
|
|
109
|
+
it('keeps a union-typed prop row at four cells', () => {
|
|
110
|
+
const docs = {
|
|
111
|
+
name: 'Grid',
|
|
112
|
+
description: 'A grid.',
|
|
113
|
+
props: [
|
|
114
|
+
{
|
|
115
|
+
name: 'gap',
|
|
116
|
+
type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10',
|
|
117
|
+
default: '2',
|
|
118
|
+
description: 'Spacing between all items.',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
const row = formatFull(docs)
|
|
123
|
+
.split('\n')
|
|
124
|
+
.find(l => l.startsWith('| `gap`'));
|
|
125
|
+
|
|
126
|
+
// A 4-column row has exactly 5 separators. Unescaped, this row had 15.
|
|
127
|
+
expect(cellPipes(row)).toBe(5);
|
|
128
|
+
expect(row).toContain('\\|');
|
|
129
|
+
// The columns the unescaped pipes were swallowing.
|
|
130
|
+
expect(row).toContain('`2`');
|
|
131
|
+
expect(row).toContain('Spacing between all items.');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('escapes pipes in a description too', () => {
|
|
135
|
+
const docs = {
|
|
136
|
+
name: 'AppShell',
|
|
137
|
+
description: 'A shell.',
|
|
138
|
+
props: [
|
|
139
|
+
{
|
|
140
|
+
name: 'mobileNav',
|
|
141
|
+
type: 'ReactNode',
|
|
142
|
+
description: "Config. breakpoint is 'sm' | 'md' | 'lg' | 'none'.",
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
};
|
|
146
|
+
const row = formatFull(docs)
|
|
147
|
+
.split('\n')
|
|
148
|
+
.find(l => l.startsWith('| `mobileNav`'));
|
|
149
|
+
|
|
150
|
+
expect(cellPipes(row)).toBe(5);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('formatBrief signature stays terse', () => {
|
|
155
|
+
// `--detail brief` exists to be token-cheap. It hoists union-typed props into
|
|
156
|
+
// the signature because a short enum reads at a glance — but an 11-member
|
|
157
|
+
// spacing scale does not, and Stack carries four of them (gap, padding,
|
|
158
|
+
// paddingInline, paddingBlock), so the same scale got printed four times.
|
|
159
|
+
// Long unions stay in the terse prop list, exactly as they did when the type
|
|
160
|
+
// was still the bare name `SpacingStep`.
|
|
161
|
+
it('hoists a short enum but not a long scale', () => {
|
|
162
|
+
const docs = {
|
|
163
|
+
name: 'HStack',
|
|
164
|
+
description: 'A stack.',
|
|
165
|
+
props: [
|
|
166
|
+
{
|
|
167
|
+
name: 'gap',
|
|
168
|
+
type: '0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10',
|
|
169
|
+
description: 'Gap.',
|
|
170
|
+
},
|
|
171
|
+
{name: 'wrap', type: "'nowrap' | 'wrap' | 'wrap-reverse'", description: 'Wrap.'},
|
|
172
|
+
{
|
|
173
|
+
name: 'hAlign',
|
|
174
|
+
type: "'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'",
|
|
175
|
+
description: 'Align.',
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
const signature = formatBrief(docs, 'HStack', '').split('\n')[0];
|
|
180
|
+
|
|
181
|
+
// Short enums still earn their place in the signature.
|
|
182
|
+
expect(signature).toContain('wrap: nowrap|wrap|wrap-reverse');
|
|
183
|
+
expect(signature).toContain('hAlign: start|center|end|between|around|evenly');
|
|
184
|
+
// The long scale does not.
|
|
185
|
+
expect(signature).not.toContain('0|0.5|1|1.5|2|3|4|5|6|8|10');
|
|
186
|
+
// But the prop is still named, so it is not lost.
|
|
187
|
+
expect(formatBrief(docs, 'HStack', '')).toContain('gap');
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -5,6 +5,59 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {pathToFileURL} from 'node:url';
|
|
8
|
+
import {importUserModule} from './module-loader.mjs';
|
|
9
|
+
import {formatZodError} from './config-schema.mjs';
|
|
10
|
+
import {ComponentDocSchema} from '../schemas/doc-schema.mjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Load a component doc through the shared load/validation boundary.
|
|
14
|
+
*
|
|
15
|
+
* This is the typed counterpart to {@link loadDocs}: it loads `.doc.ts` via
|
|
16
|
+
* jiti (and `.doc.mjs`/`.doc.js` via native import) and validates against
|
|
17
|
+
* {@link ComponentDocSchema}. That schema accepts BOTH formats, so this loader
|
|
18
|
+
* reads whichever the file uses:
|
|
19
|
+
* - NEW: the factory default export
|
|
20
|
+
* (`export default createComponentDoc({...})` / `createFunctionDoc` /
|
|
21
|
+
* `createDoc`) — the same single-export convention
|
|
22
|
+
* {@link loadModuleWithSchema} uses for config/integration/template. These
|
|
23
|
+
* carry a stamped `type` and validate against the matching per-kind schema.
|
|
24
|
+
* - OLD: the legacy loose `export const docs = {...}` (no `type`), validated
|
|
25
|
+
* against the permissive legacy union.
|
|
26
|
+
* The default export wins when both are present. Throws a readable
|
|
27
|
+
* `formatZodError`-style message on failure. Translations (`docsZh`/
|
|
28
|
+
* `docsDense`) are merged exactly as {@link loadDocs} does so callers see
|
|
29
|
+
* identical output.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} docPath absolute path to a `.doc.{ts,mjs,js}` file
|
|
32
|
+
* @param {{zh?: boolean, dense?: boolean, lang?: string}} [opts]
|
|
33
|
+
* @returns {Promise<object>} the validated (and optionally translated) doc
|
|
34
|
+
*/
|
|
35
|
+
export async function loadComponentDoc(
|
|
36
|
+
docPath,
|
|
37
|
+
{zh = false, dense = false, lang} = {},
|
|
38
|
+
) {
|
|
39
|
+
const mod = await importUserModule(docPath);
|
|
40
|
+
const authored = mod?.default ?? mod?.docs;
|
|
41
|
+
|
|
42
|
+
const result = ComponentDocSchema.safeParse(authored);
|
|
43
|
+
if (!result.success) {
|
|
44
|
+
throw new Error(formatZodError(docPath, result.error));
|
|
45
|
+
}
|
|
46
|
+
const docs = authored;
|
|
47
|
+
|
|
48
|
+
const locale = lang || (dense ? 'dense' : zh ? 'zh' : null);
|
|
49
|
+
if (!locale) return docs;
|
|
50
|
+
|
|
51
|
+
const translationKey =
|
|
52
|
+
locale === 'zh' ? 'docsZh' : locale === 'dense' ? 'docsDense' : null;
|
|
53
|
+
if (!translationKey || !mod[translationKey]) return docs;
|
|
54
|
+
|
|
55
|
+
const translation = mod[translationKey];
|
|
56
|
+
if (translation.props || translation.components?.some(c => c.props)) {
|
|
57
|
+
return translation;
|
|
58
|
+
}
|
|
59
|
+
return mergeTranslation(docs, translation);
|
|
60
|
+
}
|
|
8
61
|
|
|
9
62
|
export function mergeTranslation(docs, translation) {
|
|
10
63
|
if (!translation) return docs;
|
|
@@ -91,15 +144,64 @@ export async function loadDocs(readmePath, {zh = false, dense = false, lang} = {
|
|
|
91
144
|
|
|
92
145
|
const translation = mod[translationKey];
|
|
93
146
|
|
|
94
|
-
//
|
|
147
|
+
// A full ComponentDoc-shaped translation (legacy docsZh shape) used to be
|
|
148
|
+
// returned wholesale. That made it a REPLACEMENT, not an overlay: any prop
|
|
149
|
+
// the translation had not caught up with simply ceased to exist —
|
|
150
|
+
// `component Button --zh` silently omitted `isInterruptible` and
|
|
151
|
+
// `isIconOnly`. A reader of the translated docs cannot discover a prop that
|
|
152
|
+
// is not there. Overlay it instead, so an untranslated prop falls back to
|
|
153
|
+
// its English entry. (Same principle as the reference-doc overlays, #2182.)
|
|
95
154
|
if (translation.props || translation.components?.some(c => c.props)) {
|
|
96
|
-
return translation;
|
|
155
|
+
return overlayComponentDoc(docs, translation);
|
|
97
156
|
}
|
|
98
157
|
|
|
99
158
|
// Otherwise it's a TranslationDoc — merge it onto docs
|
|
100
159
|
return mergeTranslation(docs, translation);
|
|
101
160
|
}
|
|
102
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Overlay a full-ComponentDoc-shaped translation onto the English doc.
|
|
164
|
+
*
|
|
165
|
+
* Base order and completeness win; the translation supplies text for the
|
|
166
|
+
* entries it covers. Props are matched by name, never by position, so a
|
|
167
|
+
* translation that is missing entries (or lists them in another order) can no
|
|
168
|
+
* longer drop or misattribute one.
|
|
169
|
+
*
|
|
170
|
+
* @param {any} docs Base (English) component doc.
|
|
171
|
+
* @param {any} translation Translated doc, possibly covering only some props.
|
|
172
|
+
* @returns {any} Merged doc with every base prop present.
|
|
173
|
+
*/
|
|
174
|
+
function overlayComponentDoc(docs, translation) {
|
|
175
|
+
/** Merge one prop list: keep base entries and order, translate what's covered. */
|
|
176
|
+
const overlayProps = (baseProps, tProps) => {
|
|
177
|
+
if (!baseProps) return baseProps;
|
|
178
|
+
const byName = new Map((tProps ?? []).map(p => [p.name, p]));
|
|
179
|
+
return baseProps.map(prop => {
|
|
180
|
+
const t = byName.get(prop.name);
|
|
181
|
+
// Take the translated text, but never let it drop the prop's contract
|
|
182
|
+
// (type/default/required stay authoritative from the English doc).
|
|
183
|
+
return t ? {...prop, ...t, name: prop.name, type: prop.type} : prop;
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const merged = {...docs, ...translation};
|
|
188
|
+
|
|
189
|
+
merged.props = overlayProps(docs.props, translation.props);
|
|
190
|
+
|
|
191
|
+
if (docs.components) {
|
|
192
|
+
const tByName = new Map(
|
|
193
|
+
(translation.components ?? []).map(c => [c.name, c]),
|
|
194
|
+
);
|
|
195
|
+
merged.components = docs.components.map(base => {
|
|
196
|
+
const t = tByName.get(base.name);
|
|
197
|
+
if (!t) return base;
|
|
198
|
+
return {...base, ...t, props: overlayProps(base.props, t.props)};
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return merged;
|
|
203
|
+
}
|
|
204
|
+
|
|
103
205
|
/**
|
|
104
206
|
* Find the doc file for a component, checking both top-level
|
|
105
207
|
* and nested directories. Prefers {Name}.doc.mjs, then README.md
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Guards translated/compressed component docs against dropping props.
|
|
5
|
+
* @input packages/core/src/{Name}/{Name}.doc.mjs — its `docs`, `docsZh`, `docsDense`.
|
|
6
|
+
* @output Vitest failures naming every prop that exists in `docs` but vanishes
|
|
7
|
+
* from a translated view.
|
|
8
|
+
* @position Regression gate for component-loader.mjs.
|
|
9
|
+
*
|
|
10
|
+
* A `docsZh` that carries its own `props` array used to REPLACE the base doc
|
|
11
|
+
* wholesale, so any prop the translation had not caught up with simply ceased
|
|
12
|
+
* to exist: `astryx component Button --zh` silently omitted `isInterruptible`
|
|
13
|
+
* and `isIconOnly`. A reader of the translated docs cannot discover a prop that
|
|
14
|
+
* is not there, and CLAUDE.md tells every AI agent to read these docs.
|
|
15
|
+
*
|
|
16
|
+
* Translations are now an overlay: a prop the translation does not cover falls
|
|
17
|
+
* back to its English entry rather than disappearing. Same principle as the
|
|
18
|
+
* reference-doc overlays in #2182 — an overlay covering a subset must not
|
|
19
|
+
* destroy what it does not cover.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import {describe, it, expect} from 'vitest';
|
|
23
|
+
import * as fs from 'node:fs';
|
|
24
|
+
import * as path from 'node:path';
|
|
25
|
+
import {pathToFileURL} from 'node:url';
|
|
26
|
+
import {loadDocs} from './component-loader.mjs';
|
|
27
|
+
|
|
28
|
+
const CORE_SRC = path.join(
|
|
29
|
+
import.meta.dirname,
|
|
30
|
+
'..',
|
|
31
|
+
'..',
|
|
32
|
+
'..',
|
|
33
|
+
'core',
|
|
34
|
+
'src',
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
/** Component dirs that ship a doc file. */
|
|
38
|
+
function componentDocs() {
|
|
39
|
+
const out = [];
|
|
40
|
+
for (const dir of fs.readdirSync(CORE_SRC)) {
|
|
41
|
+
const docPath = path.join(CORE_SRC, dir, `${dir}.doc.mjs`);
|
|
42
|
+
if (!fs.existsSync(docPath)) continue;
|
|
43
|
+
if (!fs.readdirSync(path.join(CORE_SRC, dir)).includes(`${dir}.doc.mjs`)) {
|
|
44
|
+
continue; // case-exact match only
|
|
45
|
+
}
|
|
46
|
+
out.push({name: dir, docPath});
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Prop names on a doc, across single- and multi-component shapes. */
|
|
52
|
+
function propNames(doc) {
|
|
53
|
+
const names = new Set();
|
|
54
|
+
for (const p of doc?.props ?? []) names.add(p.name);
|
|
55
|
+
for (const c of doc?.components ?? []) {
|
|
56
|
+
for (const p of c.props ?? []) names.add(`${c.name ?? '?'}.${p.name}`);
|
|
57
|
+
}
|
|
58
|
+
return names;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe('translated component docs never drop a prop', () => {
|
|
62
|
+
const comps = componentDocs();
|
|
63
|
+
|
|
64
|
+
it('finds component docs to check', () => {
|
|
65
|
+
expect(comps.length).toBeGreaterThan(0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
for (const {name, docPath} of comps) {
|
|
69
|
+
for (const locale of ['zh', 'dense']) {
|
|
70
|
+
it(`${name} --${locale}: documents every prop the English doc documents`, async () => {
|
|
71
|
+
const mod = await import(pathToFileURL(docPath).href);
|
|
72
|
+
const key = locale === 'zh' ? 'docsZh' : 'docsDense';
|
|
73
|
+
if (!mod[key]) return; // no overlay, nothing to drift
|
|
74
|
+
|
|
75
|
+
const english = propNames(mod.docs);
|
|
76
|
+
const translated = propNames(
|
|
77
|
+
await loadDocs(docPath, {[locale]: true}),
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const dropped = [...english].filter(p => !translated.has(p));
|
|
81
|
+
expect(
|
|
82
|
+
dropped,
|
|
83
|
+
`${name}.doc.mjs ${key} drops ${dropped.length} prop(s) from the ` +
|
|
84
|
+
`--${locale} view: ${dropped.join(', ')}. A reader of the ` +
|
|
85
|
+
`translated docs cannot discover a prop that is not there. An ` +
|
|
86
|
+
`untranslated prop must fall back to its English entry, not vanish.`,
|
|
87
|
+
).toEqual([]);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('the reported symptom', () => {
|
|
94
|
+
it('astryx component Button --zh still lists isInterruptible and isIconOnly', async () => {
|
|
95
|
+
const docPath = path.join(CORE_SRC, 'Button', 'Button.doc.mjs');
|
|
96
|
+
const zh = await loadDocs(docPath, {zh: true});
|
|
97
|
+
const names = propNames(zh);
|
|
98
|
+
expect(names.has('isInterruptible')).toBe(true);
|
|
99
|
+
expect(names.has('isIconOnly')).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('keeps the translated descriptions it does have', async () => {
|
|
103
|
+
const docPath = path.join(CORE_SRC, 'Button', 'Button.doc.mjs');
|
|
104
|
+
const mod = await import(pathToFileURL(docPath).href);
|
|
105
|
+
const zh = await loadDocs(docPath, {zh: true});
|
|
106
|
+
|
|
107
|
+
const translated = mod.docsZh.props.find(p => p.name === 'variant');
|
|
108
|
+
const merged = zh.props.find(p => p.name === 'variant');
|
|
109
|
+
expect(merged.description).toBe(translated.description);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -73,33 +73,3 @@ export function formatZodError(label, error) {
|
|
|
73
73
|
.join('; ');
|
|
74
74
|
return `${label} is invalid: ${issues}`;
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @param {unknown} config
|
|
79
|
-
* @returns {import('../types/config').AstryxConfig}
|
|
80
|
-
*/
|
|
81
|
-
export function validateConfig(config) {
|
|
82
|
-
const result = AstryxConfigSchema.safeParse(config);
|
|
83
|
-
if (!result.success) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
formatZodError('astryx.config default export', result.error),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
return result.data;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @param {unknown} integration
|
|
93
|
-
* @param {string} [label]
|
|
94
|
-
* @returns {import('../types/integration').AstryxIntegration}
|
|
95
|
-
*/
|
|
96
|
-
export function validateIntegration(
|
|
97
|
-
integration,
|
|
98
|
-
label = 'integration manifest',
|
|
99
|
-
) {
|
|
100
|
-
const result = AstryxIntegrationSchema.safeParse(integration);
|
|
101
|
-
if (!result.success) {
|
|
102
|
-
throw new Error(formatZodError(label, result.error));
|
|
103
|
-
}
|
|
104
|
-
return result.data;
|
|
105
|
-
}
|
package/src/lib/hook-format.mjs
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import {discoverHooks, findHookDoc} from './hook-discovery.mjs';
|
|
13
13
|
import {loadDocs} from './component-loader.mjs';
|
|
14
|
+
import {mdCell} from './component-format.mjs';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Build a signature string from hook docs.
|
|
@@ -51,9 +52,11 @@ function formatParamsTable(params) {
|
|
|
51
52
|
lines.push('| Param | Type | Default | Description |');
|
|
52
53
|
lines.push('|-------|------|---------|-------------|');
|
|
53
54
|
for (const p of params) {
|
|
54
|
-
const def = p.default ? `\`${p.default}\`` : '\u2014';
|
|
55
|
+
const def = p.default ? `\`${mdCell(p.default)}\`` : '\u2014';
|
|
55
56
|
const req = p.required ? ' **(required)**' : '';
|
|
56
|
-
lines.push(
|
|
57
|
+
lines.push(
|
|
58
|
+
`| \`${mdCell(p.name)}\` | \`${mdCell(p.type)}\` | ${def} | ${mdCell(p.description)}${req} |`,
|
|
59
|
+
);
|
|
57
60
|
}
|
|
58
61
|
return lines.join('\n');
|
|
59
62
|
}
|
|
@@ -67,7 +70,9 @@ function formatReturnsTable(returns) {
|
|
|
67
70
|
lines.push('| Field | Type | Description |');
|
|
68
71
|
lines.push('|-------|------|-------------|');
|
|
69
72
|
for (const r of returns) {
|
|
70
|
-
lines.push(
|
|
73
|
+
lines.push(
|
|
74
|
+
`| \`${mdCell(r.name)}\` | \`${mdCell(r.type)}\` | ${mdCell(r.description)} |`,
|
|
75
|
+
);
|
|
71
76
|
}
|
|
72
77
|
return lines.join('\n');
|
|
73
78
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Minimal non-interactive terminal logger.
|
|
5
|
+
*
|
|
6
|
+
* @input message strings from CLI commands/codemods
|
|
7
|
+
* @output plain lines on stdout via humanLog (suppressed in --json mode)
|
|
8
|
+
* @position src/lib — shared output helper, no side effects on import
|
|
9
|
+
*
|
|
10
|
+
* The CLI is fully non-interactive: it never prompts, so it only needs plain,
|
|
11
|
+
* unbuffered output. This provides the *output-only* surface (`log.*`, `intro`,
|
|
12
|
+
* `outro`) the CLI needs, so it has no dependency on any prompt library.
|
|
13
|
+
*
|
|
14
|
+
* All output is routed through `humanLog`, the CLI's stdout-discipline
|
|
15
|
+
* primitive, which is a no-op in `--json` mode — so these human logs can never
|
|
16
|
+
* corrupt a JSON envelope.
|
|
17
|
+
*
|
|
18
|
+
* Call sites use it as `import * as p from '../lib/term-log.mjs'` and call
|
|
19
|
+
* `p.log.info(...)`, `p.intro(...)`, `p.outro(...)`.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import {humanLog} from './json.mjs';
|
|
23
|
+
|
|
24
|
+
const toStr = (msg) => (msg === undefined || msg === null ? '' : String(msg));
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Human-facing log surface (the small `log` API the CLI uses). All lines go to
|
|
28
|
+
* stdout via humanLog; the level prefixes are cosmetic. `--json` mode suppresses
|
|
29
|
+
* every one of these, keeping machine-readable stdout clean.
|
|
30
|
+
*/
|
|
31
|
+
export const log = {
|
|
32
|
+
message: (msg) => humanLog(toStr(msg)),
|
|
33
|
+
info: (msg) => humanLog(toStr(msg)),
|
|
34
|
+
step: (msg) => humanLog(toStr(msg)),
|
|
35
|
+
success: (msg) => humanLog(`✓ ${toStr(msg)}`),
|
|
36
|
+
warn: (msg) => humanLog(`⚠ ${toStr(msg)}`),
|
|
37
|
+
error: (msg) => humanLog(`✗ ${toStr(msg)}`),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** Banner printed at the start of a multi-step command. */
|
|
41
|
+
export function intro(title) {
|
|
42
|
+
humanLog(`\n${toStr(title)}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Footer printed at the end of a multi-step command. */
|
|
46
|
+
export function outro(message) {
|
|
47
|
+
humanLog(`${toStr(message)}\n`);
|
|
48
|
+
}
|
package/src/lib/xle/registry.mjs
CHANGED