astralis-cli 0.3.0 → 0.5.0

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +167 -0
  2. package/LICENSE +21 -0
  3. package/README.md +179 -29
  4. package/package.json +29 -10
  5. package/src/commands/add.mjs +48 -71
  6. package/src/commands/connect-mcp.mjs +66 -27
  7. package/src/commands/create.mjs +133 -39
  8. package/src/commands/init.mjs +125 -28
  9. package/src/commands/report.mjs +257 -0
  10. package/src/commands/theme.mjs +100 -82
  11. package/src/commands/validate.mjs +101 -0
  12. package/src/index.mjs +26 -47
  13. package/src/lib/args.mjs +135 -0
  14. package/src/lib/aria.mjs +40 -0
  15. package/src/lib/children-rule.mjs +23 -0
  16. package/src/lib/ci-setup.mjs +78 -0
  17. package/src/lib/ci.mjs +155 -0
  18. package/src/lib/commands.mjs +214 -0
  19. package/src/lib/css-value.mjs +141 -0
  20. package/src/lib/devtools-setup.mjs +142 -0
  21. package/src/lib/edits.mjs +206 -26
  22. package/src/lib/github-annotations.mjs +26 -0
  23. package/src/lib/github.d.mts +72 -0
  24. package/src/lib/github.mjs +339 -0
  25. package/src/lib/library.mjs +40 -0
  26. package/src/lib/menu.mjs +59 -0
  27. package/src/lib/prompt-child.mjs +97 -0
  28. package/src/lib/registry.mjs +37 -4
  29. package/src/lib/report-tree.mjs +134 -0
  30. package/src/lib/run.mjs +39 -0
  31. package/src/lib/snapshot.d.mts +65 -0
  32. package/src/lib/snapshot.mjs +371 -0
  33. package/src/lib/source-files.mjs +29 -0
  34. package/src/lib/spec-load.mjs +32 -0
  35. package/src/lib/spec-resolve.mjs +20 -0
  36. package/src/lib/starter.mjs +219 -0
  37. package/src/lib/suggest.mjs +32 -0
  38. package/src/lib/ui.mjs +85 -51
  39. package/src/lib/validate-core.d.mts +48 -0
  40. package/src/lib/validate-core.mjs +652 -0
  41. package/src/lib/validate.d.mts +33 -0
  42. package/src/lib/validate.mjs +8 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,167 @@
1
+ # Changelog
2
+
3
+ All notable changes to `astralis-cli`. Under 0.x, a minor version may contain
4
+ breaking changes; a patch never does.
5
+
6
+ Versions marked **internal** were set in the repository but never published to
7
+ npm. Their changes reached npm in the next published version.
8
+
9
+ ## 0.5.0 (2026-10-01)
10
+
11
+ The first npm release since 0.4.0. It includes the internal versions 0.4.1 to
12
+ 0.4.4 below. Requires Node `^22.18` or `>=24.11`.
13
+
14
+ ### Added
15
+
16
+ - **`astralis report <files...>`** builds an issue snapshot of the Astralis
17
+ components in the files you name (their props, parts and the validator's
18
+ findings, with your text replaced by placeholders), prints the exact JSON,
19
+ and, only when you confirm, opens it as a GitHub issue from your own
20
+ account, signing you in with a code the first time. `--out` writes it to a
21
+ file instead and sends nothing; `--sign-out` forgets the sign-in. It looks
22
+ for an issue that already reports the same problem first and offers to add
23
+ your report to it (`--add-to <issue>`, or `--new` to skip the check).
24
+ `--link` prints GitHub's own new-issue form, filled in, with no sign-in.
25
+ - **`astralis-cli/github`**: the GitHub sign-in, the saved token and the
26
+ issues, shared with the Astralis DevTools.
27
+ - **`astralis init --ci`** pins astralis-cli, adds a `validate` script and
28
+ writes a GitHub Actions workflow that checks every pull request.
29
+ `validate --format github` annotates the pull request's lines.
30
+ - **`astralis init --devtools`** installs the Astralis DevTools and wires them
31
+ into the root layout or `vite.config`. `create` adds them by default.
32
+ - **A new look.** `create` and `init` open with a one-line header (name, version, what is
33
+ happening), and choices are arrow-key menus with a hint under each option (numbers work
34
+ too). Piped and CI runs keep the plain numbered prompts and no banner.
35
+ - **One command table.** Every command has `--help`; `-y`/`--yes` takes the
36
+ default answer to every prompt; `--debug` prints a stack trace; a mistyped
37
+ command suggests the right one; and errors never print a raw stack trace.
38
+ - The validator judges imports against the library's export list (so
39
+ importing a type or `COLOR_SCHEMES` is no longer reported), skips type-only
40
+ imports, and reports a component left without the children its type
41
+ requires.
42
+ - Type declarations ship for the `validate` and `validate-core` exports.
43
+ - A finding on a component names it, and the attribute and literal value it
44
+ is on (`component`, `prop`, `value`), so tools can point at the component on
45
+ the page.
46
+ - A style prop a component does not take, such as `p` on Text or `bg` on Card,
47
+ is an error (`unknown-style-prop`): it reached the HTML as a stray attribute
48
+ and changed nothing. This replaces the `paint-on-recipe` warning.
49
+ - Two new warnings: a `Flex direction="column"` is a `VStack`
50
+ (`prefer-vstack`), and a Button that shows only an icon needs an
51
+ `aria-label` (`icon-button-label`).
52
+
53
+ ### Changed
54
+
55
+ - `theme` renders with the project's own installed astralis-ui and checks
56
+ contrast before writing, so `--strict-contrast` fails before a bad theme is
57
+ written.
58
+ - Scaffolders and installs are spawned with argument arrays, and `create`
59
+ passes its package manager and `--yes` on to `init` and the scaffolder.
60
+ - Entry-file imports are parsed with Babel: a new import goes after
61
+ multi-line imports, merges into an existing named import, and the CLI never
62
+ writes code it cannot parse.
63
+ - `connect-mcp` adds the server safely on Windows for Claude Code and Codex,
64
+ keeps numbered backups of config files it changes, and no longer creates
65
+ config folders for clients that are not installed.
66
+
67
+ ### Fixed
68
+
69
+ - `add` refuses block ids and registry file paths that could write outside
70
+ the project, and gives up on the registry after 10 seconds.
71
+
72
+ ## 0.4.4 (2026-08-28, internal)
73
+
74
+ ### Added
75
+
76
+ - The `astralis-cli/validate-core` export: the validator without Node APIs,
77
+ for use in a browser.
78
+
79
+ ## 0.4.3 (2026-08-24, internal)
80
+
81
+ ### Added
82
+
83
+ - `astralis theme` checks every generated theme against the library's
84
+ contrast contracts and names each failing pairing with its colours and
85
+ ratio. `--strict-contrast` makes a failure a non-zero exit.
86
+
87
+ ## 0.4.2 (2026-08-23, internal)
88
+
89
+ ### Added
90
+
91
+ - `astralis validate` accepts the container-query breakpoint keys (`@sm` to
92
+ `@xl`), with did-you-mean suggestions.
93
+
94
+ ## 0.4.1 (2026-08-21, internal)
95
+
96
+ ### Added
97
+
98
+ - **`astralis validate [paths...]`** checks TSX and JSX against the installed
99
+ astralis-ui's `system-spec.json`: unknown components and parts, values
100
+ outside a prop's set (with suggestions), CSS values that cannot be valid,
101
+ props a component excludes, compound anatomy, and common accessibility
102
+ mistakes. `--json` for CI, `--strict-tokens` to flag raw colours.
103
+ - The `astralis-cli/validate` export: the same validator for scripts and the
104
+ MCP server.
105
+
106
+ ## 0.4.0 (2026-08-10)
107
+
108
+ ### Changed
109
+
110
+ - `astralis theme` writes `src/astralis-theme.css` when the project has a
111
+ `src/` folder, and imports it into the entry point after
112
+ `astralis-ui/styles.css`. `--no-import` leaves the entry point alone.
113
+
114
+ ### Added
115
+
116
+ - `create` replaces the scaffolder's demo page with a welcome screen built
117
+ from Astralis, so working setup is visible on the first `dev`.
118
+ `--no-starter` opts out.
119
+
120
+ ### Fixed
121
+
122
+ - Prompts run in a child process, so an interactive scaffolder started by
123
+ `create` receives keystrokes (on Windows it never did).
124
+ - `create` no longer lets create-vite start a dev server that never exits and
125
+ strands the setup step, and only offers React templates.
126
+ - `init` reports only what it actually changed.
127
+
128
+ ## 0.3.0 (2026-08-08)
129
+
130
+ ### Added
131
+
132
+ - **`astralis add <block...>`** copies a block's source into the project,
133
+ with `--list`, `--dir`, `--overwrite`, `--dry-run` and `--registry`. Blocks
134
+ go to `--dir`, then `blocksDir` in `astralis.json`, then
135
+ `[src/]components/blocks`.
136
+
137
+ ### Fixed
138
+
139
+ - Failures set the exit code instead of exiting abruptly, which on Windows
140
+ reported 127 instead of 1 after any network request.
141
+
142
+ ## 0.2.1 (2026-07-24)
143
+
144
+ ### Changed
145
+
146
+ - `astralis mcp` is renamed **`astralis connect-mcp`** and becomes a guided
147
+ flow that sets up the MCP server for Claude Code, Codex, Cursor, Claude
148
+ Desktop or Antigravity.
149
+
150
+ ## 0.2.0 (2026-07-23)
151
+
152
+ ### Added
153
+
154
+ - `astralis theme` takes the whole theme seed: brand, neutral and status
155
+ colours (`--gray`, `--error`, `--warning`, `--success`, `--info`), fonts,
156
+ radius and type scale.
157
+
158
+ ## 0.1.0 (2026-07-16)
159
+
160
+ The first release.
161
+
162
+ - `astralis create <name>` scaffolds a Next.js or Vite project and wires
163
+ Astralis into it.
164
+ - `astralis init` wires astralis-ui into an existing project.
165
+ - `astralis theme <hex>` turns a brand colour into a static theme stylesheet.
166
+ - `astralis mcp` prints the MCP server configuration for AI clients, and
167
+ `--write` adds it to Claude Desktop's config.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Paul Andrew
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,66 +1,216 @@
1
1
  # astralis-cli
2
2
 
3
- Setup and tooling CLI for [Astralis UI](https://astralis-zeta.vercel.app).
3
+ Setup and tooling CLI for [Astralis UI](https://astralis-ui.com): start
4
+ a project, wire the library into an existing one, copy in blocks, generate a
5
+ static theme, check code against the design system, and connect AI agents.
4
6
 
5
7
  ```bash
6
8
  npx astralis-cli <command>
7
9
  # or: npm i -g astralis-cli && astralis <command>
8
10
  ```
9
11
 
12
+ Needs Node `^22.18` or `>=24.11`. Run `astralis <command> --help` for any
13
+ command's options. Full guide: <https://astralis-ui.com/docs/cli>.
14
+
10
15
  ## Commands
11
16
 
17
+ <!-- reference:start (generated by scripts/reference.mjs; edit src/lib/commands.mjs) -->
18
+
12
19
  ### `astralis create <name>`
13
20
 
14
- Scaffolds a brand-new project and wires Astralis into it. The official
15
- scaffolder runs with its own prompts — TypeScript, ESLint, and friends stay
16
- your call — then `init` runs on the result. Extra args pass straight through
17
- to the scaffolder.
21
+ Scaffold a new project with create-next-app or create-vite and wire Astralis into it.
22
+
23
+ | Option | |
24
+ | --- | --- |
25
+ | `--framework <next\|vite>` | Skip the framework prompt. |
26
+ | `--no-starter` | Keep the scaffolder's demo page instead of the Astralis welcome screen. |
27
+ | `--no-devtools` | Leave out the Astralis DevTools overlay, which new projects get in development. |
28
+
29
+ Any other argument passes straight to the scaffolder.
18
30
 
19
31
  ```bash
20
- npm create astralis my-app # interactive
21
- npx astralis-cli create my-app --framework vite --template react-ts
32
+ astralis create my-app
33
+ astralis create my-app --framework vite --template react
22
34
  ```
23
35
 
24
36
  ### `astralis init`
25
37
 
26
- Wires Astralis UI into a Next.js or Vite project: installs the package,
27
- adds the stylesheet import, wraps your app in `AstralisProvider`, and (Next)
28
- injects the anti-flash dark-mode script. Idempotent — safe to run twice.
38
+ Wire astralis-ui into an existing Next.js or React + Vite project.
39
+
40
+ | Option | |
41
+ | --- | --- |
42
+ | `--dry-run` | Show the changes without writing anything. |
43
+ | `--ci` | Also check every pull request: pin astralis-cli, add a validate script and write a GitHub Actions workflow. |
44
+ | `--force` | With --ci, replace an existing astralis-validate.yml. |
45
+ | `--devtools` | Also add the Astralis DevTools overlay (development only): install astralis-devtools and wire it into the root layout or vite.config. |
46
+
47
+ init --ci is safe to re-run: it adds only what is missing and never replaces a workflow without --force.
48
+
49
+ init --devtools is safe to re-run too; production builds contain none of the DevTools.
50
+
51
+ ```bash
52
+ astralis init
53
+ astralis init --dry-run
54
+ astralis init --ci
55
+ astralis init --devtools
56
+ ```
57
+
58
+ ### `astralis add <block...>`
59
+
60
+ Copy a block's source into this project.
61
+
62
+ | Option | |
63
+ | --- | --- |
64
+ | `--list` | Print every available block, by category, and exit. |
65
+ | `--dir <path>` | Where to write. Default: src/components/blocks, or components/blocks without a src/. |
66
+ | `--overwrite` | Replace existing files without asking. |
67
+ | `--dry-run` | Show what would be written; write nothing. |
68
+ | `--registry <url>` | Read blocks from a different registry host. |
69
+
70
+ ```bash
71
+ astralis add hero-01
72
+ astralis add login-01 dashboard-02 --dir src/ui/blocks
73
+ astralis add --list
74
+ ```
75
+
76
+ ### `astralis theme [hex]`
77
+
78
+ Generate a static theme stylesheet from a seed.
79
+
80
+ | Option | |
81
+ | --- | --- |
82
+ | `--brand <hex>` | Brand hue, e.g. "#8b5cf6". A bare hex argument means the same. |
83
+ | `--gray <hex>` | Neutral hue: every surface, label and border. |
84
+ | `--error <hex>` | Seeds the error palette. Default: red. |
85
+ | `--warning <hex>` | Seeds the warning palette. Default: orange. |
86
+ | `--success <hex>` | Seeds the success palette. Default: green. |
87
+ | `--info <hex>` | Seeds the info palette. Default: blue. |
88
+ | `--font-heading <stack>` | Heading font stack. |
89
+ | `--font-body <stack>` | Body font stack. |
90
+ | `--font-mono <stack>` | Monospace font stack. |
91
+ | `--radius <n>` | Border-radius multiplier. Default: 1. |
92
+ | `--spacing <n>` | Spacing multiplier: the density dial. Default: 1. |
93
+ | `--font-scale <n>` | Font-size multiplier. Default: 1. |
94
+ | `--motion <n>` | Duration multiplier; 0 turns transitions off. Default: 1. |
95
+ | `--out <file>` | Where to write the stylesheet. Default: src/astralis-theme.css, or astralis-theme.css without a src/. |
96
+ | `--force` | Overwrite an existing file. |
97
+ | `--no-import` | Write the file but leave the entry file alone. |
98
+ | `--strict-contrast` | Exit 1, writing nothing, if any promised pairing fails WCAG AA. |
99
+
100
+ The status hues' own colorScheme values are never altered; each status seeds its own palette.
29
101
 
30
102
  ```bash
31
- npx astralis-cli init # do it
32
- npx astralis-cli init --dry-run # show what would change
103
+ astralis theme "#8b5cf6"
104
+ astralis theme --brand "#8b5cf6" --gray "#64748b" --radius 1.5
33
105
  ```
34
106
 
35
- ### `astralis theme <hex>`
107
+ ### `astralis validate [paths...]`
108
+
109
+ Check TSX and JSX against the installed design system.
110
+
111
+ | Option | |
112
+ | --- | --- |
113
+ | `--format <text\|json\|github>` | How to report: text for people, json for tools, github for inline pull-request annotations. Default: github inside GitHub Actions, text elsewhere. |
114
+ | `--json` | Same as --format json. |
115
+ | `--spec <path>` | Validate against this system-spec.json. Default: the installed astralis-ui's. |
116
+ | `--strict-tokens` | Also warn on raw colors that bypass the tokens. |
117
+
118
+ With no paths it checks the current directory, skipping node_modules and build output.
36
119
 
37
- Generates a static stylesheet with the full OKLCH-derived brand ramp and role
38
- tokens for light and dark — the build-time alternative to
39
- `<AstralisProvider tokens={{ brandColor }}>`, computed with the exact same
40
- color math.
120
+ Exits 1 when there are errors; warnings are reported but never fail the run.
41
121
 
42
122
  ```bash
43
- npx astralis-cli theme "#8b5cf6" --out astralis-theme.css
123
+ astralis validate
124
+ astralis validate src/components --json
125
+ astralis validate --strict-tokens
44
126
  ```
45
127
 
46
- Import it **after** `astralis-ui/styles.css`.
128
+ ### `astralis report <files...>`
129
+
130
+ Report a problem to the Astralis maintainers, with a snapshot built from your source files.
131
+
132
+ | Option | |
133
+ | --- | --- |
134
+ | `--title <text>` | The report's title. Asked for when omitted; required with --yes. |
135
+ | `--happened <text>` | What happened. |
136
+ | `--expected <text>` | What you expected instead. |
137
+ | `--include-text` | Keep the text in your JSX; by default it is replaced by placeholders. |
138
+ | `--no-findings` | Leave out the validator's findings for these files. |
139
+ | `--out <file>` | Write the snapshot to a file instead of sending it. |
140
+ | `--dry-run` | Print the snapshot and send nothing. |
141
+ | `--add-to <issue>` | Add the report to this existing issue instead of opening a new one. |
142
+ | `--new` | Open a new issue without checking for an existing one. |
143
+ | `--link` | Print a link to GitHub's own new-issue form, filled in, instead of signing in; you submit it there. |
144
+ | `--sign-out` | Forget the saved GitHub sign-in, and do nothing else. |
145
+ | `--spec <path>` | Build against this system-spec.json. Default: the installed astralis-ui's. |
146
+
147
+ It prints the exact JSON first and sends nothing until you confirm; --yes confirms without asking.
148
+
149
+ It opens a GitHub issue from your own account. The first time, you sign in with a code on github.com.
150
+
151
+ Before opening one it looks for an issue that already reports the same problem, and offers to add your report to it.
152
+
153
+ Only literal props are recorded, and only those the spec describes; links, sources and handlers never are.
154
+
155
+ ```bash
156
+ astralis report app/page.tsx
157
+ astralis report src/App.tsx --title "Card loses its border" --out snapshot.json
158
+ ```
47
159
 
48
160
  ### `astralis connect-mcp`
49
161
 
50
- Connects a single client to the [astralis-mcp](https://www.npmjs.com/package/astralis-mcp)
51
- docs server. It prompts for the client (Claude Code, Codex, Cursor, Claude
52
- Desktop, or Antigravity), tells you exactly what it's about to do, asks you to
53
- confirm, then does it — running the client's own `mcp add` command, or writing
54
- its JSON config (with a backup). Pass `--client` to skip the prompt.
162
+ Connect an AI coding agent to the Astralis MCP docs server.
163
+
164
+ | Option | |
165
+ | --- | --- |
166
+ | `--client <claude-code\|codex\|cursor\|claude-desktop\|antigravity>` | Skip the prompt and configure this client. |
55
167
 
56
168
  ```bash
57
- npx astralis-cli connect-mcp # prompt for a client, then configure it
58
- npx astralis-cli connect-mcp --client antigravity # go straight to Antigravity
59
- npx astralis-cli connect-mcp --client codex # go straight to Codex
169
+ astralis connect-mcp
170
+ astralis connect-mcp --client cursor --yes
171
+ ```
172
+
173
+ ### Global options
174
+
175
+ Every command takes these.
176
+
177
+ | Option | |
178
+ | --- | --- |
179
+ | `-y, --yes` | Never prompt; take the default answer. Replacing files still needs --overwrite or --force. |
180
+ | `-h, --help` | Show this command's options. |
181
+ | `--debug` | Print the stack trace if something fails unexpectedly. |
182
+
183
+ <!-- reference:end -->
184
+
185
+ ## `validate` in CI
186
+
187
+ `astralis validate` exits `1` when it finds an error and `0` otherwise;
188
+ warnings never fail the run. `--json` prints one report:
189
+
190
+ ```json
191
+ {
192
+ "spec": { "name": "astralis-ui", "version": "0.8.0", "specVersion": 3 },
193
+ "files": 12,
194
+ "errors": 1,
195
+ "warnings": 0,
196
+ "results": [
197
+ {
198
+ "file": "src/app/page.tsx",
199
+ "errors": [
200
+ { "code": "invalid-recipe-value", "file": "src/app/page.tsx", "line": 8, "column": 15,
201
+ "message": "Button: \"primary\" is not a variant value (valid: link, text, subtle, solid, surface, outline)",
202
+ "component": "Button", "prop": "variant", "value": "primary" }
203
+ ],
204
+ "warnings": []
205
+ }
206
+ ]
207
+ }
60
208
  ```
61
209
 
62
- Claude Code and Codex are configured by running their own `mcp add` command;
63
- Cursor, Claude Desktop, and Antigravity by writing their config files.
210
+ `results` lists only files with findings. A finding on a component also names
211
+ it, and the attribute and literal value when it is on one. The same checks are importable:
212
+ `astralis-cli/validate` (Node, with spec lookup) and `astralis-cli/validate-core`
213
+ (pure, browser-safe), both typed.
64
214
 
65
215
  ## License
66
216
 
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "astralis-cli",
3
- "version": "0.3.0",
4
- "description": "Setup and tooling CLI for Astralis UI — wire up a project, generate a static brand theme, connect the MCP server.",
3
+ "version": "0.5.0",
4
+ "description": "Setup and tooling CLI for Astralis UI — scaffold or wire up a project, add blocks, generate a static brand theme, validate code against the design system, connect the MCP server.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "Paul Andrew",
8
- "homepage": "https://astralis-zeta.vercel.app",
8
+ "homepage": "https://astralis-ui.com",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/SekiroDev360/astralis-ui.git",
11
+ "url": "git+https://github.com/sekiro-9/astralis-ui.git",
12
12
  "directory": "packages/astralis-cli"
13
13
  },
14
14
  "bugs": {
15
- "url": "https://github.com/SekiroDev360/astralis-ui/issues"
15
+ "url": "https://github.com/sekiro-9/astralis-ui/issues"
16
16
  },
17
17
  "keywords": [
18
18
  "astralis-ui",
@@ -27,18 +27,37 @@
27
27
  "astralis": "src/index.mjs"
28
28
  },
29
29
  "exports": {
30
- "./cli": "./src/index.mjs"
30
+ "./cli": "./src/index.mjs",
31
+ "./validate": {
32
+ "types": "./src/lib/validate.d.mts",
33
+ "default": "./src/lib/validate.mjs"
34
+ },
35
+ "./validate-core": {
36
+ "types": "./src/lib/validate-core.d.mts",
37
+ "default": "./src/lib/validate-core.mjs"
38
+ },
39
+ "./snapshot": {
40
+ "types": "./src/lib/snapshot.d.mts",
41
+ "default": "./src/lib/snapshot.mjs"
42
+ },
43
+ "./github": {
44
+ "types": "./src/lib/github.d.mts",
45
+ "default": "./src/lib/github.mjs"
46
+ }
31
47
  },
32
48
  "files": [
33
- "src"
49
+ "src",
50
+ "CHANGELOG.md"
34
51
  ],
35
52
  "engines": {
36
- "node": ">=18"
53
+ "node": "^22.18.0 || >=24.11.0"
37
54
  },
38
55
  "dependencies": {
39
- "astralis-ui": "^0.4.0"
56
+ "@babel/parser": "^8.0.4",
57
+ "astralis-ui": "^0.8.0"
40
58
  },
41
59
  "scripts": {
42
- "test": "node --test"
60
+ "test": "node --test \"test/*.test.mjs\"",
61
+ "reference": "node scripts/reference.mjs"
43
62
  }
44
63
  }
@@ -1,10 +1,11 @@
1
- import { parseArgs } from "node:util";
2
1
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
2
  import { dirname, join, relative } from "node:path";
4
- import { ok, warn, info, fail, cyan, dim, bold, confirm } from "../lib/ui.mjs";
3
+ import { ok, warn, info, fail, cyan, dim, bold, confirm, isAssumeYes, posix } from "../lib/ui.mjs";
4
+ import { parseCommandArgs } from "../lib/args.mjs";
5
+ import { commandNamed } from "../lib/commands.mjs";
5
6
  import { readPackageJson, detectPackageManager } from "../lib/detect.mjs";
6
7
  import { resolveBlocksDir } from "../lib/blocks-dir.mjs";
7
- import { registryBase, fetchIndex, fetchBlock } from "../lib/registry.mjs";
8
+ import { registryBase, fetchIndex, fetchBlock, isBlockId, resolveBlockFile } from "../lib/registry.mjs";
8
9
 
9
10
  /**
10
11
  * Copies a block's source into the project.
@@ -17,25 +18,6 @@ import { registryBase, fetchIndex, fetchBlock } from "../lib/registry.mjs";
17
18
  * merge. Fetch text, write files, check one dependency.
18
19
  */
19
20
 
20
- const USAGE = `Usage: astralis add <block>... [options]
21
-
22
- Copies a block's source into your project. The files are yours after that —
23
- no dependency to configure around.
24
-
25
- Options
26
- --list print every available block and exit
27
- --dir <path> where to write (default: [src/]components/blocks)
28
- --overwrite replace existing files without asking
29
- --dry-run show what would be written, write nothing
30
- --registry <url> read from a different registry host
31
- -h, --help this message
32
-
33
- Examples
34
- astralis add hero-01
35
- astralis add login-01 dashboard-02 --dir src/ui/blocks
36
- astralis add --list
37
- `;
38
-
39
21
  /** Group ids by category for a readable --list. */
40
22
  function printCatalogue(blocks) {
41
23
  const byCategory = new Map();
@@ -56,26 +38,9 @@ function printCatalogue(blocks) {
56
38
  }
57
39
 
58
40
  export async function run(argv) {
59
- let parsed;
60
- try {
61
- parsed = parseArgs({
62
- args: argv,
63
- allowPositionals: true,
64
- options: {
65
- list: { type: "boolean", default: false },
66
- dir: { type: "string" },
67
- overwrite: { type: "boolean", default: false },
68
- "dry-run": { type: "boolean", default: false },
69
- registry: { type: "string" },
70
- help: { type: "boolean", short: "h", default: false },
71
- },
72
- });
73
- } catch (error) {
74
- fail(`${error.message}\n\n${USAGE}`);
75
- }
76
-
77
- const { values, positionals } = parsed;
78
- if (values.help) return console.log(USAGE);
41
+ const args = parseCommandArgs(commandNamed("add"), argv);
42
+ if (!args) return;
43
+ const { values, positionals } = args;
79
44
 
80
45
  const cwd = process.cwd();
81
46
  const base = registryBase(values.registry);
@@ -83,7 +48,12 @@ export async function run(argv) {
83
48
  if (values.list) return printCatalogue((await fetchIndex(base)).blocks);
84
49
 
85
50
  if (positionals.length === 0) {
86
- fail(`Name at least one block — try ${cyan("astralis add --list")}.\n\n${USAGE}`);
51
+ fail(`Name at least one block, or list them with ${cyan("astralis add --list")}.`);
52
+ }
53
+
54
+ const badIds = positionals.filter((id) => !isBlockId(id));
55
+ if (badIds.length > 0) {
56
+ fail(`Not a block id: ${badIds.map((id) => cyan(id)).join(", ")} — ids are lowercase, like hero-01.`);
87
57
  }
88
58
 
89
59
  /* --- resolve every id before writing anything -------------------------- */
@@ -103,9 +73,17 @@ export async function run(argv) {
103
73
  const target = join(cwd, dirRelative);
104
74
  const dryRun = values["dry-run"];
105
75
 
106
- // Paths are shown forward-slashed on every platform: they end up in an
107
- // import statement, where a Windows separator would be wrong anyway.
108
- const posix = (path) => path.split("\\").join("/");
76
+ // Every destination is checked before the first write, so a bad entry
77
+ // leaves the project untouched rather than half-written.
78
+ const writes = items.flatMap((block) =>
79
+ (Array.isArray(block.contents) ? block.contents : []).map((file) => {
80
+ const path = resolveBlockFile(target, file?.path);
81
+ if (!path || typeof file.content !== "string") {
82
+ fail(`The registry entry for ${cyan(block.id)} has an unsafe or malformed file (${JSON.stringify(file?.path)}) — nothing was written.`);
83
+ }
84
+ return { path, content: file.content };
85
+ }),
86
+ );
109
87
 
110
88
  console.log("");
111
89
  info(
@@ -117,34 +95,33 @@ export async function run(argv) {
117
95
  let written = 0;
118
96
  let skipped = 0;
119
97
 
120
- for (const block of items) {
121
- for (const file of block.contents) {
122
- const path = join(target, file.path);
123
- const shown = posix(relative(cwd, path));
124
-
125
- if (existsSync(path) && !values.overwrite) {
126
- if (dryRun) {
127
- warn(`${shown} ${dim("exists — would ask before replacing")}`);
128
- skipped += 1;
129
- continue;
130
- }
131
- const replace = await confirm(`${shown} already exists. Replace it?`);
132
- if (!replace) {
133
- warn(`skipped ${shown}`);
134
- skipped += 1;
135
- continue;
136
- }
137
- }
98
+ for (const { path, content } of writes) {
99
+ const shown = posix(relative(cwd, path));
138
100
 
139
- if (dryRun) {
140
- ok(`${shown} ${dim(`(${Buffer.byteLength(file.content)} bytes)`)}`);
141
- } else {
142
- mkdirSync(dirname(path), { recursive: true });
143
- writeFileSync(path, file.content);
144
- ok(shown);
101
+ if (existsSync(path) && !values.overwrite) {
102
+ if (dryRun || isAssumeYes()) {
103
+ warn(`${shown} ${dim(dryRun ? "exists — would ask before replacing" : "exists — skipped; --overwrite replaces it")}`);
104
+ skipped += 1;
105
+ continue;
145
106
  }
146
- written += 1;
107
+ const replace = await confirm(`${shown} already exists. Replace it?`, {
108
+ hint: "Pass --overwrite to replace existing files.",
109
+ });
110
+ if (!replace) {
111
+ warn(`skipped ${shown}`);
112
+ skipped += 1;
113
+ continue;
114
+ }
115
+ }
116
+
117
+ if (dryRun) {
118
+ ok(`${shown} ${dim(`(${Buffer.byteLength(content)} bytes)`)}`);
119
+ } else {
120
+ mkdirSync(dirname(path), { recursive: true });
121
+ writeFileSync(path, content);
122
+ ok(shown);
147
123
  }
124
+ written += 1;
148
125
  }
149
126
 
150
127
  /* --- the one dependency a block actually has --------------------------- */