@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
package/src/commands/build.mjs
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* the whole CLI, use `astryx search <query>` instead.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import {getCliInvocation, formatCliCommand} from '../utils/package-manager.mjs';
|
|
19
19
|
import {jsonOut, humanLog} from '../lib/json.mjs';
|
|
20
20
|
import {cliError} from '../lib/cli-error.mjs';
|
|
21
21
|
import {search as searchApi} from '../api/search.mjs';
|
|
@@ -47,25 +47,25 @@ function printPlaybook(run) {
|
|
|
47
47
|
'How to build a page with Astryx',
|
|
48
48
|
'',
|
|
49
49
|
"1. Find a starting point for what you're building:",
|
|
50
|
-
` ${run}
|
|
50
|
+
` ${run} build "<what you're building>"`,
|
|
51
51
|
' → returns the closest [page] template, the [block]s that cover parts,',
|
|
52
52
|
' and the [component]s to fill the gaps, with a "Compose:" suggestion.',
|
|
53
53
|
'',
|
|
54
54
|
'2. If a [page] template matches → scaffold it and adapt:',
|
|
55
|
-
` ${run}
|
|
55
|
+
` ${run} template <name> [path]`,
|
|
56
56
|
'',
|
|
57
57
|
'3. If nothing matches exactly → compose:',
|
|
58
|
-
` ${run}
|
|
59
|
-
` ${run}
|
|
60
|
-
` ${run}
|
|
58
|
+
` ${run} template <name> --skeleton # study a close page's layout`,
|
|
59
|
+
` ${run} template <BlockName> # drop in each block from the kit`,
|
|
60
|
+
` ${run} component <Name> # fill remaining gaps (read props)`,
|
|
61
61
|
'',
|
|
62
62
|
'4. Rules (keep it on-system):',
|
|
63
63
|
' - No <div>/raw HTML for layout — use VStack/HStack/Grid/Stack/Card etc.',
|
|
64
|
-
|
|
64
|
+
` - No style={{}} — use component props; design tokens via \`${run} docs tokens\`.`,
|
|
65
65
|
' - Wrap the app in <Theme theme={...}> and import core reset.css + astryx.css.',
|
|
66
66
|
'',
|
|
67
|
-
`Tip: \`${run}
|
|
68
|
-
`lookup of any component/doc/template, use \`${run}
|
|
67
|
+
`Tip: \`${run} build "<idea>"\` is the fastest way in. For a neutral`,
|
|
68
|
+
`lookup of any component/doc/template, use \`${run} search <query>\`.`,
|
|
69
69
|
'',
|
|
70
70
|
];
|
|
71
71
|
for (const l of lines) humanLog(l);
|
|
@@ -79,7 +79,7 @@ export function registerBuild(program) {
|
|
|
79
79
|
.option('--limit <n>', 'Max candidates to draw from (default 60)')
|
|
80
80
|
.option('--detail', 'Verbose output (include import paths and match reason)')
|
|
81
81
|
.action(async (query, options) => {
|
|
82
|
-
const run =
|
|
82
|
+
const run = getCliInvocation();
|
|
83
83
|
const json = program.opts().json || false;
|
|
84
84
|
|
|
85
85
|
// No query → print the playbook (the "how to build" skill).
|
|
@@ -115,7 +115,7 @@ export function registerBuild(program) {
|
|
|
115
115
|
if (results.length === 0) {
|
|
116
116
|
humanLog('');
|
|
117
117
|
humanLog(`No matches for "${q}".`);
|
|
118
|
-
humanLog(`Try a broader term, or browse: ${run}
|
|
118
|
+
humanLog(`Try a broader term, or browse: ${run} component --list`);
|
|
119
119
|
humanLog('');
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
@@ -138,7 +138,7 @@ export function registerBuild(program) {
|
|
|
138
138
|
humanLog('');
|
|
139
139
|
humanLog(` [${label}] ${display}`);
|
|
140
140
|
if (r.description) humanLog(` ${r.description}`);
|
|
141
|
-
humanLog(` → ${
|
|
141
|
+
humanLog(` → ${formatCliCommand(r.command)}`);
|
|
142
142
|
if (options.detail) {
|
|
143
143
|
if (r.import) humanLog(` import: ${r.import}`);
|
|
144
144
|
humanLog(` match: ${r.reason} (score ${r.score})`);
|
|
@@ -151,9 +151,9 @@ export function registerBuild(program) {
|
|
|
151
151
|
// START — the single recommended path.
|
|
152
152
|
humanLog('');
|
|
153
153
|
if (directMatch) {
|
|
154
|
-
humanLog(`START → Scaffold the \`${pages[0].name}\` page template, then adapt: ${run}
|
|
154
|
+
humanLog(`START → Scaffold the \`${pages[0].name}\` page template, then adapt: ${run} template ${pages[0].name} ./src/App.tsx`);
|
|
155
155
|
} else if (pages.length) {
|
|
156
|
-
humanLog(`START → No exact page template. Use \`${pages[0].name}\` as a layout reference (${run}
|
|
156
|
+
humanLog(`START → No exact page template. Use \`${pages[0].name}\` as a layout reference (${run} template ${pages[0].name} --skeleton) and compose the pieces below.`);
|
|
157
157
|
} else {
|
|
158
158
|
humanLog(`START → No page template fits. Frame with AppShell and compose the blocks + components below.`);
|
|
159
159
|
}
|
|
@@ -168,7 +168,7 @@ export function registerBuild(program) {
|
|
|
168
168
|
// FRAME — always (the page shell).
|
|
169
169
|
humanLog('');
|
|
170
170
|
humanLog(`FRAME — page shell (always): ${FRAME.join(', ')}`);
|
|
171
|
-
humanLog(` full-page → AppShell; or Layout + SideNav/TopNav. ${run}
|
|
171
|
+
humanLog(` full-page → AppShell; or Layout + SideNav/TopNav. ${run} component AppShell`);
|
|
172
172
|
|
|
173
173
|
// BLOCKS — idea-specific composed patterns.
|
|
174
174
|
if (blocks.length) {
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
formatBriefAll,
|
|
19
19
|
} from '../../lib/component-format.mjs';
|
|
20
20
|
import {resolveTheme} from '../../lib/resolve-theme.mjs';
|
|
21
|
-
import {
|
|
21
|
+
import {getCliInvocation} from '../../utils/package-manager.mjs';
|
|
22
22
|
import {jsonOut, humanLog} from '../../lib/json.mjs';
|
|
23
23
|
import {cliError} from '../../lib/cli-error.mjs';
|
|
24
24
|
import {ERROR_CODES} from '../../lib/error-codes.mjs';
|
|
@@ -39,7 +39,7 @@ export function registerComponent(program) {
|
|
|
39
39
|
.option('--blocks', 'List example blocks: showcase, examples, and related')
|
|
40
40
|
.option('--package <name>', 'Scope lookup to an external package (e.g. @acme/xds-widgets)')
|
|
41
41
|
.action(async (name, options) => {
|
|
42
|
-
const run =
|
|
42
|
+
const run = getCliInvocation();
|
|
43
43
|
const zh = program.opts().zh || false;
|
|
44
44
|
const dense = program.opts().dense || false;
|
|
45
45
|
const lang = program.opts().lang || null;
|
|
@@ -142,7 +142,7 @@ export function registerComponent(program) {
|
|
|
142
142
|
}
|
|
143
143
|
humanLog('');
|
|
144
144
|
humanLog(`Import from the path shown (e.g. import {Button} from '@astryxdesign/core/Button')`);
|
|
145
|
-
humanLog(`Usage: ${run}
|
|
145
|
+
humanLog(`Usage: ${run} component <name>`);
|
|
146
146
|
humanLog('');
|
|
147
147
|
}
|
|
148
148
|
break;
|
|
@@ -165,7 +165,7 @@ export function registerComponent(program) {
|
|
|
165
165
|
humanLog('');
|
|
166
166
|
}
|
|
167
167
|
humanLog(`Import from the path shown (e.g. import {Button} from '@astryxdesign/core/Button')`);
|
|
168
|
-
humanLog(`Usage: ${run}
|
|
168
|
+
humanLog(`Usage: ${run} component <name>`);
|
|
169
169
|
humanLog('');
|
|
170
170
|
break;
|
|
171
171
|
}
|
|
@@ -14,6 +14,7 @@ import {formatFull, formatBrief, formatCompact} from '../lib/component-format.mj
|
|
|
14
14
|
import {jsonOut, humanLog} from '../lib/json.mjs';
|
|
15
15
|
import {cliError} from '../lib/cli-error.mjs';
|
|
16
16
|
import {discover as discoverApi} from '../api/discover.mjs';
|
|
17
|
+
import {getCliInvocation} from '../utils/package-manager.mjs';
|
|
17
18
|
|
|
18
19
|
export function registerDiscover(program) {
|
|
19
20
|
program
|
|
@@ -25,6 +26,7 @@ export function registerDiscover(program) {
|
|
|
25
26
|
const json = program.opts().json || false;
|
|
26
27
|
const lang = program.opts().lang || null;
|
|
27
28
|
const zh = program.opts().zh || false;
|
|
29
|
+
const run = getCliInvocation();
|
|
28
30
|
|
|
29
31
|
let result;
|
|
30
32
|
try {
|
|
@@ -80,9 +82,9 @@ export function registerDiscover(program) {
|
|
|
80
82
|
humanLog('');
|
|
81
83
|
}
|
|
82
84
|
humanLog('Usage:');
|
|
83
|
-
humanLog(
|
|
84
|
-
humanLog(
|
|
85
|
-
humanLog(
|
|
85
|
+
humanLog(` ${run} discover <package> Browse a package`);
|
|
86
|
+
humanLog(` ${run} discover <package>/Component View component docs`);
|
|
87
|
+
humanLog(` ${run} discover <search> Search all packages`);
|
|
86
88
|
humanLog('');
|
|
87
89
|
}
|
|
88
90
|
break;
|
|
@@ -99,7 +101,7 @@ export function registerDiscover(program) {
|
|
|
99
101
|
humanLog('');
|
|
100
102
|
for (const comp of result.data.components) humanLog(' ' + comp);
|
|
101
103
|
humanLog('');
|
|
102
|
-
humanLog(
|
|
104
|
+
humanLog(`Usage: ${run} discover ` + result.data.name + '/<ComponentName>');
|
|
103
105
|
humanLog('');
|
|
104
106
|
break;
|
|
105
107
|
}
|
|
@@ -122,7 +124,7 @@ export function registerDiscover(program) {
|
|
|
122
124
|
humanLog('Found ' + result.data.matches.length + ' matches for "' + result.data.query + '":');
|
|
123
125
|
humanLog('');
|
|
124
126
|
for (const m of result.data.matches) {
|
|
125
|
-
humanLog(
|
|
127
|
+
humanLog(` ${run} discover ` + m.package + '/' + m.component);
|
|
126
128
|
}
|
|
127
129
|
humanLog('');
|
|
128
130
|
break;
|
package/src/commands/docs.mjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* astryx docs <topic> <section> Print one section
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import {getCliInvocation} from '../utils/package-manager.mjs';
|
|
16
16
|
import {jsonOut, humanLog} from '../lib/json.mjs';
|
|
17
17
|
import {cliError} from '../lib/cli-error.mjs';
|
|
18
18
|
import {docs as docsApi} from '../api/docs.mjs';
|
|
@@ -105,7 +105,7 @@ export function registerDocs(program) {
|
|
|
105
105
|
.command('docs [topic] [section]')
|
|
106
106
|
.description('Print reference docs')
|
|
107
107
|
.action(async (topic, section) => {
|
|
108
|
-
const run =
|
|
108
|
+
const run = getCliInvocation();
|
|
109
109
|
const lang = program.opts().lang || null;
|
|
110
110
|
const zh = program.opts().zh || false;
|
|
111
111
|
const dense = program.opts().dense || false;
|
|
@@ -130,8 +130,8 @@ export function registerDocs(program) {
|
|
|
130
130
|
for (const entry of result.data) {
|
|
131
131
|
humanLog(` ${entry.topic.padEnd(14)} ${entry.description}`);
|
|
132
132
|
}
|
|
133
|
-
humanLog(`\nUsage: ${run}
|
|
134
|
-
humanLog(` ${run}
|
|
133
|
+
humanLog(`\nUsage: ${run} docs <topic>`);
|
|
134
|
+
humanLog(` ${run} docs <topic> <section>\n`);
|
|
135
135
|
break;
|
|
136
136
|
}
|
|
137
137
|
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
formatHookBrief,
|
|
13
13
|
formatHookParams,
|
|
14
14
|
} from '../../lib/hook-format.mjs';
|
|
15
|
-
import {
|
|
15
|
+
import {getCliInvocation} from '../../utils/package-manager.mjs';
|
|
16
16
|
import {jsonOut, humanLog} from '../../lib/json.mjs';
|
|
17
17
|
import {cliError} from '../../lib/cli-error.mjs';
|
|
18
18
|
import {ERROR_CODES} from '../../lib/error-codes.mjs';
|
|
@@ -27,7 +27,7 @@ export function registerHook(program) {
|
|
|
27
27
|
.option('--category <category>', 'List hooks in a specific category')
|
|
28
28
|
.option('--params', 'Print only the parameters table')
|
|
29
29
|
.action(async (name, options) => {
|
|
30
|
-
const run =
|
|
30
|
+
const run = getCliInvocation();
|
|
31
31
|
const zh = program.opts().zh || false;
|
|
32
32
|
const lang = program.opts().lang || null;
|
|
33
33
|
const detailSource = program.getOptionValueSource('detail');
|
|
@@ -76,7 +76,7 @@ export function registerHook(program) {
|
|
|
76
76
|
for (const h of hookNames) humanLog(` ${h}`);
|
|
77
77
|
}
|
|
78
78
|
humanLog('');
|
|
79
|
-
humanLog(`Usage: ${run}
|
|
79
|
+
humanLog(`Usage: ${run} hook <name>`);
|
|
80
80
|
humanLog('');
|
|
81
81
|
}
|
|
82
82
|
break;
|
|
@@ -93,7 +93,7 @@ export function registerHook(program) {
|
|
|
93
93
|
}
|
|
94
94
|
humanLog('');
|
|
95
95
|
}
|
|
96
|
-
humanLog(`Usage: ${run}
|
|
96
|
+
humanLog(`Usage: ${run} hook <name>`);
|
|
97
97
|
humanLog('');
|
|
98
98
|
break;
|
|
99
99
|
}
|
package/src/commands/init.mjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file init command —
|
|
4
|
+
* @file init command — non-interactive setup + feature installer
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* `astryx init` is non-interactive by default: it installs the AGENTS.md/
|
|
7
|
+
* CLAUDE.md cheat sheet with NO prompts, so it behaves identically for humans,
|
|
8
|
+
* AI agents, CI, and piped I/O — it never hangs or errors on a missing TTY.
|
|
9
|
+
* Non-interactive feature install: `astryx init --features agents,theme,template`
|
|
8
10
|
* Re-runnable: safe to run multiple times, idempotent
|
|
9
11
|
*
|
|
10
12
|
* Features:
|
|
11
13
|
* agents — Install AGENTS.md/CLAUDE.md cheat sheet for AI coding agents
|
|
12
|
-
* theme —
|
|
14
|
+
* theme — Point to the theme workflow (`astryx theme`)
|
|
13
15
|
* template — Copy a starter page template
|
|
14
16
|
*/
|
|
15
17
|
|
|
16
|
-
import * as p from '@clack/prompts';
|
|
17
18
|
import * as path from 'node:path';
|
|
18
19
|
import * as fs from 'node:fs';
|
|
19
20
|
import {CLI_ROOT} from '../utils/paths.mjs';
|
|
20
21
|
import {PathSafetyError} from '../utils/path-safety.mjs';
|
|
21
|
-
import {
|
|
22
|
+
import {getCliInvocation} from '../utils/package-manager.mjs';
|
|
22
23
|
import {installAgentDocs, removeAgentDocs} from './agent-docs.mjs';
|
|
23
24
|
import {listTemplates} from './template.mjs';
|
|
24
25
|
import {humanLog} from '../lib/json.mjs';
|
|
25
26
|
import {cliError} from '../lib/cli-error.mjs';
|
|
26
27
|
import {ERROR_CODES} from '../lib/error-codes.mjs';
|
|
27
|
-
import {requireInteractive} from '../utils/interactive.mjs';
|
|
28
28
|
|
|
29
29
|
const VALID_FEATURES = ['agents', 'theme', 'template'];
|
|
30
|
-
const run =
|
|
30
|
+
const run = getCliInvocation();
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Build the "Next steps" lines printed at the end of `astryx init`.
|
|
@@ -40,10 +40,10 @@ const run = getRunPrefix();
|
|
|
40
40
|
*
|
|
41
41
|
* Exported for testing.
|
|
42
42
|
*
|
|
43
|
-
* @param {string}
|
|
43
|
+
* @param {string} invocation install-aware CLI invocation stem (e.g. `npx astryx`, `pnpm exec astryx`, or `npx @astryxdesign/cli` for one-off runs)
|
|
44
44
|
* @returns {string[]} ordered list of human-facing lines
|
|
45
45
|
*/
|
|
46
|
-
export function getNextSteps(
|
|
46
|
+
export function getNextSteps(invocation) {
|
|
47
47
|
return [
|
|
48
48
|
'',
|
|
49
49
|
' Next steps:',
|
|
@@ -54,23 +54,15 @@ export function getNextSteps(runPrefix) {
|
|
|
54
54
|
" import { neutralTheme } from '@astryxdesign/theme-neutral/built'",
|
|
55
55
|
" import '@astryxdesign/theme-neutral/theme.css'",
|
|
56
56
|
' <Theme theme={neutralTheme}>...</Theme>',
|
|
57
|
-
` For custom themes, run \`${
|
|
58
|
-
` 4. ${
|
|
57
|
+
` For custom themes, run \`${invocation} theme build <file>\` to generate the built artifacts.`,
|
|
58
|
+
` 4. ${invocation} --help for all commands`,
|
|
59
59
|
'',
|
|
60
60
|
];
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
function isCancel(value) {
|
|
64
|
-
if (p.isCancel(value)) {
|
|
65
|
-
p.cancel('Setup cancelled.');
|
|
66
|
-
process.exit(0);
|
|
67
|
-
}
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
63
|
// ─── Feature: agents ─────────────────────────────────────────────────────────
|
|
72
64
|
|
|
73
|
-
function runAgents(targetDir, {
|
|
65
|
+
function runAgents(targetDir, {agent, agentDocsPath} = {}) {
|
|
74
66
|
try {
|
|
75
67
|
const paths = agentDocsPath
|
|
76
68
|
? Array.isArray(agentDocsPath)
|
|
@@ -79,114 +71,55 @@ function runAgents(targetDir, {interactive = true, agent, agentDocsPath} = {}) {
|
|
|
79
71
|
: undefined;
|
|
80
72
|
const written = installAgentDocs(targetDir, {agent, paths});
|
|
81
73
|
const summary = written.join(', ');
|
|
82
|
-
|
|
83
|
-
p.log.success(`AI agent docs installed → ${summary}`);
|
|
84
|
-
} else {
|
|
85
|
-
humanLog(`✓ AI agent docs installed → ${summary}`);
|
|
86
|
-
}
|
|
74
|
+
humanLog(`✓ AI agent docs installed → ${summary}`);
|
|
87
75
|
} catch (err) {
|
|
88
76
|
// PathSafetyError carries a precise, user-actionable message —
|
|
89
77
|
// surface it instead of the generic "could not install" warning so
|
|
90
78
|
// misconfigured --agent-docs-path values aren't silently swallowed.
|
|
91
79
|
if (err instanceof PathSafetyError) {
|
|
92
|
-
|
|
93
|
-
if (interactive) {
|
|
94
|
-
p.log.error(msg);
|
|
95
|
-
} else {
|
|
96
|
-
console.error(msg);
|
|
97
|
-
}
|
|
80
|
+
console.error(`Error: ${err.message}`);
|
|
98
81
|
process.exitCode = 1;
|
|
99
82
|
return;
|
|
100
83
|
}
|
|
101
|
-
|
|
102
|
-
if (interactive) {
|
|
103
|
-
p.log.warning(msg);
|
|
104
|
-
} else {
|
|
105
|
-
console.error(msg);
|
|
106
|
-
}
|
|
84
|
+
console.error(`Could not install agent docs. Try again with \`${run} init --features agents\`.`);
|
|
107
85
|
}
|
|
108
86
|
}
|
|
109
87
|
|
|
110
88
|
// ─── Feature: theme ──────────────────────────────────────────────────────────
|
|
111
89
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
humanLog(`✓ Theme scaffolding requires interactive mode. Run \`${run} astryx theme\` instead.`);
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
p.note(
|
|
119
|
-
'Create a custom theme with your brand colors.\n' +
|
|
120
|
-
`Run \`${run} astryx theme\` for the full theme wizard.\n` +
|
|
121
|
-
`Run \`${run} astryx theme --list\` to see existing themes.`,
|
|
122
|
-
'Themes',
|
|
123
|
-
);
|
|
90
|
+
function runTheme() {
|
|
91
|
+
humanLog(`✓ For a custom theme, run \`${run} theme\` (browse) or \`${run} theme add <slug>\` (scaffold).`);
|
|
124
92
|
}
|
|
125
93
|
|
|
126
94
|
// ─── Feature: template ───────────────────────────────────────────────────────
|
|
127
95
|
|
|
128
|
-
|
|
96
|
+
function runTemplate(targetDir, {templateName} = {}) {
|
|
129
97
|
const templates = listTemplates();
|
|
130
98
|
if (templates.length === 0) return;
|
|
131
99
|
|
|
132
|
-
if (!
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
humanLog('');
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (!templates.includes(templateName)) {
|
|
147
|
-
cliError(`Unknown template "${templateName}". Available: ${templates.join(', ')}`, {code: ERROR_CODES.ERR_UNKNOWN_TEMPLATE});
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const outputDir = path.resolve(targetDir, `./src/pages/${templateName}`);
|
|
152
|
-
const srcPath = path.join(CLI_ROOT, 'templates', 'pages', templateName, 'page.tsx');
|
|
153
|
-
fs.mkdirSync(outputDir, {recursive: true});
|
|
154
|
-
fs.copyFileSync(srcPath, path.join(outputDir, 'page.tsx'));
|
|
155
|
-
humanLog(`✓ Template created at ${path.relative(targetDir, outputDir)}/page.tsx`);
|
|
100
|
+
if (!templateName) {
|
|
101
|
+
// Point agents at the build workflow rather than dumping page-template
|
|
102
|
+
// names — `build` surfaces pages AND blocks AND components for an idea,
|
|
103
|
+
// and `build` with no args is the full how-to-build playbook.
|
|
104
|
+
humanLog('✓ To build UI, use these commands:');
|
|
105
|
+
humanLog('');
|
|
106
|
+
humanLog(` ${run} build "<what you're building>" build a page — kit: closest template + blocks + components`);
|
|
107
|
+
humanLog(` ${run} build the how-to-build workflow (read this first)`);
|
|
108
|
+
humanLog(` ${run} search <query> find anything — components, docs, templates, blocks`);
|
|
109
|
+
humanLog('');
|
|
156
110
|
return;
|
|
157
111
|
}
|
|
158
112
|
|
|
159
|
-
|
|
160
|
-
{
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
{value: 'login', label: 'Login Page — Auth form with inputs'},
|
|
164
|
-
];
|
|
165
|
-
|
|
166
|
-
const templateChoice = isCancel(
|
|
167
|
-
await p.select({
|
|
168
|
-
message: 'Start with a page template?',
|
|
169
|
-
options: TEMPLATE_OPTIONS,
|
|
170
|
-
}),
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
if (templateChoice === 'skip') return;
|
|
174
|
-
|
|
175
|
-
const targetPath = isCancel(
|
|
176
|
-
await p.text({
|
|
177
|
-
message: 'Where should the template be created?',
|
|
178
|
-
initialValue: `./src/pages/${templateChoice}`,
|
|
179
|
-
placeholder: `./src/pages/${templateChoice}`,
|
|
180
|
-
}),
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
const outputDir = path.resolve(targetDir, targetPath);
|
|
184
|
-
const srcPath = path.join(CLI_ROOT, 'templates', 'pages', templateChoice, 'page.tsx');
|
|
113
|
+
if (!templates.includes(templateName)) {
|
|
114
|
+
cliError(`Unknown template "${templateName}". Available: ${templates.join(', ')}`, {code: ERROR_CODES.ERR_UNKNOWN_TEMPLATE});
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
185
117
|
|
|
118
|
+
const outputDir = path.resolve(targetDir, `./src/pages/${templateName}`);
|
|
119
|
+
const srcPath = path.join(CLI_ROOT, 'templates', 'pages', templateName, 'page.tsx');
|
|
186
120
|
fs.mkdirSync(outputDir, {recursive: true});
|
|
187
121
|
fs.copyFileSync(srcPath, path.join(outputDir, 'page.tsx'));
|
|
188
|
-
|
|
189
|
-
p.log.success(`Template created at ${path.relative(targetDir, outputDir)}/page.tsx`);
|
|
122
|
+
humanLog(`✓ Template created at ${path.relative(targetDir, outputDir)}/page.tsx`);
|
|
190
123
|
}
|
|
191
124
|
|
|
192
125
|
// ─── Command ─────────────────────────────────────────────────────────────────
|
|
@@ -200,7 +133,7 @@ export function registerInit(program) {
|
|
|
200
133
|
.option('--remove-agents', 'Remove AI agent docs from all agent doc files')
|
|
201
134
|
.option('--agent <tool>', 'Target AI tool for agent docs: claude, cursor, codex, hermes, all')
|
|
202
135
|
.option('--agent-docs-path <path...>', 'Explicit file path(s) for agent docs')
|
|
203
|
-
.action(
|
|
136
|
+
.action((options) => {
|
|
204
137
|
const targetDir = process.cwd();
|
|
205
138
|
|
|
206
139
|
// Remove mode
|
|
@@ -224,62 +157,25 @@ export function registerInit(program) {
|
|
|
224
157
|
|
|
225
158
|
for (const feature of features) {
|
|
226
159
|
if (feature === 'agents') runAgents(targetDir, {
|
|
227
|
-
interactive: false,
|
|
228
160
|
agent: options.agent,
|
|
229
161
|
agentDocsPath: options.agentDocsPath,
|
|
230
162
|
});
|
|
231
|
-
if (feature === 'theme')
|
|
232
|
-
if (feature === 'template')
|
|
163
|
+
if (feature === 'theme') runTheme();
|
|
164
|
+
if (feature === 'template') runTemplate(targetDir, {});
|
|
233
165
|
}
|
|
234
166
|
return;
|
|
235
167
|
}
|
|
236
168
|
|
|
237
|
-
//
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
hint: `\`${run} astryx init --all\` or \`--features agents,theme,template\``,
|
|
169
|
+
// No flags: TTY-free default. `astryx init` installs the AI agent cheat
|
|
170
|
+
// sheet with NO prompts, so it behaves identically for humans, agents, CI,
|
|
171
|
+
// and piped I/O — it never hangs or errors on a missing TTY. (A guided
|
|
172
|
+
// `--interactive` setup may return later as an explicit opt-in.)
|
|
173
|
+
runAgents(targetDir, {
|
|
174
|
+
agent: options.agent,
|
|
175
|
+
agentDocsPath: options.agentDocsPath,
|
|
245
176
|
});
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
p.note(
|
|
250
|
-
'A design system for building internal tools\nwith 300+ React components.',
|
|
251
|
-
'About',
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
// Feature: agents
|
|
255
|
-
const shouldInstallAgents = isCancel(
|
|
256
|
-
await p.confirm({
|
|
257
|
-
message: 'Install AI agent support? (adds a design system cheat sheet to AGENTS.md)',
|
|
258
|
-
initialValue: true,
|
|
259
|
-
}),
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
if (shouldInstallAgents) {
|
|
263
|
-
const s = p.spinner();
|
|
264
|
-
s.start('Installing agent docs');
|
|
265
|
-
runAgents(targetDir);
|
|
266
|
-
s.stop('Done');
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// Feature: swizzle awareness
|
|
270
|
-
p.note(
|
|
271
|
-
`You can customize any component with:\n ${run} astryx swizzle Button\n ${run} astryx swizzle --list`,
|
|
272
|
-
'Component Customization',
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
// Feature: template
|
|
276
|
-
await runTemplate(targetDir);
|
|
277
|
-
|
|
278
|
-
// Feature: theme awareness
|
|
279
|
-
await runTheme();
|
|
280
|
-
|
|
281
|
-
// Outro
|
|
282
|
-
p.outro('Design system initialized!');
|
|
177
|
+
humanLog('');
|
|
178
|
+
humanLog(` Tip: \`${run} init --all\` also points you to the theme and page-building workflows.`);
|
|
283
179
|
|
|
284
180
|
for (const line of getNextSteps(run)) {
|
|
285
181
|
humanLog(line);
|
|
@@ -23,7 +23,7 @@ import {describe, it, expect} from 'vitest';
|
|
|
23
23
|
import {getNextSteps} from './init.mjs';
|
|
24
24
|
|
|
25
25
|
describe('init Next steps theme guidance', () => {
|
|
26
|
-
const text = getNextSteps('npx').join('\n');
|
|
26
|
+
const text = getNextSteps('npx astryx').join('\n');
|
|
27
27
|
|
|
28
28
|
it('mentions the base CSS imports so the app is not left unstyled', () => {
|
|
29
29
|
expect(text).toContain("'@astryxdesign/core/reset.css'");
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file Subprocess no-hang tests for
|
|
4
|
+
* @file Subprocess no-hang tests for `astryx init`.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* These tests spawn the CLI
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* status null) — so asserting `signal === null && status === 1` proves the
|
|
12
|
-
* process exited cleanly rather than hanging.
|
|
6
|
+
* TTY was removed from the CLI: `init` is non-interactive by default and must
|
|
7
|
+
* run cleanly (exit 0, writing the agent cheat sheet) instead of hanging on a
|
|
8
|
+
* prompt. These tests spawn the CLI with stdin/stdout NOT a TTY (the CI / piped
|
|
9
|
+
* / agent condition). A hang would show as signal SIGTERM + status null; we
|
|
10
|
+
* assert `signal === null && status === 0` to prove it exits cleanly and works.
|
|
13
11
|
*/
|
|
14
12
|
|
|
15
13
|
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
|
|
@@ -42,25 +40,24 @@ afterEach(() => {
|
|
|
42
40
|
fs.rmSync(tmpDir, {recursive: true, force: true});
|
|
43
41
|
});
|
|
44
42
|
|
|
45
|
-
describe('init non-interactive
|
|
46
|
-
it('
|
|
43
|
+
describe('init is non-interactive by default (no TTY needed)', () => {
|
|
44
|
+
it('runs cleanly (exit 0, no hang) and writes agent docs', () => {
|
|
47
45
|
const r = runCli(['init']);
|
|
48
|
-
expect(r.signal).toBeNull();
|
|
49
|
-
expect(r.status).toBe(
|
|
50
|
-
expect(fs.readdirSync(tmpDir)).
|
|
46
|
+
expect(r.signal).toBeNull(); // did not hang
|
|
47
|
+
expect(r.status).toBe(0); // succeeded without a TTY
|
|
48
|
+
expect(fs.readdirSync(tmpDir).length).toBeGreaterThan(0); // wrote the cheat sheet
|
|
51
49
|
});
|
|
52
50
|
|
|
53
|
-
it('
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
expect(
|
|
59
|
-
expect(
|
|
60
|
-
expect(out).toMatch(/--features/);
|
|
51
|
+
it('writes an agent-doc file containing the ASTRYX cheat-sheet marker', () => {
|
|
52
|
+
runCli(['init']);
|
|
53
|
+
// init injects into AGENTS.md/CLAUDE.md if present, else creates .claude/CLAUDE.md
|
|
54
|
+
const candidates = ['AGENTS.md', 'CLAUDE.md', '.cursorrules', path.join('.claude', 'CLAUDE.md')];
|
|
55
|
+
const doc = candidates.find(f => fs.existsSync(path.join(tmpDir, f)));
|
|
56
|
+
expect(doc).toBeTruthy();
|
|
57
|
+
expect(fs.readFileSync(path.join(tmpDir, doc), 'utf8')).toMatch(/ASTRYX:START/);
|
|
61
58
|
});
|
|
62
59
|
|
|
63
|
-
it('still runs --features agents non-interactively
|
|
60
|
+
it('still runs --features agents non-interactively', () => {
|
|
64
61
|
const r = runCli(['init', '--features', 'agents']);
|
|
65
62
|
expect(r.signal).toBeNull();
|
|
66
63
|
expect(r.status).toBe(0);
|
|
@@ -45,7 +45,7 @@ function runCli(args, {cwd} = {}) {
|
|
|
45
45
|
|
|
46
46
|
function parseJson(stdout) {
|
|
47
47
|
// CLI emits a single JSON document. If anything else snuck onto stdout
|
|
48
|
-
// (
|
|
48
|
+
// (log output, console.log strings, etc.) JSON.parse will throw —
|
|
49
49
|
// which is exactly the failure mode we want to catch in tests.
|
|
50
50
|
return JSON.parse(stdout);
|
|
51
51
|
}
|
package/src/commands/layout.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import {layoutExpand, layoutCheck, layoutGrammar} from '../api/layout.mjs';
|
|
|
20
20
|
/** Resolve the expression from arg, --file, or stdin ('-'). */
|
|
21
21
|
async function readExpression(expr, options) {
|
|
22
22
|
if (options.file) return fs.readFileSync(options.file, 'utf-8');
|
|
23
|
-
if (expr === '-'
|
|
23
|
+
if (expr === '-') {
|
|
24
24
|
const chunks = [];
|
|
25
25
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
26
26
|
return Buffer.concat(chunks).toString('utf-8');
|