@astralkit/cli 4.1.1 → 4.2.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.
- package/README.md +148 -225
- package/package.json +1 -1
- package/src/commands/add.js +90 -2
package/README.md
CHANGED
|
@@ -1,212 +1,115 @@
|
|
|
1
1
|
# @astralkit/cli
|
|
2
2
|
|
|
3
|
-
Install and manage AstralKit UI components, boosters, and workflows in your
|
|
3
|
+
Install and manage AstralKit UI components, boosters, and workflows in your React and Next.js projects.
|
|
4
4
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
#
|
|
9
|
-
npx @astralkit/cli init
|
|
8
|
+
# 1. Get your API key from https://astralkit.com/account
|
|
10
9
|
|
|
11
|
-
#
|
|
12
|
-
npx @astralkit/cli
|
|
10
|
+
# 2. Initialize AstralKit in your project
|
|
11
|
+
npx @astralkit/cli init --api-key ak_YOUR_KEY
|
|
13
12
|
|
|
14
|
-
# Add a
|
|
15
|
-
npx @astralkit/cli add
|
|
16
|
-
|
|
17
|
-
# Scaffold a workflow
|
|
18
|
-
npx @astralkit/cli add saas-starter
|
|
19
|
-
|
|
20
|
-
# Search for content
|
|
21
|
-
npx @astralkit/cli search "pricing table"
|
|
13
|
+
# 3. Add a component
|
|
14
|
+
npx @astralkit/cli add button-sizes --api-key ak_YOUR_KEY
|
|
22
15
|
```
|
|
23
16
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## Content Types
|
|
27
|
-
|
|
28
|
-
AstralKit distributes three types of content:
|
|
29
|
-
|
|
30
|
-
| Type | Description | Example |
|
|
31
|
-
|------|-------------|---------|
|
|
32
|
-
| **Components** | Single UI elements with framework variants | Button, Card, Data Table |
|
|
33
|
-
| **Boosters** | Drop-in feature modules (core logic + framework adapters) | Auth System, Stripe Billing, File Upload |
|
|
34
|
-
| **Workflows** | Complete application scaffolds | AI SaaS Starter, CRM, Admin Dashboard |
|
|
35
|
-
|
|
36
|
-
## Commands
|
|
37
|
-
|
|
38
|
-
### `astralkit add <name>`
|
|
39
|
-
|
|
40
|
-
Add a component, booster, or workflow to your project. The CLI is fully interactive — when you omit flags, it prompts you with arrow-key selections.
|
|
41
|
-
|
|
42
|
-
#### Smart Auto-Detection
|
|
43
|
-
|
|
44
|
-
The CLI automatically:
|
|
45
|
-
- **Detects what you're installing** — searches components, boosters, and workflows for the slug. If found in multiple, prompts you to choose.
|
|
46
|
-
- **Detects your framework** — checks for `next.config.js` (Next.js), `react` in package.json (React), or prompts if unsure.
|
|
47
|
-
- **Detects your package manager** — reads lockfiles (`bun.lockb`, `pnpm-lock.yaml`, `yarn.lock`) and uses the right one.
|
|
17
|
+
After init, your API key is saved locally — no need to pass it again:
|
|
48
18
|
|
|
49
19
|
```bash
|
|
50
|
-
|
|
51
|
-
astralkit add
|
|
52
|
-
|
|
53
|
-
? What are you installing?
|
|
54
|
-
❯ Booster (feature module)
|
|
55
|
-
Component (UI element)
|
|
56
|
-
Workflow (complete app)
|
|
57
|
-
|
|
58
|
-
? Detected Next.js project. Which framework? (nextjs)
|
|
59
|
-
|
|
60
|
-
✔ Added booster Authentication System (Next.js)
|
|
20
|
+
astralkit add pricing-table
|
|
21
|
+
astralkit add sidebar-light
|
|
22
|
+
astralkit list
|
|
61
23
|
```
|
|
62
24
|
|
|
63
|
-
|
|
25
|
+
## What Init Does
|
|
64
26
|
|
|
65
27
|
```bash
|
|
66
|
-
astralkit
|
|
67
|
-
astralkit add pricing-table --framework=react
|
|
68
|
-
astralkit add data-table --overwrite
|
|
28
|
+
npx @astralkit/cli init --api-key ak_YOUR_KEY
|
|
69
29
|
```
|
|
70
30
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
astralkit add stripe-billing --booster --framework=nextjs
|
|
78
|
-
```
|
|
31
|
+
1. **Installs `astralkit`** — design tokens, CSS utilities, and `cn()` helper as a real npm dependency
|
|
32
|
+
2. **Detects your framework** — Next.js or React (auto-detected from project files)
|
|
33
|
+
3. **Detects Tailwind version** — v3 or v4, writes the correct CSS imports
|
|
34
|
+
4. **Detects TypeScript** — serves `.tsx` or `.jsx` accordingly
|
|
35
|
+
5. **Updates your CSS** — adds `@import "astralkit/theme"` and `@import "astralkit/utilities"` to your globals.css
|
|
36
|
+
6. **Creates `astralkit-ai-rules.md`** — paste into Cursor, CLAUDE.md, etc.
|
|
79
37
|
|
|
80
|
-
|
|
38
|
+
No config file is created. Everything is auto-detected on every command.
|
|
81
39
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
✔ Added booster Stripe Billing (Next.js)
|
|
86
|
-
Core files → src/lib/stripe-billing/
|
|
87
|
-
stripe.ts
|
|
88
|
-
webhooks.ts
|
|
89
|
-
Adapter files → src/components/stripe-billing/
|
|
90
|
-
CheckoutButton.tsx
|
|
91
|
-
PricingTable.tsx
|
|
92
|
-
|
|
93
|
-
? Install dependencies? (stripe, @stripe/stripe-js) (Y/n)
|
|
94
|
-
✔ Dependencies installed
|
|
95
|
-
|
|
96
|
-
✅ Stripe Billing installed successfully!
|
|
97
|
-
```
|
|
40
|
+
## Commands
|
|
98
41
|
|
|
99
|
-
|
|
42
|
+
### `astralkit init`
|
|
100
43
|
|
|
101
|
-
|
|
44
|
+
Initialize AstralKit in your project.
|
|
102
45
|
|
|
103
46
|
```bash
|
|
104
|
-
astralkit
|
|
105
|
-
astralkit
|
|
47
|
+
astralkit init --api-key ak_YOUR_KEY
|
|
48
|
+
astralkit init --framework react
|
|
49
|
+
astralkit init --dir src/components/ui
|
|
106
50
|
```
|
|
107
51
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
? Install dependencies with npm? (Y/n)
|
|
115
|
-
✔ Dependencies installed
|
|
116
|
-
|
|
117
|
-
✅ Ready to go!
|
|
52
|
+
| Flag | Description |
|
|
53
|
+
|------|-------------|
|
|
54
|
+
| `--api-key <key>` | Your API key (from astralkit.com/account) |
|
|
55
|
+
| `--framework <fw>` | Override framework detection (react, nextjs) |
|
|
56
|
+
| `--dir <path>` | Component output directory (default: src/components/ui) |
|
|
118
57
|
|
|
119
|
-
|
|
120
|
-
npm run dev
|
|
121
|
-
```
|
|
58
|
+
### `astralkit add <name>`
|
|
122
59
|
|
|
123
|
-
|
|
60
|
+
Add a component, booster, or workflow to your project. The CLI **auto-detects the content type** — no flags needed.
|
|
124
61
|
|
|
125
62
|
```bash
|
|
126
|
-
|
|
63
|
+
# Just type the name — the CLI figures out what it is
|
|
64
|
+
astralkit add avatar-verified # → found as component, installs directly
|
|
65
|
+
astralkit add auth-system # → found as booster, installs directly
|
|
66
|
+
astralkit add ai-saas-starter # → found as workflow, scaffolds directly
|
|
127
67
|
```
|
|
128
68
|
|
|
129
|
-
|
|
69
|
+
**Smart detection:**
|
|
70
|
+
- Searches all registries (components, boosters, workflows) simultaneously
|
|
71
|
+
- If found in one → installs directly
|
|
72
|
+
- If found in multiple → prompts you to choose
|
|
73
|
+
- If not found → suggests similar names ("Did you mean?")
|
|
130
74
|
|
|
131
|
-
|
|
75
|
+
You can still use explicit flags to skip detection:
|
|
132
76
|
|
|
133
77
|
```bash
|
|
134
|
-
astralkit add auth-system --booster
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
Core → src/lib/auth-system/
|
|
139
|
-
+ create auth.ts
|
|
140
|
-
+ create session.ts
|
|
141
|
-
+ create middleware.ts
|
|
142
|
-
Adapter → src/components/auth-system/
|
|
143
|
-
+ create LoginForm.tsx
|
|
144
|
-
+ create SignupForm.tsx
|
|
145
|
-
|
|
146
|
-
Dependencies: better-auth
|
|
78
|
+
astralkit add auth-system --booster # skip detection, install as booster
|
|
79
|
+
astralkit add crm --workflow --overlay # merge workflow into current project
|
|
80
|
+
astralkit add pricing-table --framework react
|
|
147
81
|
```
|
|
148
82
|
|
|
149
|
-
#### Options
|
|
150
|
-
|
|
151
83
|
| Flag | Description |
|
|
152
84
|
|------|-------------|
|
|
153
|
-
|
|
|
154
|
-
|
|
|
85
|
+
| `--api-key <key>` | Your API key |
|
|
86
|
+
| `-f, --framework <fw>` | Framework version (react, nextjs) |
|
|
87
|
+
| `--dir <path>` | Override output directory |
|
|
155
88
|
| `--overwrite` | Overwrite existing files |
|
|
156
|
-
| `--booster` | Install a booster
|
|
157
|
-
| `--workflow` | Scaffold a workflow
|
|
158
|
-
| `--overlay` | Merge workflow into current project
|
|
159
|
-
| `--dry-run` | Preview
|
|
89
|
+
| `--booster` | Install a booster |
|
|
90
|
+
| `--workflow` | Scaffold a workflow |
|
|
91
|
+
| `--overlay` | Merge workflow into current project |
|
|
92
|
+
| `--dry-run` | Preview without writing files |
|
|
160
93
|
|
|
161
94
|
### `astralkit remove <name>`
|
|
162
95
|
|
|
163
|
-
Remove a previously installed component, booster, or workflow.
|
|
96
|
+
Remove a previously installed component, booster, or workflow.
|
|
164
97
|
|
|
165
98
|
```bash
|
|
166
99
|
astralkit remove auth-system
|
|
167
|
-
|
|
168
|
-
Found files for "auth-system":
|
|
169
|
-
|
|
170
|
-
Booster (core): src/lib/auth-system/
|
|
171
|
-
auth.ts
|
|
172
|
-
session.ts
|
|
173
|
-
Booster (adapter): src/components/auth-system/
|
|
174
|
-
LoginForm.tsx
|
|
175
|
-
SignupForm.tsx
|
|
176
|
-
|
|
177
|
-
? Remove 2 item(s)? (y/N)
|
|
178
|
-
✓ Removed src/lib/auth-system/
|
|
179
|
-
✓ Removed src/components/auth-system/
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
Use `--force` to skip the confirmation prompt (for scripts/CI).
|
|
183
|
-
|
|
184
|
-
### `astralkit init`
|
|
185
|
-
|
|
186
|
-
Initialize AstralKit in your project:
|
|
187
|
-
|
|
188
|
-
1. Installs the `astralkit` npm package (design tokens, utilities, `cn()` helper)
|
|
189
|
-
2. Adds required CSS imports to your stylesheet
|
|
190
|
-
3. Creates `astralkit.config.json`
|
|
191
|
-
|
|
192
|
-
```bash
|
|
193
|
-
astralkit init
|
|
194
|
-
astralkit init --framework=react
|
|
195
|
-
astralkit init --dir=src/components/ui
|
|
100
|
+
astralkit remove pricing-table --force # skip confirmation
|
|
196
101
|
```
|
|
197
102
|
|
|
198
103
|
### `astralkit list`
|
|
199
104
|
|
|
200
|
-
|
|
105
|
+
Browse available content.
|
|
201
106
|
|
|
202
107
|
```bash
|
|
203
|
-
astralkit list #
|
|
204
|
-
astralkit list --boosters #
|
|
205
|
-
astralkit list --workflows #
|
|
206
|
-
astralkit list --category
|
|
207
|
-
astralkit list --
|
|
208
|
-
astralkit list --pro
|
|
209
|
-
astralkit list --free
|
|
108
|
+
astralkit list # components
|
|
109
|
+
astralkit list --boosters # boosters
|
|
110
|
+
astralkit list --workflows # workflows
|
|
111
|
+
astralkit list --category forms
|
|
112
|
+
astralkit list --pro # pro-only items
|
|
210
113
|
```
|
|
211
114
|
|
|
212
115
|
### `astralkit search <query>`
|
|
@@ -214,21 +117,19 @@ astralkit list --free
|
|
|
214
117
|
Search by name or description.
|
|
215
118
|
|
|
216
119
|
```bash
|
|
217
|
-
astralkit search "
|
|
218
|
-
astralkit search "pricing" --framework=react
|
|
120
|
+
astralkit search "pricing table"
|
|
219
121
|
astralkit search "stripe" --boosters
|
|
220
|
-
astralkit search "crm" --workflows
|
|
221
122
|
```
|
|
222
123
|
|
|
223
|
-
### `astralkit diff <
|
|
124
|
+
### `astralkit diff <name>`
|
|
224
125
|
|
|
225
|
-
|
|
126
|
+
Compare your local version against the latest.
|
|
226
127
|
|
|
227
128
|
```bash
|
|
228
129
|
astralkit diff button-sizes
|
|
229
130
|
```
|
|
230
131
|
|
|
231
|
-
### `astralkit update <
|
|
132
|
+
### `astralkit update <name>`
|
|
232
133
|
|
|
233
134
|
Update a component to the latest version.
|
|
234
135
|
|
|
@@ -237,66 +138,70 @@ astralkit update button-sizes
|
|
|
237
138
|
astralkit update button-sizes --force
|
|
238
139
|
```
|
|
239
140
|
|
|
240
|
-
### `astralkit
|
|
141
|
+
### `astralkit whoami`
|
|
241
142
|
|
|
242
|
-
|
|
143
|
+
Show your authentication status and plan.
|
|
243
144
|
|
|
244
145
|
```bash
|
|
245
|
-
astralkit
|
|
246
|
-
astralkit logout # Remove stored token
|
|
247
|
-
astralkit whoami # Show auth status and plan
|
|
146
|
+
astralkit whoami
|
|
248
147
|
```
|
|
249
148
|
|
|
250
|
-
|
|
149
|
+
### `astralkit login` / `astralkit logout`
|
|
251
150
|
|
|
252
|
-
|
|
151
|
+
Browser-based authentication (alternative to `--api-key`).
|
|
253
152
|
|
|
254
153
|
```bash
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
Visit https://astralkit.com/pricing
|
|
258
|
-
|
|
259
|
-
$ astralkit login
|
|
260
|
-
✔ Authenticated successfully!
|
|
261
|
-
Email: you@example.com
|
|
262
|
-
Plan: pro
|
|
263
|
-
|
|
264
|
-
$ astralkit add stripe-billing --booster
|
|
265
|
-
✔ Added booster Stripe Billing (Next.js)
|
|
266
|
-
✨ Pro booster — thank you for your subscription!
|
|
154
|
+
astralkit login # opens browser
|
|
155
|
+
astralkit logout # clear stored token
|
|
267
156
|
```
|
|
268
157
|
|
|
269
|
-
##
|
|
158
|
+
## Authentication
|
|
270
159
|
|
|
271
|
-
|
|
160
|
+
**API key (recommended):**
|
|
272
161
|
|
|
273
|
-
|
|
162
|
+
Get your key from [astralkit.com/account](https://astralkit.com/account). Pass it once with `--api-key` — it's saved to `~/.astralkit/config.json` for future commands.
|
|
274
163
|
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
"$schema": "https://astralkit.com/schema/config.json",
|
|
278
|
-
"framework": "nextjs",
|
|
279
|
-
"componentsDir": "src/components/ui"
|
|
280
|
-
}
|
|
164
|
+
```bash
|
|
165
|
+
astralkit init --api-key ak_YOUR_KEY
|
|
281
166
|
```
|
|
282
167
|
|
|
283
|
-
|
|
168
|
+
**Browser login (alternative):**
|
|
284
169
|
|
|
285
|
-
|
|
170
|
+
```bash
|
|
171
|
+
astralkit login
|
|
172
|
+
```
|
|
286
173
|
|
|
287
|
-
|
|
174
|
+
**CI/CD:**
|
|
288
175
|
|
|
289
|
-
|
|
176
|
+
Set the `ASTRALKIT_API_KEY` environment variable:
|
|
290
177
|
|
|
291
178
|
```bash
|
|
292
|
-
export
|
|
179
|
+
export ASTRALKIT_API_KEY=ak_YOUR_KEY
|
|
293
180
|
astralkit add button-sizes
|
|
294
|
-
astralkit add stripe-billing --booster
|
|
295
181
|
```
|
|
296
182
|
|
|
183
|
+
## Content Types
|
|
184
|
+
|
|
185
|
+
| Type | Description | Install Location |
|
|
186
|
+
|------|-------------|------------------|
|
|
187
|
+
| **Components** | Single UI elements (Button, Card, Table) | `src/components/ui/` |
|
|
188
|
+
| **Boosters** | Feature modules (Auth, Stripe, File Upload) | `src/lib/<name>/` + `src/components/<name>/` |
|
|
189
|
+
| **Workflows** | Complete app scaffolds (SaaS Starter, CRM) | New directory or `--overlay` into current |
|
|
190
|
+
|
|
191
|
+
## Framework Support
|
|
192
|
+
|
|
193
|
+
The CLI is for **React and Next.js** projects. HTML users copy components directly from [astralkit.com](https://astralkit.com).
|
|
194
|
+
|
|
195
|
+
| Detection | Signal |
|
|
196
|
+
|-----------|--------|
|
|
197
|
+
| Next.js | `next.config.*` found |
|
|
198
|
+
| React | `react` in package.json dependencies |
|
|
199
|
+
| TypeScript | `tsconfig.json` found → `.tsx` files |
|
|
200
|
+
| JavaScript | No tsconfig → `.jsx` files |
|
|
201
|
+
|
|
297
202
|
## Package Manager Support
|
|
298
203
|
|
|
299
|
-
|
|
204
|
+
Auto-detected from lockfiles:
|
|
300
205
|
|
|
301
206
|
| Lockfile | Package Manager |
|
|
302
207
|
|----------|----------------|
|
|
@@ -305,58 +210,76 @@ The CLI auto-detects your package manager from lockfiles:
|
|
|
305
210
|
| `yarn.lock` | yarn |
|
|
306
211
|
| (default) | npm |
|
|
307
212
|
|
|
308
|
-
|
|
213
|
+
## What Gets Installed
|
|
214
|
+
|
|
215
|
+
After `astralkit init`, your project has:
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
node_modules/astralkit/ ← real npm dependency
|
|
219
|
+
├── astralkit-theme.css ← design tokens
|
|
220
|
+
├── astralkit-utilities.css ← utility classes
|
|
221
|
+
├── lib/utils.js ← cn() function
|
|
222
|
+
└── package.json
|
|
223
|
+
|
|
224
|
+
src/components/ui/ ← components go here
|
|
225
|
+
astralkit-ai-rules.md ← AI coding rules
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Your `globals.css`:
|
|
229
|
+
```css
|
|
230
|
+
@import "tailwindcss";
|
|
231
|
+
@import "astralkit/theme";
|
|
232
|
+
@import "astralkit/utilities";
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Teammates clone and run `npm install` — everything works. No `astralkit init` needed in CI.
|
|
236
|
+
|
|
237
|
+
## Free vs Pro
|
|
238
|
+
|
|
239
|
+
| | Free | Pro |
|
|
240
|
+
|---|---|---|
|
|
241
|
+
| Components | 10/month | Unlimited |
|
|
242
|
+
| Frameworks | React, Next.js | React, Next.js |
|
|
243
|
+
| Boosters | — | All |
|
|
244
|
+
| Workflows | — | All |
|
|
245
|
+
|
|
246
|
+
Upgrade at [astralkit.com/pricing](https://astralkit.com/pricing).
|
|
309
247
|
|
|
310
248
|
## Environment Variables
|
|
311
249
|
|
|
312
250
|
| Variable | Description |
|
|
313
251
|
|----------|-------------|
|
|
314
|
-
| `
|
|
252
|
+
| `ASTRALKIT_API_KEY` | API key for CI/CD (skips interactive auth) |
|
|
315
253
|
| `ASTRALKIT_API_URL` | Override API base URL (development only) |
|
|
316
254
|
| `ASTRALKIT_LOGIN_PORT` | Override callback port for login (default: 9876) |
|
|
317
255
|
|
|
318
|
-
## Security
|
|
319
|
-
|
|
320
|
-
- Tokens stored at `~/.astralkit/config.json` with `0600` permissions
|
|
321
|
-
- Browser login uses CSRF state tokens
|
|
322
|
-
- All API requests use HTTPS with 30-second timeouts
|
|
323
|
-
- No credentials are hardcoded in the package
|
|
324
|
-
|
|
325
256
|
## Troubleshooting
|
|
326
257
|
|
|
327
|
-
|
|
328
|
-
|
|
258
|
+
**Port 9876 in use:**
|
|
329
259
|
```bash
|
|
330
260
|
ASTRALKIT_LOGIN_PORT=9877 astralkit login
|
|
331
261
|
```
|
|
332
262
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
### Dependency conflicts (ERESOLVE)
|
|
338
|
-
|
|
339
|
-
The CLI handles most dependency conflicts automatically. If you see an error, try:
|
|
263
|
+
**Token expired:**
|
|
264
|
+
```bash
|
|
265
|
+
astralkit init --api-key ak_YOUR_NEW_KEY
|
|
266
|
+
```
|
|
340
267
|
|
|
268
|
+
**Dependency conflicts:**
|
|
341
269
|
```bash
|
|
342
|
-
# npm
|
|
343
270
|
npm install <package> --legacy-peer-deps
|
|
344
|
-
|
|
345
|
-
# pnpm
|
|
346
|
-
pnpm add <package> --force
|
|
347
271
|
```
|
|
348
272
|
|
|
349
|
-
### Network errors
|
|
350
|
-
|
|
351
|
-
Check your internet connection. The CLI requires access to `astralkit.com`.
|
|
352
|
-
|
|
353
273
|
## Requirements
|
|
354
274
|
|
|
355
275
|
- Node.js 18+
|
|
276
|
+
- React or Next.js project
|
|
356
277
|
- An AstralKit account for premium content
|
|
357
278
|
|
|
358
279
|
## Links
|
|
359
280
|
|
|
360
281
|
- [AstralKit](https://astralkit.com)
|
|
361
|
-
- [
|
|
282
|
+
- [Components](https://astralkit.com/components)
|
|
362
283
|
- [Pricing](https://astralkit.com/pricing)
|
|
284
|
+
- [Documentation](https://astralkit.com/documentation)
|
|
285
|
+
- [Support](https://astralkit.com/support)
|
package/package.json
CHANGED
package/src/commands/add.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
4
|
import * as p from '@clack/prompts';
|
|
5
|
-
import { getComponent, getBooster, getWorkflow } from '../lib/api.js';
|
|
5
|
+
import { getComponent, getBooster, getWorkflow, listComponents, listBoosters, listWorkflows } from '../lib/api.js';
|
|
6
6
|
import {
|
|
7
7
|
detectFramework,
|
|
8
8
|
detectTypeScript,
|
|
@@ -34,9 +34,97 @@ export async function addCommand(nameOrSlug, options) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
// If explicit type flag provided, skip smart detection
|
|
37
38
|
if (options.booster) return addBooster(nameOrSlug, options);
|
|
38
39
|
if (options.workflow) return addWorkflow(nameOrSlug, options);
|
|
39
|
-
|
|
40
|
+
|
|
41
|
+
// ─── Smart detection: search all registries for the slug ───
|
|
42
|
+
const ora = (await import('ora')).default;
|
|
43
|
+
const spinner = ora('Searching registries...').start();
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
// Search all three registries in parallel
|
|
47
|
+
const [components, boosters, workflows] = await Promise.allSettled([
|
|
48
|
+
listComponents({ search: nameOrSlug }).catch(() => ({ data: [] })),
|
|
49
|
+
listBoosters({ search: nameOrSlug }).catch(() => ({ data: [] })),
|
|
50
|
+
listWorkflows({ search: nameOrSlug }).catch(() => ({ data: [] })),
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
const compMatch = (components.status === 'fulfilled' ? components.value?.data : [])
|
|
54
|
+
?.find(c => c.slug === nameOrSlug);
|
|
55
|
+
const boosterMatch = (boosters.status === 'fulfilled' ? boosters.value?.data : [])
|
|
56
|
+
?.find(b => b.slug === nameOrSlug);
|
|
57
|
+
const workflowMatch = (workflows.status === 'fulfilled' ? workflows.value?.data : [])
|
|
58
|
+
?.find(w => w.slug === nameOrSlug);
|
|
59
|
+
|
|
60
|
+
const matches = [];
|
|
61
|
+
if (compMatch) matches.push({ type: 'component', name: compMatch.name || nameOrSlug, slug: nameOrSlug });
|
|
62
|
+
if (boosterMatch) matches.push({ type: 'booster', name: boosterMatch.name || nameOrSlug, slug: nameOrSlug });
|
|
63
|
+
if (workflowMatch) matches.push({ type: 'workflow', name: workflowMatch.name || nameOrSlug, slug: nameOrSlug });
|
|
64
|
+
|
|
65
|
+
spinner.stop();
|
|
66
|
+
|
|
67
|
+
if (matches.length === 0) {
|
|
68
|
+
// No exact match — try fuzzy suggestions
|
|
69
|
+
const allItems = [
|
|
70
|
+
...((components.status === 'fulfilled' ? components.value?.data : []) || []).map(c => ({ ...c, type: 'component' })),
|
|
71
|
+
...((boosters.status === 'fulfilled' ? boosters.value?.data : []) || []).map(b => ({ ...b, type: 'booster' })),
|
|
72
|
+
...((workflows.status === 'fulfilled' ? workflows.value?.data : []) || []).map(w => ({ ...w, type: 'workflow' })),
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
const similar = allItems
|
|
76
|
+
.filter(item => item.slug && (
|
|
77
|
+
item.slug.includes(nameOrSlug) ||
|
|
78
|
+
nameOrSlug.includes(item.slug) ||
|
|
79
|
+
item.name?.toLowerCase().includes(nameOrSlug.toLowerCase())
|
|
80
|
+
))
|
|
81
|
+
.slice(0, 5);
|
|
82
|
+
|
|
83
|
+
if (similar.length > 0) {
|
|
84
|
+
p.log.warn(`"${nameOrSlug}" not found.`);
|
|
85
|
+
console.log();
|
|
86
|
+
console.log(pc.gray(' Did you mean:'));
|
|
87
|
+
for (const s of similar) {
|
|
88
|
+
console.log(` ${pc.cyan(s.slug)} ${pc.gray(`(${s.type})`)}`);
|
|
89
|
+
}
|
|
90
|
+
console.log();
|
|
91
|
+
} else {
|
|
92
|
+
p.log.error(`"${nameOrSlug}" not found in any registry.`);
|
|
93
|
+
p.log.info('Run ' + pc.cyan('astralkit search "' + nameOrSlug + '"') + ' to browse available content.');
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (matches.length === 1) {
|
|
99
|
+
// Exact match in one registry — install directly
|
|
100
|
+
const match = matches[0];
|
|
101
|
+
p.log.step(`Found ${pc.cyan(match.name)} as a ${pc.bold(match.type)}`);
|
|
102
|
+
|
|
103
|
+
if (match.type === 'booster') return addBooster(nameOrSlug, options);
|
|
104
|
+
if (match.type === 'workflow') return addWorkflow(nameOrSlug, options);
|
|
105
|
+
return addComponent(nameOrSlug, options);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Found in multiple registries — prompt user to choose
|
|
109
|
+
const choice = await p.select({
|
|
110
|
+
message: `"${nameOrSlug}" found in multiple registries. What would you like to install?`,
|
|
111
|
+
options: matches.map(m => ({
|
|
112
|
+
value: m.type,
|
|
113
|
+
label: `${m.name} (${m.type === 'component' ? 'UI component' : m.type === 'booster' ? 'feature module' : 'app scaffold'})`,
|
|
114
|
+
})),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (p.isCancel(choice)) { p.cancel('Cancelled.'); process.exit(0); }
|
|
118
|
+
|
|
119
|
+
if (choice === 'booster') return addBooster(nameOrSlug, options);
|
|
120
|
+
if (choice === 'workflow') return addWorkflow(nameOrSlug, options);
|
|
121
|
+
return addComponent(nameOrSlug, options);
|
|
122
|
+
|
|
123
|
+
} catch (err) {
|
|
124
|
+
spinner.stop();
|
|
125
|
+
// If registry search fails, fall back to component (original behavior)
|
|
126
|
+
return addComponent(nameOrSlug, options);
|
|
127
|
+
}
|
|
40
128
|
}
|
|
41
129
|
|
|
42
130
|
function resolveFramework(options) {
|