@astralkit/cli 2.0.1 → 2.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 +90 -18
- package/bin/index.js +15 -8
- package/package.json +2 -4
- package/src/commands/add.js +283 -44
- package/src/commands/diff.js +1 -1
- package/src/commands/init.js +82 -11
- package/src/commands/list.js +125 -3
- package/src/commands/search.js +105 -2
- package/src/commands/update.js +1 -4
- package/src/lib/api.js +53 -1
- package/src/lib/config.js +70 -23
- package/src/lib/validators.js +29 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @astralkit/cli
|
|
2
2
|
|
|
3
|
-
Install and manage AstralKit UI components in your project.
|
|
3
|
+
Install and manage AstralKit UI components, boosters, and workflows in your project.
|
|
4
4
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
@@ -11,15 +11,35 @@ npx @astralkit/cli init
|
|
|
11
11
|
# Add a component
|
|
12
12
|
npx @astralkit/cli add button-sizes
|
|
13
13
|
|
|
14
|
+
# Add a booster (feature module)
|
|
15
|
+
npx @astralkit/cli add stripe-payments --booster
|
|
16
|
+
|
|
17
|
+
# Scaffold a workflow (complete app)
|
|
18
|
+
npx @astralkit/cli add saas-starter --workflow
|
|
19
|
+
|
|
14
20
|
# Search for components
|
|
15
21
|
npx @astralkit/cli search "pricing table"
|
|
16
22
|
```
|
|
17
23
|
|
|
24
|
+
## Content Types
|
|
25
|
+
|
|
26
|
+
AstralKit distributes three types of content:
|
|
27
|
+
|
|
28
|
+
| Type | Description | Example |
|
|
29
|
+
|------|-------------|---------|
|
|
30
|
+
| **Components** | Single UI elements with framework variants | Button, Card, Data Table |
|
|
31
|
+
| **Boosters** | Drop-in feature modules (core logic + framework adapters) | Stripe Payments, Auth System |
|
|
32
|
+
| **Workflows** | Complete application scaffolds | SaaS Starter, CRM, Admin Dashboard |
|
|
33
|
+
|
|
18
34
|
## Commands
|
|
19
35
|
|
|
20
36
|
### `astralkit init`
|
|
21
37
|
|
|
22
|
-
Initialize AstralKit in your project.
|
|
38
|
+
Initialize AstralKit in your project. This command:
|
|
39
|
+
|
|
40
|
+
1. Installs the `astralkit` npm package (design tokens, utilities, and `cn()` helper)
|
|
41
|
+
2. Adds required CSS imports to your stylesheet (`@import "tailwindcss"`, `@import "astralkit/theme"`, `@import "astralkit/utilities"`)
|
|
42
|
+
3. Creates `astralkit.config.json` with your framework and component directory
|
|
23
43
|
|
|
24
44
|
```bash
|
|
25
45
|
astralkit init
|
|
@@ -27,9 +47,11 @@ astralkit init --framework=react
|
|
|
27
47
|
astralkit init --dir=src/components/ui
|
|
28
48
|
```
|
|
29
49
|
|
|
30
|
-
### `astralkit add <
|
|
50
|
+
### `astralkit add <name>`
|
|
31
51
|
|
|
32
|
-
Add a component
|
|
52
|
+
Add a component, booster, or workflow to your project.
|
|
53
|
+
|
|
54
|
+
#### Adding Components
|
|
33
55
|
|
|
34
56
|
```bash
|
|
35
57
|
astralkit add avatar-variants
|
|
@@ -37,17 +59,51 @@ astralkit add pricing-table --framework=react
|
|
|
37
59
|
astralkit add data-table --overwrite
|
|
38
60
|
```
|
|
39
61
|
|
|
40
|
-
|
|
41
|
-
|
|
62
|
+
#### Adding Boosters
|
|
63
|
+
|
|
64
|
+
Boosters install framework-agnostic core files (API routes, webhooks, utilities) and framework-specific adapter files (UI components, hooks).
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
astralkit add stripe-payments --booster
|
|
68
|
+
astralkit add auth-system --booster --framework=nextjs
|
|
69
|
+
astralkit add stripe-payments --booster --overwrite
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Core files are written to `src/lib/<booster-slug>/` and adapter files to `src/components/<booster-slug>/` by default. Boosters may specify custom install paths.
|
|
73
|
+
|
|
74
|
+
#### Adding Workflows
|
|
75
|
+
|
|
76
|
+
Workflows scaffold a complete application. By default, files are created in a new `./<slug>/` directory.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
astralkit add saas-starter --workflow
|
|
80
|
+
astralkit add crm --workflow --framework=nextjs
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Use `--overlay` to merge workflow files into your current project instead of creating a new directory:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
astralkit add saas-starter --workflow --overlay
|
|
87
|
+
astralkit add saas-starter --workflow --overlay --overwrite
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Options
|
|
91
|
+
|
|
92
|
+
- `-f, --framework` — Framework version (html, react, nextjs)
|
|
42
93
|
- `--dir` — Override output directory
|
|
43
94
|
- `--overwrite` — Overwrite existing files
|
|
95
|
+
- `--booster` — Install a booster (feature module)
|
|
96
|
+
- `--workflow` — Scaffold a workflow (complete app template)
|
|
97
|
+
- `--overlay` — Merge workflow into current project (workflow only)
|
|
44
98
|
|
|
45
99
|
### `astralkit list`
|
|
46
100
|
|
|
47
|
-
List
|
|
101
|
+
List available content.
|
|
48
102
|
|
|
49
103
|
```bash
|
|
50
|
-
astralkit list
|
|
104
|
+
astralkit list # List components
|
|
105
|
+
astralkit list --boosters # List boosters
|
|
106
|
+
astralkit list --workflows # List workflows
|
|
51
107
|
astralkit list --category=forms
|
|
52
108
|
astralkit list --framework=react
|
|
53
109
|
astralkit list --pro
|
|
@@ -56,11 +112,13 @@ astralkit list --free
|
|
|
56
112
|
|
|
57
113
|
### `astralkit search <query>`
|
|
58
114
|
|
|
59
|
-
Search
|
|
115
|
+
Search by name or description.
|
|
60
116
|
|
|
61
117
|
```bash
|
|
62
118
|
astralkit search "data table"
|
|
63
119
|
astralkit search "pricing" --framework=react
|
|
120
|
+
astralkit search "stripe" --boosters
|
|
121
|
+
astralkit search "crm" --workflows
|
|
64
122
|
```
|
|
65
123
|
|
|
66
124
|
### `astralkit diff <component>`
|
|
@@ -82,7 +140,7 @@ astralkit update button-sizes --force
|
|
|
82
140
|
|
|
83
141
|
### `astralkit login`
|
|
84
142
|
|
|
85
|
-
Authenticate with AstralKit to access premium
|
|
143
|
+
Authenticate with AstralKit to access premium content. Opens your browser for secure login.
|
|
86
144
|
|
|
87
145
|
```bash
|
|
88
146
|
astralkit login
|
|
@@ -96,9 +154,9 @@ Remove stored authentication.
|
|
|
96
154
|
|
|
97
155
|
Show current authentication status and subscription plan. Verifies your token with the server.
|
|
98
156
|
|
|
99
|
-
## Premium
|
|
157
|
+
## Premium Content
|
|
100
158
|
|
|
101
|
-
Some components require a Pro subscription. When you try to add
|
|
159
|
+
Some components, boosters, and workflows require a Pro subscription. When you try to add pro content without authentication:
|
|
102
160
|
|
|
103
161
|
```bash
|
|
104
162
|
$ astralkit add pro-data-table
|
|
@@ -106,7 +164,7 @@ $ astralkit add pro-data-table
|
|
|
106
164
|
Authentication required. Run `astralkit login` to authenticate.
|
|
107
165
|
```
|
|
108
166
|
|
|
109
|
-
After logging in, pro
|
|
167
|
+
After logging in, pro content installs normally:
|
|
110
168
|
|
|
111
169
|
```bash
|
|
112
170
|
$ astralkit login
|
|
@@ -114,8 +172,22 @@ $ astralkit login
|
|
|
114
172
|
Email: you@example.com
|
|
115
173
|
Plan: pro
|
|
116
174
|
|
|
117
|
-
$ astralkit add
|
|
118
|
-
✔ Added
|
|
175
|
+
$ astralkit add stripe-payments --booster
|
|
176
|
+
✔ Added booster Stripe Payments (nextjs)
|
|
177
|
+
Core files → src/lib/stripe-payments/
|
|
178
|
+
lib/stripe.ts
|
|
179
|
+
api/webhooks/stripe/route.ts
|
|
180
|
+
Adapter files → src/components/stripe-payments/
|
|
181
|
+
components/checkout-button.tsx
|
|
182
|
+
hooks/use-subscription.ts
|
|
183
|
+
|
|
184
|
+
Install required dependencies:
|
|
185
|
+
npm install stripe @stripe/stripe-js
|
|
186
|
+
|
|
187
|
+
Add these environment variables to your .env:
|
|
188
|
+
STRIPE_SECRET_KEY=
|
|
189
|
+
STRIPE_PUBLISHABLE_KEY=
|
|
190
|
+
STRIPE_WEBHOOK_SECRET=
|
|
119
191
|
```
|
|
120
192
|
|
|
121
193
|
## Configuration
|
|
@@ -128,8 +200,7 @@ Created by `astralkit init` in your project root:
|
|
|
128
200
|
{
|
|
129
201
|
"$schema": "https://astralkit.com/schema/config.json",
|
|
130
202
|
"framework": "nextjs",
|
|
131
|
-
"componentsDir": "src/components/ui"
|
|
132
|
-
"tokensImport": "@astralkit/tokens/css"
|
|
203
|
+
"componentsDir": "src/components/ui"
|
|
133
204
|
}
|
|
134
205
|
```
|
|
135
206
|
|
|
@@ -147,6 +218,7 @@ export ASTRALKIT_TOKEN="your-api-token"
|
|
|
147
218
|
|
|
148
219
|
# Commands automatically use the env var
|
|
149
220
|
astralkit add button-sizes
|
|
221
|
+
astralkit add stripe-payments --booster
|
|
150
222
|
astralkit whoami
|
|
151
223
|
```
|
|
152
224
|
|
|
@@ -189,7 +261,7 @@ If you see timeout or connection errors, check your internet connection. The CLI
|
|
|
189
261
|
## Requirements
|
|
190
262
|
|
|
191
263
|
- Node.js 18+
|
|
192
|
-
- An AstralKit account for premium
|
|
264
|
+
- An AstralKit account for premium content
|
|
193
265
|
|
|
194
266
|
## Links
|
|
195
267
|
|
package/bin/index.js
CHANGED
|
@@ -18,7 +18,7 @@ const program = new Command();
|
|
|
18
18
|
|
|
19
19
|
program
|
|
20
20
|
.name('astralkit')
|
|
21
|
-
.description('AstralKit CLI — Install and manage UI components')
|
|
21
|
+
.description('AstralKit CLI — Install and manage UI components, boosters, and workflows')
|
|
22
22
|
.version(pkg.version);
|
|
23
23
|
|
|
24
24
|
// ─── init ────────────────────────────────────────────
|
|
@@ -31,11 +31,14 @@ program
|
|
|
31
31
|
|
|
32
32
|
// ─── add ─────────────────────────────────────────────
|
|
33
33
|
program
|
|
34
|
-
.command('add <
|
|
35
|
-
.description('Add a component to your project')
|
|
36
|
-
.option('-f, --framework <framework>', 'Framework version (html, react,
|
|
34
|
+
.command('add <name>')
|
|
35
|
+
.description('Add a component, booster, or workflow to your project')
|
|
36
|
+
.option('-f, --framework <framework>', 'Framework version (html, react, nextjs)')
|
|
37
37
|
.option('--dir <directory>', 'Override output directory')
|
|
38
38
|
.option('--overwrite', 'Overwrite existing files', false)
|
|
39
|
+
.option('--booster', 'Install a booster (feature module)')
|
|
40
|
+
.option('--workflow', 'Scaffold a workflow (complete app template)')
|
|
41
|
+
.option('--overlay', 'Merge workflow into current project (workflow only)')
|
|
39
42
|
.action(addCommand);
|
|
40
43
|
|
|
41
44
|
// ─── login ───────────────────────────────────────────
|
|
@@ -57,18 +60,22 @@ program
|
|
|
57
60
|
// ─── list ────────────────────────────────────────────
|
|
58
61
|
program
|
|
59
62
|
.command('list')
|
|
60
|
-
.description('List available components')
|
|
63
|
+
.description('List available components, boosters, or workflows')
|
|
61
64
|
.option('-c, --category <category>', 'Filter by category')
|
|
62
65
|
.option('--framework <framework>', 'Filter by supported framework')
|
|
63
|
-
.option('--pro', 'Show only pro
|
|
64
|
-
.option('--free', 'Show only free
|
|
66
|
+
.option('--pro', 'Show only pro items', false)
|
|
67
|
+
.option('--free', 'Show only free items', false)
|
|
68
|
+
.option('--boosters', 'List boosters instead of components')
|
|
69
|
+
.option('--workflows', 'List workflows instead of components')
|
|
65
70
|
.action(listCommand);
|
|
66
71
|
|
|
67
72
|
// ─── search ──────────────────────────────────────────
|
|
68
73
|
program
|
|
69
74
|
.command('search <query>')
|
|
70
|
-
.description('Search for components')
|
|
75
|
+
.description('Search for components, boosters, or workflows')
|
|
71
76
|
.option('--framework <framework>', 'Filter by supported framework')
|
|
77
|
+
.option('--boosters', 'Search boosters only')
|
|
78
|
+
.option('--workflows', 'Search workflows only')
|
|
72
79
|
.action(searchCommand);
|
|
73
80
|
|
|
74
81
|
// ─── diff ────────────────────────────────────────────
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astralkit/cli",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "AstralKit CLI — Install and manage UI components in your project",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -28,9 +28,7 @@
|
|
|
28
28
|
"tailwind",
|
|
29
29
|
"cli",
|
|
30
30
|
"react",
|
|
31
|
-
"nextjs"
|
|
32
|
-
"vue",
|
|
33
|
-
"svelte"
|
|
31
|
+
"nextjs"
|
|
34
32
|
],
|
|
35
33
|
"homepage": "https://astralkit.com",
|
|
36
34
|
"repository": {
|
package/src/commands/add.js
CHANGED
|
@@ -2,25 +2,52 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const chalk = require('chalk');
|
|
4
4
|
const ora = require('ora');
|
|
5
|
-
const { getComponent } = require('../lib/api');
|
|
6
|
-
const {
|
|
7
|
-
|
|
5
|
+
const { getComponent, getBooster, getWorkflow } = require('../lib/api');
|
|
6
|
+
const {
|
|
7
|
+
getProjectConfig,
|
|
8
|
+
detectFramework,
|
|
9
|
+
isAstralkitInstalled,
|
|
10
|
+
findCssEntryFile,
|
|
11
|
+
getMissingCssImports,
|
|
12
|
+
addCssImports,
|
|
13
|
+
REQUIRED_CSS_IMPORTS,
|
|
14
|
+
} = require('../lib/config');
|
|
15
|
+
const { validateSlug, validateFramework, isSafePath, writeFiles } = require('../lib/validators');
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Route to the correct add handler based on flags.
|
|
19
|
+
*/
|
|
20
|
+
async function addCommand(nameOrSlug, options) {
|
|
21
|
+
if (options.booster) {
|
|
22
|
+
return addBooster(nameOrSlug, options);
|
|
23
|
+
}
|
|
24
|
+
if (options.workflow) {
|
|
25
|
+
return addWorkflow(nameOrSlug, options);
|
|
26
|
+
}
|
|
27
|
+
return addComponent(nameOrSlug, options);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Add a single UI component.
|
|
32
|
+
* Drops a single file (.html, .jsx, or .tsx) into src/components/ui/.
|
|
33
|
+
* Verifies astralkit npm package is installed and CSS imports are present.
|
|
34
|
+
*/
|
|
35
|
+
async function addComponent(componentSlug, options) {
|
|
11
36
|
if (!validateSlug(componentSlug)) process.exit(1);
|
|
12
|
-
if (!validateFramework(options.framework)) process.exit(1);
|
|
37
|
+
if (options.framework && !validateFramework(options.framework)) process.exit(1);
|
|
13
38
|
|
|
14
|
-
// Resolve framework
|
|
15
39
|
const config = getProjectConfig();
|
|
16
40
|
const framework = options.framework || config?.framework || detectFramework();
|
|
17
41
|
const componentsDir = options.dir || config?.componentsDir || 'src/components/ui';
|
|
18
|
-
const targetDir = path.resolve(process.cwd(), componentsDir, componentSlug);
|
|
19
42
|
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
43
|
+
// For react/nextjs, the API returns a single file — write it directly into componentsDir
|
|
44
|
+
// For html, also a single file
|
|
45
|
+
const ext = framework === 'nextjs' ? '.tsx' : framework === 'react' ? '.jsx' : '.html';
|
|
46
|
+
const targetFile = path.resolve(process.cwd(), componentsDir, `${componentSlug}${ext}`);
|
|
47
|
+
|
|
48
|
+
if (fs.existsSync(targetFile) && !options.overwrite) {
|
|
49
|
+
console.log(chalk.yellow(`Component already exists: ${componentsDir}/${componentSlug}${ext}`));
|
|
50
|
+
console.log(chalk.gray('Use --overwrite to replace.'));
|
|
24
51
|
return;
|
|
25
52
|
}
|
|
26
53
|
|
|
@@ -37,39 +64,56 @@ async function addCommand(componentSlug, options) {
|
|
|
37
64
|
return;
|
|
38
65
|
}
|
|
39
66
|
|
|
40
|
-
//
|
|
41
|
-
|
|
67
|
+
// Write the component file(s)
|
|
68
|
+
const dir = path.resolve(process.cwd(), componentsDir);
|
|
69
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
42
70
|
|
|
43
|
-
// Write each file (with path traversal protection)
|
|
44
71
|
for (const file of data.files) {
|
|
45
|
-
if (!isSafePath(
|
|
72
|
+
if (!isSafePath(dir, file.path)) {
|
|
46
73
|
console.log(chalk.red(` Skipping suspicious file path: ${file.path}`));
|
|
47
74
|
continue;
|
|
48
75
|
}
|
|
49
|
-
const filePath = path.resolve(
|
|
50
|
-
|
|
51
|
-
if (!fs.existsSync(fileDir)) {
|
|
52
|
-
fs.mkdirSync(fileDir, { recursive: true });
|
|
53
|
-
}
|
|
76
|
+
const filePath = path.resolve(dir, file.path);
|
|
77
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
54
78
|
fs.writeFileSync(filePath, file.content);
|
|
55
79
|
}
|
|
56
80
|
|
|
57
81
|
spinner.succeed(`Added ${chalk.cyan(data.name || componentSlug)} (${framework})`);
|
|
58
82
|
|
|
59
|
-
|
|
60
|
-
console.log(chalk.gray(` ${componentsDir}/${componentSlug}/`));
|
|
83
|
+
console.log(chalk.gray(` ${componentsDir}/`));
|
|
61
84
|
for (const file of data.files) {
|
|
62
85
|
console.log(chalk.gray(` ${file.path}`));
|
|
63
86
|
}
|
|
64
87
|
|
|
65
|
-
//
|
|
66
|
-
if (
|
|
88
|
+
// ─── Post-install checks for react/nextjs ──────────────
|
|
89
|
+
if (framework !== 'html') {
|
|
67
90
|
console.log();
|
|
68
|
-
|
|
69
|
-
|
|
91
|
+
|
|
92
|
+
// Check astralkit npm package
|
|
93
|
+
if (!isAstralkitInstalled()) {
|
|
94
|
+
console.log(chalk.yellow('astralkit package not found.'));
|
|
95
|
+
console.log(chalk.cyan(' npm install astralkit'));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Check CSS imports
|
|
99
|
+
const cssEntry = findCssEntryFile();
|
|
100
|
+
if (cssEntry) {
|
|
101
|
+
const missing = getMissingCssImports(cssEntry.path);
|
|
102
|
+
if (missing.length > 0) {
|
|
103
|
+
console.log(chalk.yellow(`Missing CSS imports in ${cssEntry.relative}:`));
|
|
104
|
+
for (const imp of missing) {
|
|
105
|
+
console.log(chalk.cyan(` ${imp}`));
|
|
106
|
+
}
|
|
107
|
+
console.log(chalk.gray('Run `astralkit init` to set up automatically.'));
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
console.log(chalk.yellow('No CSS entry file found. Add these to your main CSS:'));
|
|
111
|
+
for (const imp of REQUIRED_CSS_IMPORTS) {
|
|
112
|
+
console.log(chalk.cyan(` ${imp}`));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
70
115
|
}
|
|
71
116
|
|
|
72
|
-
// Pro badge
|
|
73
117
|
if (data.is_pro) {
|
|
74
118
|
console.log();
|
|
75
119
|
console.log(chalk.magenta('Pro component — thank you for your subscription!'));
|
|
@@ -77,28 +121,223 @@ async function addCommand(componentSlug, options) {
|
|
|
77
121
|
|
|
78
122
|
} catch (err) {
|
|
79
123
|
spinner.fail('Failed to add component.');
|
|
124
|
+
handleAddError(err, componentSlug, framework);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Add a booster (multi-file feature module with core + adapter).
|
|
130
|
+
*/
|
|
131
|
+
async function addBooster(slug, options) {
|
|
132
|
+
if (!validateSlug(slug, 'booster name')) process.exit(1);
|
|
133
|
+
if (options.framework && !validateFramework(options.framework)) process.exit(1);
|
|
134
|
+
|
|
135
|
+
const config = getProjectConfig();
|
|
136
|
+
const framework = options.framework || config?.framework || detectFramework();
|
|
137
|
+
|
|
138
|
+
const spinner = ora(`Fetching booster ${slug} (${framework})...`).start();
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
const data = await getBooster(slug, framework);
|
|
142
|
+
|
|
143
|
+
const coreFiles = data.core_files || [];
|
|
144
|
+
const adapterFiles = data.adapter_files || [];
|
|
80
145
|
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
146
|
+
if (coreFiles.length === 0 && adapterFiles.length === 0) {
|
|
147
|
+
spinner.fail(`No files available for booster "${slug}" (${framework}).`);
|
|
148
|
+
if (data.frameworks?.length) {
|
|
149
|
+
console.log(chalk.gray(`Available frameworks: ${data.frameworks.join(', ')}`));
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Resolve install paths
|
|
155
|
+
const corePath = options.dir || data.install_paths?.core || `src/lib/${slug}`;
|
|
156
|
+
const adapterPath = data.install_paths?.adapter || `src/components/${slug}`;
|
|
157
|
+
const coreDir = path.resolve(process.cwd(), corePath);
|
|
158
|
+
const adapterDir = path.resolve(process.cwd(), adapterPath);
|
|
159
|
+
|
|
160
|
+
// Check for existing files
|
|
161
|
+
if (!options.overwrite) {
|
|
162
|
+
const conflicts = [];
|
|
163
|
+
for (const file of coreFiles) {
|
|
164
|
+
const fp = path.resolve(coreDir, file.path);
|
|
165
|
+
if (fs.existsSync(fp)) conflicts.push(`${corePath}/${file.path}`);
|
|
166
|
+
}
|
|
167
|
+
for (const file of adapterFiles) {
|
|
168
|
+
const fp = path.resolve(adapterDir, file.path);
|
|
169
|
+
if (fs.existsSync(fp)) conflicts.push(`${adapterPath}/${file.path}`);
|
|
170
|
+
}
|
|
171
|
+
if (conflicts.length > 0) {
|
|
172
|
+
spinner.fail('Some files already exist.');
|
|
173
|
+
console.log(chalk.yellow('Conflicting files:'));
|
|
174
|
+
for (const c of conflicts) {
|
|
175
|
+
console.log(chalk.gray(` ${c}`));
|
|
176
|
+
}
|
|
177
|
+
console.log(chalk.gray('Use --overwrite to replace existing files.'));
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Write core + adapter files
|
|
183
|
+
const coreCount = writeFiles(coreDir, coreFiles);
|
|
184
|
+
const adapterCount = writeFiles(adapterDir, adapterFiles);
|
|
185
|
+
|
|
186
|
+
spinner.succeed(`Added booster ${chalk.cyan(data.name || slug)} (${framework})`);
|
|
187
|
+
|
|
188
|
+
// Show files written
|
|
189
|
+
if (coreCount > 0) {
|
|
190
|
+
console.log(chalk.gray(` Core files → ${corePath}/`));
|
|
191
|
+
for (const file of coreFiles) {
|
|
192
|
+
console.log(chalk.gray(` ${file.path}`));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (adapterCount > 0) {
|
|
196
|
+
console.log(chalk.gray(` Adapter files → ${adapterPath}/`));
|
|
197
|
+
for (const file of adapterFiles) {
|
|
198
|
+
console.log(chalk.gray(` ${file.path}`));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
printPostInstallInfo(data);
|
|
203
|
+
|
|
204
|
+
if (data.is_pro) {
|
|
205
|
+
console.log();
|
|
206
|
+
console.log(chalk.magenta('Pro booster — thank you for your subscription!'));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
} catch (err) {
|
|
210
|
+
spinner.fail('Failed to add booster.');
|
|
211
|
+
handleAddError(err, slug, framework);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Add a workflow (complete application scaffold).
|
|
217
|
+
*/
|
|
218
|
+
async function addWorkflow(slug, options) {
|
|
219
|
+
if (!validateSlug(slug, 'workflow name')) process.exit(1);
|
|
220
|
+
if (options.framework && !validateFramework(options.framework)) process.exit(1);
|
|
221
|
+
|
|
222
|
+
const config = getProjectConfig();
|
|
223
|
+
const framework = options.framework || config?.framework || detectFramework();
|
|
224
|
+
|
|
225
|
+
const spinner = ora(`Fetching workflow ${slug} (${framework})...`).start();
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
const data = await getWorkflow(slug, framework);
|
|
229
|
+
|
|
230
|
+
if (!data.files || data.files.length === 0) {
|
|
231
|
+
spinner.fail(`No files available for workflow "${slug}" (${framework}).`);
|
|
232
|
+
if (data.frameworks?.length) {
|
|
233
|
+
console.log(chalk.gray(`Available frameworks: ${data.frameworks.join(', ')}`));
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Determine target directory
|
|
239
|
+
let targetDir;
|
|
240
|
+
if (options.overlay) {
|
|
241
|
+
targetDir = path.resolve(process.cwd());
|
|
85
242
|
} else {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
243
|
+
const dirName = options.dir || slug;
|
|
244
|
+
targetDir = path.resolve(process.cwd(), dirName);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Check for conflicts in overlay mode
|
|
248
|
+
if (options.overlay && !options.overwrite) {
|
|
249
|
+
const conflicts = [];
|
|
250
|
+
for (const file of data.files) {
|
|
251
|
+
const fp = path.resolve(targetDir, file.path);
|
|
252
|
+
if (fs.existsSync(fp)) conflicts.push(file.path);
|
|
253
|
+
}
|
|
254
|
+
if (conflicts.length > 0) {
|
|
255
|
+
spinner.fail(`${conflicts.length} file(s) would be overwritten.`);
|
|
256
|
+
console.log(chalk.yellow('Conflicting files:'));
|
|
257
|
+
for (const c of conflicts.slice(0, 20)) {
|
|
258
|
+
console.log(chalk.gray(` ${c}`));
|
|
259
|
+
}
|
|
260
|
+
if (conflicts.length > 20) {
|
|
261
|
+
console.log(chalk.gray(` ... and ${conflicts.length - 20} more`));
|
|
94
262
|
}
|
|
95
|
-
|
|
96
|
-
|
|
263
|
+
console.log(chalk.gray('Use --overwrite to replace existing files.'));
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Check if target directory exists (non-overlay)
|
|
269
|
+
if (!options.overlay && fs.existsSync(targetDir) && !options.overwrite) {
|
|
270
|
+
spinner.fail(`Directory "${slug}/" already exists.`);
|
|
271
|
+
console.log(chalk.gray('Use --overwrite to replace, or --dir to specify a different name.'));
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Write files
|
|
276
|
+
const fileCount = writeFiles(targetDir, data.files);
|
|
277
|
+
|
|
278
|
+
const targetLabel = options.overlay ? './' : `${slug}/`;
|
|
279
|
+
spinner.succeed(`Scaffolded workflow ${chalk.cyan(data.name || slug)} (${framework}) → ${targetLabel}`);
|
|
280
|
+
|
|
281
|
+
console.log(chalk.gray(` ${fileCount} files written to ${targetLabel}`));
|
|
282
|
+
|
|
283
|
+
printPostInstallInfo(data, { npmPrefix: options.overlay ? '' : `cd ${slug} && ` });
|
|
284
|
+
|
|
285
|
+
if (data.is_pro) {
|
|
286
|
+
console.log();
|
|
287
|
+
console.log(chalk.magenta('Pro workflow — thank you for your subscription!'));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
} catch (err) {
|
|
291
|
+
spinner.fail('Failed to add workflow.');
|
|
292
|
+
handleAddError(err, slug, framework);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Print post-install info (deps, env vars, setup instructions).
|
|
298
|
+
*/
|
|
299
|
+
function printPostInstallInfo(data, { npmPrefix = '' } = {}) {
|
|
300
|
+
if (data.dependencies?.npm?.length) {
|
|
301
|
+
console.log();
|
|
302
|
+
console.log(chalk.yellow('Install required dependencies:'));
|
|
303
|
+
console.log(chalk.cyan(` ${npmPrefix}npm install ${data.dependencies.npm.join(' ')}`));
|
|
304
|
+
}
|
|
305
|
+
if (data.dependencies?.env?.length) {
|
|
306
|
+
console.log();
|
|
307
|
+
console.log(chalk.yellow('Add these environment variables to your .env:'));
|
|
308
|
+
for (const envVar of data.dependencies.env) {
|
|
309
|
+
console.log(chalk.gray(` ${envVar}=`));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (data.post_install) {
|
|
313
|
+
console.log();
|
|
314
|
+
console.log(chalk.white.bold('Setup instructions:'));
|
|
315
|
+
console.log(chalk.gray(data.post_install));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Shared error handler for add commands.
|
|
321
|
+
*/
|
|
322
|
+
function handleAddError(err, slug, framework) {
|
|
323
|
+
if (err.code === 'AUTH_REQUIRED') {
|
|
324
|
+
console.log(chalk.yellow(err.message));
|
|
325
|
+
} else if (err.code === 'PRO_REQUIRED') {
|
|
326
|
+
console.log(chalk.yellow(err.message));
|
|
327
|
+
} else {
|
|
328
|
+
try {
|
|
329
|
+
const body = JSON.parse(err.message.replace(/^API error \d+: /, ''));
|
|
330
|
+
if (body.supported_frameworks) {
|
|
331
|
+
console.log(chalk.yellow(`No ${framework} version available for "${slug}".`));
|
|
332
|
+
console.log(chalk.gray(`Available frameworks: ${body.supported_frameworks.join(', ')}`));
|
|
333
|
+
process.exit(1);
|
|
97
334
|
}
|
|
98
|
-
|
|
335
|
+
} catch {
|
|
336
|
+
// Not a JSON parse error
|
|
99
337
|
}
|
|
100
|
-
|
|
338
|
+
console.error(chalk.red(err.message));
|
|
101
339
|
}
|
|
340
|
+
process.exit(1);
|
|
102
341
|
}
|
|
103
342
|
|
|
104
343
|
module.exports = { addCommand };
|
package/src/commands/diff.js
CHANGED
|
@@ -79,7 +79,7 @@ async function diffCommand(componentSlug, options) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// Check for local files not on remote
|
|
82
|
-
|
|
82
|
+
{
|
|
83
83
|
const localFiles = fs.readdirSync(targetDir);
|
|
84
84
|
const remoteFilenames = new Set(data.files.map(f => f.path));
|
|
85
85
|
for (const localFile of localFiles) {
|
package/src/commands/init.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
1
3
|
const chalk = require('chalk');
|
|
2
4
|
const inquirer = require('inquirer');
|
|
3
|
-
const
|
|
5
|
+
const ora = require('ora');
|
|
6
|
+
const { execSync } = require('child_process');
|
|
7
|
+
const {
|
|
8
|
+
detectFramework,
|
|
9
|
+
defaultConfig,
|
|
10
|
+
writeProjectConfig,
|
|
11
|
+
getProjectConfig,
|
|
12
|
+
CONFIG_FILENAME,
|
|
13
|
+
isAstralkitInstalled,
|
|
14
|
+
findCssEntryFile,
|
|
15
|
+
getMissingCssImports,
|
|
16
|
+
addCssImports,
|
|
17
|
+
REQUIRED_CSS_IMPORTS,
|
|
18
|
+
} = require('../lib/config');
|
|
4
19
|
const { validateFramework } = require('../lib/validators');
|
|
5
20
|
|
|
6
21
|
async function initCommand(options) {
|
|
@@ -42,12 +57,8 @@ async function initCommand(options) {
|
|
|
42
57
|
{ name: `${detected} (detected)`, value: detected },
|
|
43
58
|
{ name: 'HTML + Tailwind', value: 'html' },
|
|
44
59
|
{ name: 'React', value: 'react' },
|
|
45
|
-
{ name: 'Vue', value: 'vue' },
|
|
46
60
|
{ name: 'Next.js', value: 'nextjs' },
|
|
47
|
-
|
|
48
|
-
{ name: 'Svelte', value: 'svelte' },
|
|
49
|
-
{ name: 'Astro', value: 'astro' },
|
|
50
|
-
].filter((c, i, arr) => {
|
|
61
|
+
].filter((c, i) => {
|
|
51
62
|
// Remove duplicate if detected matches a named option
|
|
52
63
|
if (i === 0) return true;
|
|
53
64
|
return c.value !== detected;
|
|
@@ -60,10 +71,60 @@ async function initCommand(options) {
|
|
|
60
71
|
// Component directory
|
|
61
72
|
const componentDir = options.dir || 'src/components/ui';
|
|
62
73
|
|
|
63
|
-
//
|
|
74
|
+
// ─── Step 1: Install astralkit npm package ──────────────
|
|
75
|
+
if (framework !== 'html') {
|
|
76
|
+
if (!isAstralkitInstalled()) {
|
|
77
|
+
const spinner = ora('Installing astralkit...').start();
|
|
78
|
+
try {
|
|
79
|
+
const pm = detectPackageManager();
|
|
80
|
+
const installCmd = pm === 'yarn' ? 'yarn add astralkit'
|
|
81
|
+
: pm === 'pnpm' ? 'pnpm add astralkit'
|
|
82
|
+
: pm === 'bun' ? 'bun add astralkit'
|
|
83
|
+
: 'npm install astralkit';
|
|
84
|
+
execSync(installCmd, { stdio: 'pipe', cwd: process.cwd() });
|
|
85
|
+
spinner.succeed('Installed astralkit');
|
|
86
|
+
} catch (err) {
|
|
87
|
+
spinner.fail('Failed to install astralkit');
|
|
88
|
+
console.log(chalk.yellow('Run manually: npm install astralkit'));
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
console.log(chalk.gray(' astralkit already installed'));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ─── Step 2: Add CSS imports ────────────────────────────
|
|
96
|
+
const cssEntry = findCssEntryFile();
|
|
97
|
+
if (cssEntry) {
|
|
98
|
+
const missing = getMissingCssImports(cssEntry.path);
|
|
99
|
+
if (missing.length > 0) {
|
|
100
|
+
console.log();
|
|
101
|
+
console.log(chalk.gray(`Found CSS entry: ${cssEntry.relative}`));
|
|
102
|
+
const { addImports } = await inquirer.prompt([{
|
|
103
|
+
type: 'confirm',
|
|
104
|
+
name: 'addImports',
|
|
105
|
+
message: `Add AstralKit imports to ${cssEntry.relative}?`,
|
|
106
|
+
default: true,
|
|
107
|
+
}]);
|
|
108
|
+
if (addImports) {
|
|
109
|
+
addCssImports(cssEntry.path, missing);
|
|
110
|
+
console.log(chalk.green(' Added CSS imports'));
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
console.log(chalk.gray(' CSS imports already present'));
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
console.log();
|
|
117
|
+
console.log(chalk.yellow('No CSS entry file found.'));
|
|
118
|
+
console.log(chalk.gray('Add these imports to your main CSS file:'));
|
|
119
|
+
for (const imp of REQUIRED_CSS_IMPORTS) {
|
|
120
|
+
console.log(chalk.cyan(` ${imp}`));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ─── Step 3: Write config ──────────────────────────────
|
|
64
125
|
const config = defaultConfig(framework);
|
|
65
126
|
config.componentsDir = componentDir;
|
|
66
|
-
|
|
127
|
+
writeProjectConfig(config);
|
|
67
128
|
|
|
68
129
|
console.log();
|
|
69
130
|
console.log(chalk.green('Created'), chalk.cyan(CONFIG_FILENAME));
|
|
@@ -71,9 +132,19 @@ async function initCommand(options) {
|
|
|
71
132
|
console.log(chalk.gray(` Components: ${componentDir}/`));
|
|
72
133
|
console.log();
|
|
73
134
|
console.log(chalk.green('Next steps:'));
|
|
74
|
-
console.log(chalk.gray(' astralkit add
|
|
75
|
-
console.log(chalk.gray(' astralkit list
|
|
76
|
-
console.log(chalk.gray(' astralkit login
|
|
135
|
+
console.log(chalk.gray(' astralkit add sidebar-expanded-light Add a component'));
|
|
136
|
+
console.log(chalk.gray(' astralkit list Browse components'));
|
|
137
|
+
console.log(chalk.gray(' astralkit login Unlock pro components'));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Detect which package manager the project uses.
|
|
142
|
+
*/
|
|
143
|
+
function detectPackageManager(dir = process.cwd()) {
|
|
144
|
+
if (fs.existsSync(path.join(dir, 'bun.lockb')) || fs.existsSync(path.join(dir, 'bun.lock'))) return 'bun';
|
|
145
|
+
if (fs.existsSync(path.join(dir, 'pnpm-lock.yaml'))) return 'pnpm';
|
|
146
|
+
if (fs.existsSync(path.join(dir, 'yarn.lock'))) return 'yarn';
|
|
147
|
+
return 'npm';
|
|
77
148
|
}
|
|
78
149
|
|
|
79
150
|
module.exports = { initCommand };
|
package/src/commands/list.js
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
2
|
const ora = require('ora');
|
|
3
|
-
const { listComponents } = require('../lib/api');
|
|
3
|
+
const { listComponents, listBoosters, listWorkflows } = require('../lib/api');
|
|
4
4
|
const { validateFramework } = require('../lib/validators');
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Route to the correct list handler based on flags.
|
|
8
|
+
*/
|
|
6
9
|
async function listCommand(options) {
|
|
7
|
-
// Validate --framework if provided
|
|
8
10
|
if (options.framework && !validateFramework(options.framework)) {
|
|
9
11
|
process.exit(1);
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
if (options.boosters) {
|
|
15
|
+
return listBoostersCommand(options);
|
|
16
|
+
}
|
|
17
|
+
if (options.workflows) {
|
|
18
|
+
return listWorkflowsCommand(options);
|
|
19
|
+
}
|
|
20
|
+
return listComponentsCommand(options);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* List UI components (existing behavior).
|
|
25
|
+
*/
|
|
26
|
+
async function listComponentsCommand(options) {
|
|
12
27
|
const spinner = ora('Fetching components...').start();
|
|
13
28
|
|
|
14
29
|
try {
|
|
@@ -26,7 +41,6 @@ async function listCommand(options) {
|
|
|
26
41
|
return;
|
|
27
42
|
}
|
|
28
43
|
|
|
29
|
-
// Group by category
|
|
30
44
|
const grouped = {};
|
|
31
45
|
for (const comp of data.components) {
|
|
32
46
|
const cat = comp.category || 'Uncategorized';
|
|
@@ -61,4 +75,112 @@ async function listCommand(options) {
|
|
|
61
75
|
}
|
|
62
76
|
}
|
|
63
77
|
|
|
78
|
+
/**
|
|
79
|
+
* List available boosters.
|
|
80
|
+
*/
|
|
81
|
+
async function listBoostersCommand(options) {
|
|
82
|
+
const spinner = ora('Fetching boosters...').start();
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const data = await listBoosters({
|
|
86
|
+
framework: options.framework,
|
|
87
|
+
pro: options.pro,
|
|
88
|
+
free: options.free,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
spinner.stop();
|
|
92
|
+
|
|
93
|
+
if (!data.boosters || data.boosters.length === 0) {
|
|
94
|
+
console.log(chalk.yellow('No boosters found.'));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const grouped = {};
|
|
99
|
+
for (const booster of data.boosters) {
|
|
100
|
+
const cat = booster.category || 'Uncategorized';
|
|
101
|
+
if (!grouped[cat]) grouped[cat] = [];
|
|
102
|
+
grouped[cat].push(booster);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log(chalk.blue.bold(`AstralKit Boosters (${data.boosters.length} total)`));
|
|
106
|
+
console.log();
|
|
107
|
+
|
|
108
|
+
for (const [category, boosters] of Object.entries(grouped)) {
|
|
109
|
+
console.log(chalk.white.bold(` ${category}`));
|
|
110
|
+
for (const b of boosters) {
|
|
111
|
+
const proTag = b.is_pro ? chalk.magenta(' PRO') : '';
|
|
112
|
+
const frameworks = b.frameworks?.length
|
|
113
|
+
? chalk.gray(` [${b.frameworks.join(', ')}]`)
|
|
114
|
+
: '';
|
|
115
|
+
console.log(` ${chalk.cyan(b.slug)}${proTag}${frameworks}`);
|
|
116
|
+
if (b.description) {
|
|
117
|
+
console.log(` ${chalk.gray(b.description)}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
console.log();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
console.log(chalk.gray('Run'), chalk.cyan('astralkit add --booster <name>'), chalk.gray('to install.'));
|
|
124
|
+
|
|
125
|
+
} catch (err) {
|
|
126
|
+
spinner.fail('Failed to list boosters.');
|
|
127
|
+
console.error(chalk.red(err.message));
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* List available workflows.
|
|
134
|
+
*/
|
|
135
|
+
async function listWorkflowsCommand(options) {
|
|
136
|
+
const spinner = ora('Fetching workflows...').start();
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const data = await listWorkflows({
|
|
140
|
+
framework: options.framework,
|
|
141
|
+
pro: options.pro,
|
|
142
|
+
free: options.free,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
spinner.stop();
|
|
146
|
+
|
|
147
|
+
if (!data.workflows || data.workflows.length === 0) {
|
|
148
|
+
console.log(chalk.yellow('No workflows found.'));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const grouped = {};
|
|
153
|
+
for (const workflow of data.workflows) {
|
|
154
|
+
const cat = workflow.category || 'Uncategorized';
|
|
155
|
+
if (!grouped[cat]) grouped[cat] = [];
|
|
156
|
+
grouped[cat].push(workflow);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
console.log(chalk.blue.bold(`AstralKit Workflows (${data.workflows.length} total)`));
|
|
160
|
+
console.log();
|
|
161
|
+
|
|
162
|
+
for (const [category, workflows] of Object.entries(grouped)) {
|
|
163
|
+
console.log(chalk.white.bold(` ${category}`));
|
|
164
|
+
for (const w of workflows) {
|
|
165
|
+
const proTag = w.is_pro ? chalk.magenta(' PRO') : '';
|
|
166
|
+
const frameworks = w.frameworks?.length
|
|
167
|
+
? chalk.gray(` [${w.frameworks.join(', ')}]`)
|
|
168
|
+
: '';
|
|
169
|
+
console.log(` ${chalk.cyan(w.slug)}${proTag}${frameworks}`);
|
|
170
|
+
if (w.description) {
|
|
171
|
+
console.log(` ${chalk.gray(w.description)}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
console.log();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
console.log(chalk.gray('Run'), chalk.cyan('astralkit add --workflow <name>'), chalk.gray('to scaffold.'));
|
|
178
|
+
|
|
179
|
+
} catch (err) {
|
|
180
|
+
spinner.fail('Failed to list workflows.');
|
|
181
|
+
console.error(chalk.red(err.message));
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
64
186
|
module.exports = { listCommand };
|
package/src/commands/search.js
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
2
|
const ora = require('ora');
|
|
3
|
-
const { listComponents } = require('../lib/api');
|
|
3
|
+
const { listComponents, listBoosters, listWorkflows } = require('../lib/api');
|
|
4
4
|
const { validateFramework } = require('../lib/validators');
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Route to the correct search handler based on flags.
|
|
8
|
+
*/
|
|
6
9
|
async function searchCommand(query, options) {
|
|
7
|
-
// Validate --framework if provided
|
|
8
10
|
if (options.framework && !validateFramework(options.framework)) {
|
|
9
11
|
process.exit(1);
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
if (options.boosters) {
|
|
15
|
+
return searchBoostersCommand(query, options);
|
|
16
|
+
}
|
|
17
|
+
if (options.workflows) {
|
|
18
|
+
return searchWorkflowsCommand(query, options);
|
|
19
|
+
}
|
|
20
|
+
return searchComponentsCommand(query, options);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Search UI components (existing behavior).
|
|
25
|
+
*/
|
|
26
|
+
async function searchComponentsCommand(query, options) {
|
|
12
27
|
const spinner = ora(`Searching for "${query}"...`).start();
|
|
13
28
|
|
|
14
29
|
try {
|
|
@@ -50,4 +65,92 @@ async function searchCommand(query, options) {
|
|
|
50
65
|
}
|
|
51
66
|
}
|
|
52
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Search boosters.
|
|
70
|
+
*/
|
|
71
|
+
async function searchBoostersCommand(query, options) {
|
|
72
|
+
const spinner = ora(`Searching boosters for "${query}"...`).start();
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const data = await listBoosters({
|
|
76
|
+
search: query,
|
|
77
|
+
framework: options.framework,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
spinner.stop();
|
|
81
|
+
|
|
82
|
+
if (!data.boosters || data.boosters.length === 0) {
|
|
83
|
+
console.log(chalk.yellow(`No boosters found for "${query}".`));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log(chalk.blue.bold(`Found ${data.boosters.length} booster(s):`));
|
|
88
|
+
console.log();
|
|
89
|
+
|
|
90
|
+
for (const b of data.boosters) {
|
|
91
|
+
const proTag = b.is_pro ? chalk.magenta(' PRO') : '';
|
|
92
|
+
const cat = b.category ? chalk.gray(` (${b.category})`) : '';
|
|
93
|
+
console.log(` ${chalk.cyan(b.slug)}${proTag}${cat}`);
|
|
94
|
+
if (b.description) {
|
|
95
|
+
console.log(` ${chalk.gray(b.description.length > 80 ? b.description.slice(0, 80) + '...' : b.description)}`);
|
|
96
|
+
}
|
|
97
|
+
if (b.frameworks?.length) {
|
|
98
|
+
console.log(` ${chalk.gray(`Frameworks: ${b.frameworks.join(', ')}`)}`);
|
|
99
|
+
}
|
|
100
|
+
console.log();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.log(chalk.gray('Run'), chalk.cyan('astralkit add --booster <name>'), chalk.gray('to install.'));
|
|
104
|
+
|
|
105
|
+
} catch (err) {
|
|
106
|
+
spinner.fail('Search failed.');
|
|
107
|
+
console.error(chalk.red(err.message));
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Search workflows.
|
|
114
|
+
*/
|
|
115
|
+
async function searchWorkflowsCommand(query, options) {
|
|
116
|
+
const spinner = ora(`Searching workflows for "${query}"...`).start();
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const data = await listWorkflows({
|
|
120
|
+
search: query,
|
|
121
|
+
framework: options.framework,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
spinner.stop();
|
|
125
|
+
|
|
126
|
+
if (!data.workflows || data.workflows.length === 0) {
|
|
127
|
+
console.log(chalk.yellow(`No workflows found for "${query}".`));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
console.log(chalk.blue.bold(`Found ${data.workflows.length} workflow(s):`));
|
|
132
|
+
console.log();
|
|
133
|
+
|
|
134
|
+
for (const w of data.workflows) {
|
|
135
|
+
const proTag = w.is_pro ? chalk.magenta(' PRO') : '';
|
|
136
|
+
const cat = w.category ? chalk.gray(` (${w.category})`) : '';
|
|
137
|
+
console.log(` ${chalk.cyan(w.slug)}${proTag}${cat}`);
|
|
138
|
+
if (w.description) {
|
|
139
|
+
console.log(` ${chalk.gray(w.description.length > 80 ? w.description.slice(0, 80) + '...' : w.description)}`);
|
|
140
|
+
}
|
|
141
|
+
if (w.frameworks?.length) {
|
|
142
|
+
console.log(` ${chalk.gray(`Frameworks: ${w.frameworks.join(', ')}`)}`);
|
|
143
|
+
}
|
|
144
|
+
console.log();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
console.log(chalk.gray('Run'), chalk.cyan('astralkit add --workflow <name>'), chalk.gray('to scaffold.'));
|
|
148
|
+
|
|
149
|
+
} catch (err) {
|
|
150
|
+
spinner.fail('Search failed.');
|
|
151
|
+
console.error(chalk.red(err.message));
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
53
156
|
module.exports = { searchCommand };
|
package/src/commands/update.js
CHANGED
|
@@ -101,10 +101,7 @@ async function updateCommand(componentSlug, options) {
|
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
103
|
const filePath = path.resolve(targetDir, file.path);
|
|
104
|
-
|
|
105
|
-
if (!fs.existsSync(fileDir)) {
|
|
106
|
-
fs.mkdirSync(fileDir, { recursive: true });
|
|
107
|
-
}
|
|
104
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
108
105
|
fs.writeFileSync(filePath, file.content);
|
|
109
106
|
}
|
|
110
107
|
|
package/src/lib/api.js
CHANGED
|
@@ -136,4 +136,56 @@ async function verifyAuth() {
|
|
|
136
136
|
return response.json();
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
/**
|
|
140
|
+
* List boosters with optional filters.
|
|
141
|
+
*/
|
|
142
|
+
async function listBoosters({ framework, search, pro, free } = {}) {
|
|
143
|
+
const params = new URLSearchParams();
|
|
144
|
+
if (framework) params.set('framework', framework);
|
|
145
|
+
if (pro) params.set('pro', 'true');
|
|
146
|
+
if (free) params.set('free', 'true');
|
|
147
|
+
if (search) params.set('search', search);
|
|
148
|
+
|
|
149
|
+
const response = await apiRequest(`/api/cli/boosters?${params}`);
|
|
150
|
+
return response.json();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get a single booster's details + files for installation.
|
|
155
|
+
*/
|
|
156
|
+
async function getBooster(slug, framework = 'nextjs') {
|
|
157
|
+
const response = await apiRequest(
|
|
158
|
+
`/api/cli/boosters/${encodeURIComponent(slug)}?framework=${encodeURIComponent(framework)}`
|
|
159
|
+
);
|
|
160
|
+
return response.json();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* List workflows with optional filters.
|
|
165
|
+
*/
|
|
166
|
+
async function listWorkflows({ framework, search, pro, free } = {}) {
|
|
167
|
+
const params = new URLSearchParams();
|
|
168
|
+
if (framework) params.set('framework', framework);
|
|
169
|
+
if (pro) params.set('pro', 'true');
|
|
170
|
+
if (free) params.set('free', 'true');
|
|
171
|
+
if (search) params.set('search', search);
|
|
172
|
+
|
|
173
|
+
const response = await apiRequest(`/api/cli/workflows?${params}`);
|
|
174
|
+
return response.json();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Get a single workflow's details + files for scaffolding.
|
|
179
|
+
*/
|
|
180
|
+
async function getWorkflow(slug, framework = 'nextjs') {
|
|
181
|
+
const response = await apiRequest(
|
|
182
|
+
`/api/cli/workflows/${encodeURIComponent(slug)}?framework=${encodeURIComponent(framework)}`
|
|
183
|
+
);
|
|
184
|
+
return response.json();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
module.exports = {
|
|
188
|
+
apiRequest, listComponents, getComponent, verifyAuth,
|
|
189
|
+
listBoosters, getBooster, listWorkflows, getWorkflow,
|
|
190
|
+
API_BASE, CLI_VERSION,
|
|
191
|
+
};
|
package/src/lib/config.js
CHANGED
|
@@ -11,7 +11,6 @@ function defaultConfig(framework = 'html') {
|
|
|
11
11
|
$schema: 'https://astralkit.com/schema/config.json',
|
|
12
12
|
framework,
|
|
13
13
|
componentsDir: 'src/components/ui',
|
|
14
|
-
tokensImport: '@astralkit/tokens/css',
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
16
|
|
|
@@ -70,33 +69,12 @@ function detectFramework(dir = process.cwd()) {
|
|
|
70
69
|
return 'nextjs';
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
// Check for
|
|
74
|
-
if (fs.existsSync(path.join(dir, 'nuxt.config.ts')) || fs.existsSync(path.join(dir, 'nuxt.config.js'))) {
|
|
75
|
-
return 'vue';
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Check for Svelte
|
|
79
|
-
if (fs.existsSync(path.join(dir, 'svelte.config.js')) || fs.existsSync(path.join(dir, 'svelte.config.ts'))) {
|
|
80
|
-
return 'svelte';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Check for Astro
|
|
84
|
-
if (fs.existsSync(path.join(dir, 'astro.config.mjs')) || fs.existsSync(path.join(dir, 'astro.config.ts'))) {
|
|
85
|
-
return 'astro';
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Check for Angular
|
|
89
|
-
if (fs.existsSync(path.join(dir, 'angular.json'))) {
|
|
90
|
-
return 'angular';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Check package.json for Vue/React
|
|
72
|
+
// Check package.json for React
|
|
94
73
|
const pkgPath = path.join(dir, 'package.json');
|
|
95
74
|
if (fs.existsSync(pkgPath)) {
|
|
96
75
|
try {
|
|
97
76
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
98
77
|
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
99
|
-
if (allDeps['vue']) return 'vue';
|
|
100
78
|
if (allDeps['react']) return 'react';
|
|
101
79
|
} catch {
|
|
102
80
|
// Ignore
|
|
@@ -106,6 +84,69 @@ function detectFramework(dir = process.cwd()) {
|
|
|
106
84
|
return 'html';
|
|
107
85
|
}
|
|
108
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Check if the astralkit npm package is installed in the project.
|
|
89
|
+
*/
|
|
90
|
+
function isAstralkitInstalled(dir = process.cwd()) {
|
|
91
|
+
return fs.existsSync(path.join(dir, 'node_modules', 'astralkit', 'package.json'));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Common CSS file locations to search for when adding imports.
|
|
96
|
+
*/
|
|
97
|
+
const CSS_ENTRY_CANDIDATES = [
|
|
98
|
+
'src/index.css',
|
|
99
|
+
'src/app/globals.css',
|
|
100
|
+
'src/styles/globals.css',
|
|
101
|
+
'src/styles/index.css',
|
|
102
|
+
'app/globals.css',
|
|
103
|
+
'styles/globals.css',
|
|
104
|
+
'index.css',
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
const REQUIRED_CSS_IMPORTS = [
|
|
108
|
+
'@import "tailwindcss";',
|
|
109
|
+
'@import "astralkit/theme";',
|
|
110
|
+
'@import "astralkit/utilities";',
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Find the project's CSS entry file.
|
|
115
|
+
*/
|
|
116
|
+
function findCssEntryFile(dir = process.cwd()) {
|
|
117
|
+
for (const candidate of CSS_ENTRY_CANDIDATES) {
|
|
118
|
+
const filePath = path.join(dir, candidate);
|
|
119
|
+
if (fs.existsSync(filePath)) {
|
|
120
|
+
return { path: filePath, relative: candidate };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check which of the 3 required CSS imports are missing from a file.
|
|
128
|
+
* Returns array of missing import lines.
|
|
129
|
+
*/
|
|
130
|
+
function getMissingCssImports(cssFilePath) {
|
|
131
|
+
try {
|
|
132
|
+
const content = fs.readFileSync(cssFilePath, 'utf8');
|
|
133
|
+
return REQUIRED_CSS_IMPORTS.filter(imp => !content.includes(imp));
|
|
134
|
+
} catch {
|
|
135
|
+
return REQUIRED_CSS_IMPORTS;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Add missing CSS imports to the top of a file.
|
|
141
|
+
*/
|
|
142
|
+
function addCssImports(cssFilePath, imports) {
|
|
143
|
+
const existing = fs.existsSync(cssFilePath)
|
|
144
|
+
? fs.readFileSync(cssFilePath, 'utf8')
|
|
145
|
+
: '';
|
|
146
|
+
const newContent = imports.join('\n') + '\n\n' + existing;
|
|
147
|
+
fs.writeFileSync(cssFilePath, newContent);
|
|
148
|
+
}
|
|
149
|
+
|
|
109
150
|
module.exports = {
|
|
110
151
|
CONFIG_FILENAME,
|
|
111
152
|
defaultConfig,
|
|
@@ -113,4 +154,10 @@ module.exports = {
|
|
|
113
154
|
getProjectConfig,
|
|
114
155
|
writeProjectConfig,
|
|
115
156
|
detectFramework,
|
|
157
|
+
isAstralkitInstalled,
|
|
158
|
+
CSS_ENTRY_CANDIDATES,
|
|
159
|
+
REQUIRED_CSS_IMPORTS,
|
|
160
|
+
findCssEntryFile,
|
|
161
|
+
getMissingCssImports,
|
|
162
|
+
addCssImports,
|
|
116
163
|
};
|
package/src/lib/validators.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
1
2
|
const path = require('path');
|
|
2
3
|
const chalk = require('chalk');
|
|
3
4
|
|
|
4
|
-
const VALID_FRAMEWORKS = ['html', 'react', '
|
|
5
|
+
const VALID_FRAMEWORKS = ['html', 'react', 'nextjs'];
|
|
5
6
|
const SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -20,23 +21,25 @@ function validateFramework(framework) {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
|
-
* Validate a
|
|
24
|
+
* Validate a slug format.
|
|
25
|
+
* @param {string} slug
|
|
26
|
+
* @param {string} [label='name'] - Content type label for error messages.
|
|
24
27
|
* Returns true if valid, false if invalid (and logs an error).
|
|
25
28
|
*/
|
|
26
|
-
function validateSlug(slug) {
|
|
29
|
+
function validateSlug(slug, label = 'name') {
|
|
27
30
|
if (!slug || typeof slug !== 'string') {
|
|
28
|
-
console.error(chalk.red(
|
|
31
|
+
console.error(chalk.red(`${label.charAt(0).toUpperCase() + label.slice(1)} is required.`));
|
|
29
32
|
return false;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
if (slug.length > 128) {
|
|
33
|
-
console.error(chalk.red(
|
|
36
|
+
console.error(chalk.red(`${label.charAt(0).toUpperCase() + label.slice(1)} is too long (max 128 characters).`));
|
|
34
37
|
return false;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
if (!SLUG_PATTERN.test(slug)) {
|
|
38
41
|
console.error(
|
|
39
|
-
chalk.red(`Invalid
|
|
42
|
+
chalk.red(`Invalid ${label} "${slug}".`),
|
|
40
43
|
chalk.gray('Use lowercase letters, numbers, and hyphens only (e.g., "button-sizes").')
|
|
41
44
|
);
|
|
42
45
|
return false;
|
|
@@ -55,10 +58,30 @@ function isSafePath(basedir, filepath) {
|
|
|
55
58
|
return !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Write files to a base directory with path-traversal protection.
|
|
63
|
+
* Returns the number of files successfully written.
|
|
64
|
+
*/
|
|
65
|
+
function writeFiles(baseDir, files) {
|
|
66
|
+
let count = 0;
|
|
67
|
+
for (const file of files) {
|
|
68
|
+
if (!isSafePath(baseDir, file.path)) {
|
|
69
|
+
console.log(chalk.red(` Skipping suspicious file path: ${file.path}`));
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const filePath = path.resolve(baseDir, file.path);
|
|
73
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
74
|
+
fs.writeFileSync(filePath, file.content);
|
|
75
|
+
count++;
|
|
76
|
+
}
|
|
77
|
+
return count;
|
|
78
|
+
}
|
|
79
|
+
|
|
58
80
|
module.exports = {
|
|
59
81
|
VALID_FRAMEWORKS,
|
|
60
82
|
SLUG_PATTERN,
|
|
61
83
|
validateFramework,
|
|
62
84
|
validateSlug,
|
|
63
85
|
isSafePath,
|
|
86
|
+
writeFiles,
|
|
64
87
|
};
|