@astryxdesign/cli 0.1.1-canary.a514b99 → 0.1.1-canary.a7d67d0
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/docs/working-with-ai.doc.mjs +6 -6
- package/package.json +19 -8
- package/src/api/discover.mjs +78 -26
- package/src/api/layout.mjs +301 -0
- package/src/api/layout.test.mjs +238 -0
- package/src/api/template.mjs +191 -50
- package/src/api/template.test.mjs +2 -0
- package/src/codemods/__tests__/registry.test.mjs +1 -0
- package/src/codemods/registry.mjs +1 -0
- package/src/codemods/transforms/v0.1.2/__tests__/rename-text-color-active-to-accent.test.mjs +120 -0
- package/src/codemods/transforms/v0.1.2/index.mjs +19 -0
- package/src/codemods/transforms/v0.1.2/rename-text-color-active-to-accent.mjs +136 -0
- package/src/commands/gap-report.mjs +17 -9
- package/src/commands/gap-report.test.mjs +21 -16
- package/src/commands/init.mjs +34 -8
- package/src/commands/init.next-steps.test.mjs +46 -0
- package/src/commands/layout.mjs +139 -0
- package/src/commands/swizzle.mjs +51 -23
- package/src/commands/upgrade.mjs +2 -71
- package/src/config.mjs +31 -0
- package/src/config.test.mjs +24 -0
- package/src/index.mjs +4 -0
- package/src/lib/config-schema.mjs +119 -0
- package/src/lib/config.mjs +34 -7
- package/src/lib/config.test.mjs +51 -2
- package/src/lib/error-codes.mjs +8 -0
- package/src/lib/integrations.mjs +155 -0
- package/src/lib/integrations.test.mjs +154 -0
- package/src/lib/levenshtein.mjs +29 -0
- package/src/lib/manifest.mjs +6 -0
- package/src/lib/package-scanner.mjs +31 -7
- package/src/lib/string-utils.mjs +5 -14
- package/src/lib/xle/browser.d.ts +100 -0
- package/src/lib/xle/browser.mjs +120 -0
- package/src/lib/xle/expand.mjs +622 -0
- package/src/lib/xle/parse.mjs +581 -0
- package/src/lib/xle/print.mjs +174 -0
- package/src/lib/xle/registry-core.mjs +170 -0
- package/src/lib/xle/registry.mjs +237 -0
- package/src/lib/xle/splice.mjs +137 -0
- package/src/lib/xle/validate.mjs +356 -0
- package/src/lib/xle/xle.test.mjs +333 -0
- package/src/types/config.d.ts +99 -0
- package/src/utils/github.mjs +12 -27
- package/templates/blocks/components/Card/ClickableCardWithNestedButton.doc.mjs +1 -1
- package/templates/blocks/components/Card/SelectableCardMulti.doc.mjs +1 -1
- package/templates/blocks/components/ChatDictationButton/ChatDictationButtonShowcase.tsx +3 -3
- package/templates/blocks/components/CommandPaletteEmpty/CommandPaletteEmptyShowcase.doc.mjs +15 -0
- package/templates/blocks/components/CommandPaletteEmpty/CommandPaletteEmptyShowcase.tsx +26 -0
- package/templates/blocks/components/DateInput/DateInputDateRange.doc.mjs +2 -2
- package/templates/blocks/components/FileInput/FileInputShowcase.tsx +4 -2
- package/templates/blocks/components/LinkProvider/LinkProviderCustomLink.doc.mjs +14 -0
- package/templates/blocks/components/LinkProvider/LinkProviderCustomLink.tsx +43 -0
- package/templates/blocks/components/MultiSelector/MultiSelectorShowcase.tsx +6 -2
- package/templates/blocks/components/NumberInput/NumberInputShowcase.tsx +6 -2
- package/templates/blocks/components/RadioList/RadioListShowcase.tsx +8 -1
- package/templates/blocks/components/SegmentedControl/SegmentedControlShowcase.tsx +3 -1
- package/templates/blocks/components/Selector/SelectorShowcase.tsx +4 -1
- package/templates/blocks/components/Slider/SliderShowcase.tsx +10 -1
- package/templates/blocks/components/Tab/TabShowcase.tsx +3 -1
- package/templates/blocks/components/TabList/TabListShowcase.tsx +3 -1
- package/templates/blocks/components/TabMenu/TabMenuShowcase.tsx +3 -1
- package/templates/blocks/components/Table/ColumnResizeHookUsage.doc.mjs +14 -0
- package/templates/blocks/components/Table/ColumnResizeHookUsage.tsx +59 -0
- package/templates/blocks/components/Table/StickyColumnsHookUsage.doc.mjs +14 -0
- package/templates/blocks/components/Table/StickyColumnsHookUsage.tsx +104 -0
- package/templates/blocks/components/Text/TextColors.tsx +20 -5
- package/templates/blocks/components/TextArea/TextAreaShowcase.tsx +4 -2
- package/templates/blocks/components/TextInput/TextInputShowcase.tsx +4 -2
- package/templates/blocks/components/Thumbnail/ThumbnailGallery.tsx +25 -5
- package/templates/blocks/components/Timestamp/TimestampColors.tsx +2 -2
- package/templates/blocks/components/ToggleButton/ToggleButtonGroup.doc.mjs +1 -1
- package/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +8 -6
- package/templates/blocks/components/Typeahead/TypeaheadShowcase.tsx +6 -2
- package/templates/pages/theme-showcase/page.tsx +8 -19
- package/templates/blocks/components/MoreMenu/MoreMenuInToolbar.doc.mjs +0 -14
- package/templates/blocks/components/MoreMenu/MoreMenuInToolbar.tsx +0 -57
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, it, expect} from 'vitest';
|
|
4
|
+
|
|
5
|
+
async function applyTransform(source) {
|
|
6
|
+
const {default: transform} =
|
|
7
|
+
await import('../rename-text-color-active-to-accent.mjs');
|
|
8
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
9
|
+
const j = jscodeshift.withParser('tsx');
|
|
10
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
11
|
+
const file = {source, path: 'test.tsx'};
|
|
12
|
+
const result = transform(file, api);
|
|
13
|
+
return result ?? source;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('rename-text-color-active-to-accent', () => {
|
|
17
|
+
it('renames Text color="active" to color="accent"', async () => {
|
|
18
|
+
const input = `<Text color="active">Hi</Text>`;
|
|
19
|
+
const output = await applyTransform(input);
|
|
20
|
+
expect(output).toContain("'accent'");
|
|
21
|
+
expect(output).not.toContain('active');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('renames Heading color="active" to color="accent"', async () => {
|
|
25
|
+
const input = `<Heading level={2} color="active">Title</Heading>`;
|
|
26
|
+
const output = await applyTransform(input);
|
|
27
|
+
expect(output).toContain("'accent'");
|
|
28
|
+
expect(output).not.toContain('active');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('renames Link color="active" to color="accent"', async () => {
|
|
32
|
+
const input = `<Link href="/x" color="active">Go</Link>`;
|
|
33
|
+
const output = await applyTransform(input);
|
|
34
|
+
expect(output).toContain("'accent'");
|
|
35
|
+
expect(output).not.toContain('active');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('renames Timestamp color="active" to color="accent"', async () => {
|
|
39
|
+
const input = `<Timestamp value={d} color="active" />`;
|
|
40
|
+
const output = await applyTransform(input);
|
|
41
|
+
expect(output).toContain("'accent'");
|
|
42
|
+
expect(output).not.toContain('active');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("renames expression-container color={'active'}", async () => {
|
|
46
|
+
const input = `<Text color={'active'}>Hi</Text>`;
|
|
47
|
+
const output = await applyTransform(input);
|
|
48
|
+
expect(output).toContain("'accent'");
|
|
49
|
+
expect(output).not.toContain("'active'");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('renames active inside a ternary color expression', async () => {
|
|
53
|
+
const input = `<Text color={isOn ? 'active' : 'secondary'}>Hi</Text>`;
|
|
54
|
+
const output = await applyTransform(input);
|
|
55
|
+
expect(output).toContain("'accent'");
|
|
56
|
+
expect(output).toContain("'secondary'");
|
|
57
|
+
expect(output).not.toContain("'active'");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('does not change other color values', async () => {
|
|
61
|
+
const input = `<Text color="secondary">Hi</Text>`;
|
|
62
|
+
const output = await applyTransform(input);
|
|
63
|
+
expect(output).toBe(input);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('does not touch color="active" on non-target components', async () => {
|
|
67
|
+
const input = `<StatusDot color="active" />`;
|
|
68
|
+
const output = await applyTransform(input);
|
|
69
|
+
expect(output).toBe(input);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('does not touch unrelated "active" string literals', async () => {
|
|
73
|
+
const input = `const node = {id: 'active', label: 'Active Users'};`;
|
|
74
|
+
const output = await applyTransform(input);
|
|
75
|
+
expect(output).toBe(input);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('does not touch a status enum value named active', async () => {
|
|
79
|
+
const input = `const filters = {status: 'active'};`;
|
|
80
|
+
const output = await applyTransform(input);
|
|
81
|
+
expect(output).toBe(input);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('renames object color prop in files importing a target component', async () => {
|
|
85
|
+
const input = `import {Text} from '@xds/core/Text';
|
|
86
|
+
const cfg = {color: 'active'};`;
|
|
87
|
+
const output = await applyTransform(input);
|
|
88
|
+
expect(output).toContain("color: 'accent'");
|
|
89
|
+
expect(output).not.toContain("'active'");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("renames color: 'active' as const in files importing a target component", async () => {
|
|
93
|
+
const input = `import {Text} from '@xds/core/Text';
|
|
94
|
+
const COLORS = [{color: 'active' as const, description: 'Accent'}];`;
|
|
95
|
+
const output = await applyTransform(input);
|
|
96
|
+
expect(output).toContain("'accent' as const");
|
|
97
|
+
expect(output).not.toContain("'active'");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('does not rename object color prop when no target component is imported', async () => {
|
|
101
|
+
const input = `const cfg = {color: 'active'};`;
|
|
102
|
+
const output = await applyTransform(input);
|
|
103
|
+
expect(output).toBe(input);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('renames active in Storybook color argTypes options', async () => {
|
|
107
|
+
const input = `import {Text} from '@xds/core/Text';
|
|
108
|
+
const meta = {argTypes: {color: {control: 'select', options: ['primary', 'active', 'inherit']}}};`;
|
|
109
|
+
const output = await applyTransform(input);
|
|
110
|
+
expect(output).toContain("'accent'");
|
|
111
|
+
expect(output).not.toContain("'active'");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('returns undefined (no change) when nothing matches', async () => {
|
|
115
|
+
const input = `<Text color="primary">Hi</Text>`;
|
|
116
|
+
const output = await applyTransform(input);
|
|
117
|
+
// applyTransform falls back to source when transform returns undefined
|
|
118
|
+
expect(output).toBe(input);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file v0.1.2 transform manifest
|
|
5
|
+
*
|
|
6
|
+
* Lists all codemods for the v0.1.2 release in the order they should run.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import renameTextColorActiveToAccent, {
|
|
10
|
+
meta as renameTextColorActiveToAccentMeta,
|
|
11
|
+
} from './rename-text-color-active-to-accent.mjs';
|
|
12
|
+
|
|
13
|
+
export default [
|
|
14
|
+
{
|
|
15
|
+
name: 'rename-text-color-active-to-accent',
|
|
16
|
+
transform: renameTextColorActiveToAccent,
|
|
17
|
+
meta: renameTextColorActiveToAccentMeta,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Codemod: Rename Text/Heading/Link/Timestamp color "active" to "accent"
|
|
5
|
+
* @see https://github.com/facebook/astryx/issues/2863
|
|
6
|
+
*
|
|
7
|
+
* The `active` text-color value is renamed to `accent` and now maps to the
|
|
8
|
+
* dedicated `--color-text-accent` token (legible accent ink) instead of
|
|
9
|
+
* `--color-accent` (the interactive/base accent surface). This gives a
|
|
10
|
+
* first-class, type-safe way to render accent-colored text and resolves the
|
|
11
|
+
* gap reported in #2863.
|
|
12
|
+
*
|
|
13
|
+
* Transforms (scoped to Text, Heading, Link, and Timestamp):
|
|
14
|
+
* - <Text color="active" /> → <Text color="accent" />
|
|
15
|
+
* - <Heading color={'active'} /> → <Heading color={'accent'} />
|
|
16
|
+
* - <Text color={cond ? 'active' : x}> → <Text color={cond ? 'accent' : x}>
|
|
17
|
+
* - Storybook argTypes: color: { options: [..., 'active', ...] }
|
|
18
|
+
* → replaces 'active' with 'accent' (files importing a target component)
|
|
19
|
+
* - Object properties: { color: 'active' } / { color: 'active' as const }
|
|
20
|
+
* → { color: 'accent' } (files importing a target component)
|
|
21
|
+
*
|
|
22
|
+
* The transform deliberately does NOT touch bare `'active'` strings that are
|
|
23
|
+
* not a `color` value (e.g. status enums, ids, filter values), so it is safe
|
|
24
|
+
* to run across an entire codebase.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export const meta = {
|
|
28
|
+
title: 'Rename Text/Heading/Link/Timestamp color "active" to "accent"',
|
|
29
|
+
description:
|
|
30
|
+
'Renames the `color="active"` value to `color="accent"` on Text, Heading, ' +
|
|
31
|
+
'Link, and Timestamp. The `accent` value maps to `--color-text-accent` ' +
|
|
32
|
+
'(the dedicated accent text ink). Also updates Storybook color argTypes ' +
|
|
33
|
+
'options and object-literal `color` props in files that import a target component.',
|
|
34
|
+
pr: '#2863',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const OLD_VALUE = 'active';
|
|
38
|
+
const NEW_VALUE = 'accent';
|
|
39
|
+
|
|
40
|
+
/** Components whose `color` prop accepts a TextColor value. */
|
|
41
|
+
const TARGET_COMPONENTS = new Set(['Text', 'Heading', 'Link', 'Timestamp']);
|
|
42
|
+
|
|
43
|
+
export default function transformer(file, api) {
|
|
44
|
+
const j = api.jscodeshift;
|
|
45
|
+
const root = j(file.source);
|
|
46
|
+
let hasChanges = false;
|
|
47
|
+
|
|
48
|
+
/** Rewrite a string-literal node when it equals the old value. */
|
|
49
|
+
function renameStringLiteral(node) {
|
|
50
|
+
if (!node) return false;
|
|
51
|
+
if (
|
|
52
|
+
(node.type === 'StringLiteral' || node.type === 'Literal') &&
|
|
53
|
+
node.value === OLD_VALUE
|
|
54
|
+
) {
|
|
55
|
+
node.value = NEW_VALUE;
|
|
56
|
+
if (node.raw) node.raw = `'${NEW_VALUE}'`;
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Recursively rewrite the old value inside ternary/logical expressions. */
|
|
63
|
+
function renameInExpression(node) {
|
|
64
|
+
if (!node) return false;
|
|
65
|
+
let changed = false;
|
|
66
|
+
if (node.type === 'StringLiteral' || node.type === 'Literal') {
|
|
67
|
+
changed = renameStringLiteral(node) || changed;
|
|
68
|
+
} else if (node.type === 'ConditionalExpression') {
|
|
69
|
+
changed = renameInExpression(node.consequent) || changed;
|
|
70
|
+
changed = renameInExpression(node.alternate) || changed;
|
|
71
|
+
} else if (node.type === 'LogicalExpression') {
|
|
72
|
+
changed = renameInExpression(node.left) || changed;
|
|
73
|
+
changed = renameInExpression(node.right) || changed;
|
|
74
|
+
} else if (node.type === 'TSAsExpression') {
|
|
75
|
+
// `'active' as const` → rewrite the inner expression
|
|
76
|
+
changed = renameInExpression(node.expression) || changed;
|
|
77
|
+
}
|
|
78
|
+
return changed;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// --- 1. JSX attribute: color="active" / color={'active'} on target components ---
|
|
82
|
+
root.find(j.JSXOpeningElement).forEach(path => {
|
|
83
|
+
const name = path.node.name;
|
|
84
|
+
const componentName = name.type === 'JSXIdentifier' ? name.name : null;
|
|
85
|
+
if (!componentName || !TARGET_COMPONENTS.has(componentName)) return;
|
|
86
|
+
|
|
87
|
+
path.node.attributes.forEach(attr => {
|
|
88
|
+
if (attr.type !== 'JSXAttribute') return;
|
|
89
|
+
if (!attr.name || attr.name.name !== 'color') return;
|
|
90
|
+
|
|
91
|
+
const value = attr.value;
|
|
92
|
+
if (!value) return;
|
|
93
|
+
|
|
94
|
+
if (value.type === 'StringLiteral' || value.type === 'Literal') {
|
|
95
|
+
if (renameStringLiteral(value)) hasChanges = true;
|
|
96
|
+
} else if (value.type === 'JSXExpressionContainer') {
|
|
97
|
+
if (renameInExpression(value.expression)) hasChanges = true;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Object-property / argTypes transforms only run in files that use a target
|
|
103
|
+
// component — keeps unrelated `{ color: 'active' }` / `'active'` strings safe.
|
|
104
|
+
const importsTarget =
|
|
105
|
+
root
|
|
106
|
+
.find(j.ImportSpecifier)
|
|
107
|
+
.filter(p => TARGET_COMPONENTS.has(p.node.imported?.name))
|
|
108
|
+
.size() > 0;
|
|
109
|
+
|
|
110
|
+
if (importsTarget) {
|
|
111
|
+
const PropertyType = j.ObjectProperty ?? j.Property;
|
|
112
|
+
|
|
113
|
+
// --- 2. Object property: { color: 'active' } / { color: 'active' as const } ---
|
|
114
|
+
root.find(PropertyType, {key: {name: 'color'}}).forEach(path => {
|
|
115
|
+
if (renameInExpression(path.node.value)) hasChanges = true;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// --- 3. Storybook argTypes: color: { options: [..., 'active', ...] } ---
|
|
119
|
+
root.find(PropertyType, {key: {name: 'color'}}).forEach(path => {
|
|
120
|
+
const value = path.node.value;
|
|
121
|
+
if (!value || value.type !== 'ObjectExpression') return;
|
|
122
|
+
|
|
123
|
+
const optionsProp = value.properties.find(
|
|
124
|
+
p => p.key && (p.key.name === 'options' || p.key.value === 'options'),
|
|
125
|
+
);
|
|
126
|
+
if (optionsProp && optionsProp.value.type === 'ArrayExpression') {
|
|
127
|
+
optionsProp.value.elements.forEach(el => {
|
|
128
|
+
if (renameStringLiteral(el)) hasChanges = true;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!hasChanges) return undefined;
|
|
135
|
+
return root.toSource({quote: 'single'});
|
|
136
|
+
}
|
|
@@ -132,7 +132,7 @@ export function registerGapReport(program) {
|
|
|
132
132
|
.action(async () => {
|
|
133
133
|
p.intro('Gap report setup');
|
|
134
134
|
|
|
135
|
-
const config = loadGapReportConfig();
|
|
135
|
+
const config = await loadGapReportConfig();
|
|
136
136
|
const currentMode = !config.enabled
|
|
137
137
|
? 'disabled'
|
|
138
138
|
: config.command
|
|
@@ -252,9 +252,14 @@ export function registerGapReport(program) {
|
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
const config = loadGapReportConfig();
|
|
255
|
+
const config = await loadGapReportConfig();
|
|
256
256
|
if (!config.enabled) {
|
|
257
|
-
if (json)
|
|
257
|
+
if (json)
|
|
258
|
+
return jsonError(
|
|
259
|
+
'Gap reporting is disabled',
|
|
260
|
+
undefined,
|
|
261
|
+
ERROR_CODES.ERR_GAP_REPORT_FAILED,
|
|
262
|
+
);
|
|
258
263
|
humanLog(
|
|
259
264
|
`Gap reporting is disabled (ASTRYX_GAP_REPORT=off or astryx.config.mjs).\n` +
|
|
260
265
|
`Run \`${getRunPrefix()} astryx gap-report setup\` to configure.`,
|
|
@@ -295,7 +300,7 @@ export function registerGapReport(program) {
|
|
|
295
300
|
return;
|
|
296
301
|
}
|
|
297
302
|
|
|
298
|
-
const preview = buildGapReportPreview({
|
|
303
|
+
const preview = await buildGapReportPreview({
|
|
299
304
|
component: options.component,
|
|
300
305
|
category: options.category,
|
|
301
306
|
intention: options.reason,
|
|
@@ -326,7 +331,7 @@ export function registerGapReport(program) {
|
|
|
326
331
|
}
|
|
327
332
|
|
|
328
333
|
try {
|
|
329
|
-
const url = createGapReport({
|
|
334
|
+
const url = await createGapReport({
|
|
330
335
|
component: options.component,
|
|
331
336
|
category: options.category,
|
|
332
337
|
intention: options.reason,
|
|
@@ -343,7 +348,9 @@ export function registerGapReport(program) {
|
|
|
343
348
|
humanLog('\nGap reporting is disabled via configuration.\n');
|
|
344
349
|
}
|
|
345
350
|
} catch (err) {
|
|
346
|
-
cliError(`Filing gap report failed: ${err.message}`, {
|
|
351
|
+
cliError(`Filing gap report failed: ${err.message}`, {
|
|
352
|
+
code: ERROR_CODES.ERR_GAP_REPORT_FAILED,
|
|
353
|
+
});
|
|
347
354
|
return;
|
|
348
355
|
}
|
|
349
356
|
return;
|
|
@@ -386,7 +393,8 @@ export function registerGapReport(program) {
|
|
|
386
393
|
placeholder:
|
|
387
394
|
'e.g. "Need a compact variant for use in dense data tables"',
|
|
388
395
|
validate: val => {
|
|
389
|
-
if (!val.trim())
|
|
396
|
+
if (!val.trim())
|
|
397
|
+
return 'Please describe what you were trying to do';
|
|
390
398
|
},
|
|
391
399
|
}),
|
|
392
400
|
);
|
|
@@ -406,7 +414,7 @@ export function registerGapReport(program) {
|
|
|
406
414
|
source: 'interactive',
|
|
407
415
|
};
|
|
408
416
|
|
|
409
|
-
const preview = buildGapReportPreview(previewArgs);
|
|
417
|
+
const preview = await buildGapReportPreview(previewArgs);
|
|
410
418
|
|
|
411
419
|
// Always show the user exactly what would be filed before sending.
|
|
412
420
|
p.note(
|
|
@@ -440,7 +448,7 @@ export function registerGapReport(program) {
|
|
|
440
448
|
s.start('Filing gap report');
|
|
441
449
|
|
|
442
450
|
try {
|
|
443
|
-
const url = createGapReport(previewArgs);
|
|
451
|
+
const url = await createGapReport(previewArgs);
|
|
444
452
|
s.stop(url ? 'Gap report filed' : 'Gap reporting is disabled');
|
|
445
453
|
if (url) {
|
|
446
454
|
p.log.success(url);
|
|
@@ -40,9 +40,9 @@ describe('shouldActuallyFile', () => {
|
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
it('--dry-run wins over --commit (safety)', () => {
|
|
43
|
-
expect(
|
|
44
|
-
|
|
45
|
-
)
|
|
43
|
+
expect(shouldActuallyFile({isTTY: true, commit: true, dryRun: true})).toBe(
|
|
44
|
+
false,
|
|
45
|
+
);
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
48
|
|
|
@@ -54,7 +54,9 @@ describe('formatPreview', () => {
|
|
|
54
54
|
title: '[gap] Button: missing compact variant',
|
|
55
55
|
body: '## User Intention\n\nNeed a compact variant',
|
|
56
56
|
});
|
|
57
|
-
expect(out).toContain(
|
|
57
|
+
expect(out).toContain(
|
|
58
|
+
'Would file GitHub issue on facebookexperimental/xds',
|
|
59
|
+
);
|
|
58
60
|
expect(out).toContain('[gap] Button');
|
|
59
61
|
expect(out).toContain('Need a compact variant');
|
|
60
62
|
expect(out).toContain('Labels: gap-report');
|
|
@@ -91,13 +93,14 @@ describe('ASTRYX_GAP_REPORT=off env var', () => {
|
|
|
91
93
|
it('disables gap reporting when set to "off"', async () => {
|
|
92
94
|
process.env.ASTRYX_GAP_REPORT = 'off';
|
|
93
95
|
vi.resetModules();
|
|
94
|
-
const {loadGapReportConfig, createGapReport} =
|
|
95
|
-
'../utils/github.mjs'
|
|
96
|
-
)
|
|
97
|
-
|
|
96
|
+
const {loadGapReportConfig, createGapReport} =
|
|
97
|
+
await import('../utils/github.mjs');
|
|
98
|
+
await expect(loadGapReportConfig()).resolves.toMatchObject({
|
|
99
|
+
enabled: false,
|
|
100
|
+
});
|
|
98
101
|
|
|
99
102
|
// createGapReport must return null and never invoke gh.
|
|
100
|
-
const result = createGapReport({
|
|
103
|
+
const result = await createGapReport({
|
|
101
104
|
component: 'Button',
|
|
102
105
|
category: 'other',
|
|
103
106
|
intention: 'test',
|
|
@@ -109,12 +112,16 @@ describe('ASTRYX_GAP_REPORT=off env var', () => {
|
|
|
109
112
|
process.env.ASTRYX_GAP_REPORT = 'false';
|
|
110
113
|
vi.resetModules();
|
|
111
114
|
let mod = await import('../utils/github.mjs');
|
|
112
|
-
expect(mod.loadGapReportConfig()
|
|
115
|
+
await expect(mod.loadGapReportConfig()).resolves.toMatchObject({
|
|
116
|
+
enabled: false,
|
|
117
|
+
});
|
|
113
118
|
|
|
114
119
|
process.env.ASTRYX_GAP_REPORT = '0';
|
|
115
120
|
vi.resetModules();
|
|
116
121
|
mod = await import('../utils/github.mjs');
|
|
117
|
-
expect(mod.loadGapReportConfig()
|
|
122
|
+
await expect(mod.loadGapReportConfig()).resolves.toMatchObject({
|
|
123
|
+
enabled: false,
|
|
124
|
+
});
|
|
118
125
|
});
|
|
119
126
|
});
|
|
120
127
|
|
|
@@ -133,16 +140,14 @@ describe('buildGapReportPreview', () => {
|
|
|
133
140
|
it('renders title and body without invoking gh', async () => {
|
|
134
141
|
vi.resetModules();
|
|
135
142
|
const {buildGapReportPreview} = await import('../utils/github.mjs');
|
|
136
|
-
const preview = buildGapReportPreview({
|
|
143
|
+
const preview = await buildGapReportPreview({
|
|
137
144
|
component: 'Button',
|
|
138
145
|
category: 'missing_variant',
|
|
139
146
|
intention: 'Need compact variant for tables',
|
|
140
147
|
});
|
|
141
148
|
expect(preview.mode).toBe('github');
|
|
142
149
|
expect(preview.enabled).toBe(true);
|
|
143
|
-
expect(preview.title).toBe(
|
|
144
|
-
'[gap] Button: Need compact variant for tables',
|
|
145
|
-
);
|
|
150
|
+
expect(preview.title).toBe('[gap] Button: Need compact variant for tables');
|
|
146
151
|
expect(preview.body).toContain('| **Component** | Button |');
|
|
147
152
|
expect(preview.body).toContain('Need compact variant for tables');
|
|
148
153
|
expect(preview.repo).toBe('facebookexperimental/xds');
|
|
@@ -152,7 +157,7 @@ describe('buildGapReportPreview', () => {
|
|
|
152
157
|
process.env.ASTRYX_GAP_REPORT = 'off';
|
|
153
158
|
vi.resetModules();
|
|
154
159
|
const {buildGapReportPreview} = await import('../utils/github.mjs');
|
|
155
|
-
const preview = buildGapReportPreview({
|
|
160
|
+
const preview = await buildGapReportPreview({
|
|
156
161
|
component: 'Button',
|
|
157
162
|
category: 'other',
|
|
158
163
|
intention: 'x',
|
package/src/commands/init.mjs
CHANGED
|
@@ -29,6 +29,37 @@ import {requireInteractive} from '../utils/interactive.mjs';
|
|
|
29
29
|
const VALID_FEATURES = ['agents', 'theme', 'template'];
|
|
30
30
|
const run = getRunPrefix();
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Build the "Next steps" lines printed at the end of `astryx init`.
|
|
34
|
+
*
|
|
35
|
+
* Theme guidance must match the runtime recommendation emitted by core's
|
|
36
|
+
* <Theme> component (packages/core/src/theme/Theme.tsx): the pre-built theme
|
|
37
|
+
* path (`/built` import + `theme.css`) plus the base CSS import, so users
|
|
38
|
+
* don't end up with an unstyled app or the slower runtime style-injection
|
|
39
|
+
* path. See https://github.com/facebook/astryx/issues/3080.
|
|
40
|
+
*
|
|
41
|
+
* Exported for testing.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} runPrefix package-manager run prefix (e.g. `npx`)
|
|
44
|
+
* @returns {string[]} ordered list of human-facing lines
|
|
45
|
+
*/
|
|
46
|
+
export function getNextSteps(runPrefix) {
|
|
47
|
+
return [
|
|
48
|
+
'',
|
|
49
|
+
' Next steps:',
|
|
50
|
+
" 1. Import base styles: import '@astryxdesign/core/reset.css'",
|
|
51
|
+
" and import '@astryxdesign/core/astryx.css'",
|
|
52
|
+
" 2. Import components: import { Button } from '@astryxdesign/core'",
|
|
53
|
+
' 3. Optionally add a theme (use the pre-built path for performance):',
|
|
54
|
+
" import { neutralTheme } from '@astryxdesign/theme-neutral/built'",
|
|
55
|
+
" import '@astryxdesign/theme-neutral/theme.css'",
|
|
56
|
+
' <Theme theme={neutralTheme}>...</Theme>',
|
|
57
|
+
` For custom themes, run \`${runPrefix} astryx theme build <file>\` to generate the built artifacts.`,
|
|
58
|
+
` 4. ${runPrefix} astryx --help for all commands`,
|
|
59
|
+
'',
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
|
|
32
63
|
function isCancel(value) {
|
|
33
64
|
if (p.isCancel(value)) {
|
|
34
65
|
p.cancel('Setup cancelled.');
|
|
@@ -250,13 +281,8 @@ export function registerInit(program) {
|
|
|
250
281
|
// Outro
|
|
251
282
|
p.outro('Design system initialized!');
|
|
252
283
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
humanLog(' 2. Optionally add a theme:');
|
|
257
|
-
humanLog(" import { neutralTheme } from '@astryxdesign/theme-neutral'");
|
|
258
|
-
humanLog(' <Theme theme={neutralTheme}>...</Theme>');
|
|
259
|
-
humanLog(` 3. ${run} astryx --help for all commands`);
|
|
260
|
-
humanLog('');
|
|
284
|
+
for (const line of getNextSteps(run)) {
|
|
285
|
+
humanLog(line);
|
|
286
|
+
}
|
|
261
287
|
});
|
|
262
288
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Regression test for `astryx init` "Next steps" theme guidance.
|
|
5
|
+
*
|
|
6
|
+
* The init command previously steered users toward the slower runtime
|
|
7
|
+
* style-injection path:
|
|
8
|
+
*
|
|
9
|
+
* import { neutralTheme } from '@astryxdesign/theme-neutral'
|
|
10
|
+
* <Theme theme={neutralTheme}>...</Theme>
|
|
11
|
+
*
|
|
12
|
+
* ...which contradicted the runtime console warning emitted by core's
|
|
13
|
+
* <Theme> component (packages/core/src/theme/Theme.tsx) recommending the
|
|
14
|
+
* pre-built path, and left users with an unstyled app because the base CSS
|
|
15
|
+
* imports were never mentioned (facebook/astryx#3080).
|
|
16
|
+
*
|
|
17
|
+
* These assertions lock in the corrected guidance: base CSS imports, the
|
|
18
|
+
* pre-built (`/built` + `theme.css`) theme path, and the custom-theme build
|
|
19
|
+
* command.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import {describe, it, expect} from 'vitest';
|
|
23
|
+
import {getNextSteps} from './init.mjs';
|
|
24
|
+
|
|
25
|
+
describe('init Next steps theme guidance', () => {
|
|
26
|
+
const text = getNextSteps('npx').join('\n');
|
|
27
|
+
|
|
28
|
+
it('mentions the base CSS imports so the app is not left unstyled', () => {
|
|
29
|
+
expect(text).toContain("'@astryxdesign/core/reset.css'");
|
|
30
|
+
expect(text).toContain("'@astryxdesign/core/astryx.css'");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('uses the pre-built theme path matching the runtime recommendation', () => {
|
|
34
|
+
expect(text).toContain("'@astryxdesign/theme-neutral/built'");
|
|
35
|
+
expect(text).toContain("'@astryxdesign/theme-neutral/theme.css'");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('mentions building custom themes via `astryx theme build`', () => {
|
|
39
|
+
expect(text).toContain('astryx theme build <file>');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('does not steer users to the runtime style-injection import', () => {
|
|
43
|
+
// The bare source import (no `/built`) is the slow runtime-injection path.
|
|
44
|
+
expect(text).not.toContain("from '@astryxdesign/theme-neutral'");
|
|
45
|
+
});
|
|
46
|
+
});
|