@astralkit/cli 3.1.0 → 4.0.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/bin/index.js +155 -156
- package/package.json +42 -48
- package/src/commands/add.js +162 -444
- package/src/commands/diff.js +57 -107
- package/src/commands/init.js +117 -128
- package/src/commands/list.js +46 -186
- package/src/commands/login.js +133 -157
- package/src/commands/remove.js +42 -118
- package/src/commands/search.js +58 -156
- package/src/commands/update.js +90 -120
- package/src/lib/ai-rules.js +49 -50
- package/src/lib/api.js +152 -197
- package/src/lib/auth.js +98 -142
- package/src/lib/config.js +156 -163
- package/src/lib/pkg-manager.js +25 -65
- package/src/lib/validators.js +50 -87
package/src/lib/ai-rules.js
CHANGED
|
@@ -1,50 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function getAiRulesContent() {
|
|
9
|
-
const candidates = [
|
|
10
|
-
path.join(process.cwd(), 'node_modules', 'astralkit', 'ai-rules.md'),
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- Use
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
module.exports = { getAiRulesContent };
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { dirname } from 'path';
|
|
5
|
+
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
|
|
8
|
+
export function getAiRulesContent() {
|
|
9
|
+
const candidates = [
|
|
10
|
+
path.join(process.cwd(), 'node_modules', 'astralkit', 'ai-rules.md'),
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
for (const candidate of candidates) {
|
|
14
|
+
try {
|
|
15
|
+
return fs.readFileSync(candidate, 'utf8');
|
|
16
|
+
} catch { /* try next */ }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return getEmbeddedRules();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getEmbeddedRules() {
|
|
23
|
+
return `# AstralKit — AI Coding Rules
|
|
24
|
+
|
|
25
|
+
## Component Usage
|
|
26
|
+
- Import components from the components directory: \`import { Button } from '@/components/ui/button'\`
|
|
27
|
+
- Use the \`cn()\` helper for conditional classes: \`import { cn } from '@/lib/utils'\`
|
|
28
|
+
- All components use Tailwind CSS for styling
|
|
29
|
+
- Components are built on top of Radix UI primitives where applicable
|
|
30
|
+
|
|
31
|
+
## Design Tokens
|
|
32
|
+
- Use CSS variables for colors: \`var(--color-primary)\`
|
|
33
|
+
- Spacing follows Tailwind's scale
|
|
34
|
+
- All tokens are defined in \`astralkit/theme\`
|
|
35
|
+
|
|
36
|
+
## File Structure
|
|
37
|
+
- Components live in \`src/components/ui/\`
|
|
38
|
+
- Boosters live in \`src/lib/<booster-name>/\` (core) and \`src/components/<booster-name>/\` (adapters)
|
|
39
|
+
- Configuration is in \`astralkit.config.json\`
|
|
40
|
+
|
|
41
|
+
## Adding Components
|
|
42
|
+
- Use the CLI: \`astralkit add <component-name>\`
|
|
43
|
+
- Never manually copy components — always use the CLI to get the latest version
|
|
44
|
+
|
|
45
|
+
## Pro Components
|
|
46
|
+
- Run \`astralkit login\` to access Pro content
|
|
47
|
+
- Pro components are marked with ✨ in the CLI output
|
|
48
|
+
`;
|
|
49
|
+
}
|
package/src/lib/api.js
CHANGED
|
@@ -1,197 +1,152 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
} catch {
|
|
23
|
-
console.error('\x1b[31m✖ Invalid ASTRALKIT_API_URL. Falling back to default.\x1b[0m');
|
|
24
|
-
return DEFAULT_API_BASE;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
'
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
headers['
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (err.
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
throw
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (response.status ===
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (search) params.set('search', search);
|
|
154
|
-
|
|
155
|
-
const response = await apiRequest(`/api/cli/boosters?${params}`);
|
|
156
|
-
return response.json();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Get a single booster's details + files for installation.
|
|
161
|
-
*/
|
|
162
|
-
async function getBooster(slug, framework = 'nextjs') {
|
|
163
|
-
const response = await apiRequest(
|
|
164
|
-
`/api/cli/boosters/${encodeURIComponent(slug)}?framework=${encodeURIComponent(framework)}`
|
|
165
|
-
);
|
|
166
|
-
return response.json();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* List workflows with optional filters.
|
|
171
|
-
*/
|
|
172
|
-
async function listWorkflows({ framework, search, pro, free } = {}) {
|
|
173
|
-
const params = new URLSearchParams();
|
|
174
|
-
if (framework) params.set('framework', framework);
|
|
175
|
-
if (pro) params.set('pro', 'true');
|
|
176
|
-
if (free) params.set('free', 'true');
|
|
177
|
-
if (search) params.set('search', search);
|
|
178
|
-
|
|
179
|
-
const response = await apiRequest(`/api/cli/workflows?${params}`);
|
|
180
|
-
return response.json();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Get a single workflow's details + files for scaffolding.
|
|
185
|
-
*/
|
|
186
|
-
async function getWorkflow(slug, framework = 'nextjs') {
|
|
187
|
-
const response = await apiRequest(
|
|
188
|
-
`/api/cli/workflows/${encodeURIComponent(slug)}?framework=${encodeURIComponent(framework)}`
|
|
189
|
-
);
|
|
190
|
-
return response.json();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
module.exports = {
|
|
194
|
-
apiRequest, listComponents, getComponent, verifyAuth,
|
|
195
|
-
listBoosters, getBooster, listWorkflows, getWorkflow,
|
|
196
|
-
API_BASE, CLI_VERSION,
|
|
197
|
-
};
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { dirname, join } from 'path';
|
|
4
|
+
import { getAuth, getApiKey } from './auth.js';
|
|
5
|
+
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const pkg = require(join(__dirname, '..', '..', 'package.json'));
|
|
9
|
+
|
|
10
|
+
const CLI_VERSION = pkg.version;
|
|
11
|
+
const DEFAULT_API_BASE = 'https://astralkit.com';
|
|
12
|
+
const REQUEST_TIMEOUT_MS = 30_000;
|
|
13
|
+
|
|
14
|
+
export const API_BASE = (() => {
|
|
15
|
+
const override = process.env.ASTRALKIT_API_URL;
|
|
16
|
+
if (!override) return DEFAULT_API_BASE;
|
|
17
|
+
try {
|
|
18
|
+
const parsed = new URL(override);
|
|
19
|
+
if (parsed.protocol !== 'https:') {
|
|
20
|
+
console.warn('\x1b[33m⚠ ASTRALKIT_API_URL uses insecure protocol.\x1b[0m');
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
console.error('\x1b[31m✖ Invalid ASTRALKIT_API_URL. Falling back to default.\x1b[0m');
|
|
24
|
+
return DEFAULT_API_BASE;
|
|
25
|
+
}
|
|
26
|
+
return override;
|
|
27
|
+
})();
|
|
28
|
+
|
|
29
|
+
export { CLI_VERSION };
|
|
30
|
+
|
|
31
|
+
export async function apiRequest(urlPath, options = {}) {
|
|
32
|
+
const url = `${API_BASE}${urlPath}`;
|
|
33
|
+
|
|
34
|
+
const headers = {
|
|
35
|
+
'Accept': 'application/json',
|
|
36
|
+
'User-Agent': `@astralkit/cli/${CLI_VERSION} node/${process.version}`,
|
|
37
|
+
'X-AstralKit-CLI': CLI_VERSION,
|
|
38
|
+
...options.headers,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const apiKey = getApiKey();
|
|
42
|
+
if (apiKey) {
|
|
43
|
+
headers['x-api-key'] = apiKey;
|
|
44
|
+
} else {
|
|
45
|
+
const auth = getAuth();
|
|
46
|
+
if (auth.token) headers['Authorization'] = `Bearer ${auth.token}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
51
|
+
|
|
52
|
+
let response;
|
|
53
|
+
try {
|
|
54
|
+
response = await fetch(url, { ...options, headers, signal: controller.signal });
|
|
55
|
+
} catch (err) {
|
|
56
|
+
clearTimeout(timeout);
|
|
57
|
+
if (err.name === 'AbortError') {
|
|
58
|
+
const e = new Error('Request timed out. Check your connection and try again.');
|
|
59
|
+
e.code = 'TIMEOUT';
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
if (err.code === 'ENOTFOUND' || err.cause?.code === 'ENOTFOUND') {
|
|
63
|
+
const e = new Error('Could not reach astralkit.com. Check your internet connection.');
|
|
64
|
+
e.code = 'NETWORK_ERROR';
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
if (err.code === 'ECONNREFUSED' || err.cause?.code === 'ECONNREFUSED') {
|
|
68
|
+
const e = new Error('Connection refused. The AstralKit API may be temporarily down.');
|
|
69
|
+
e.code = 'NETWORK_ERROR';
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
throw err;
|
|
73
|
+
} finally {
|
|
74
|
+
clearTimeout(timeout);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (response.status === 401) {
|
|
78
|
+
const auth = getAuth();
|
|
79
|
+
const message = auth.expired
|
|
80
|
+
? 'Session expired. Run `astralkit login` to re-authenticate.'
|
|
81
|
+
: 'Authentication required. Run `astralkit login` to authenticate.';
|
|
82
|
+
const err = new Error(message);
|
|
83
|
+
err.code = 'AUTH_REQUIRED';
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (response.status === 403) {
|
|
88
|
+
const err = new Error('Pro subscription required. Visit https://astralkit.com/pricing');
|
|
89
|
+
err.code = 'PRO_REQUIRED';
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
const body = await response.text().catch(() => '');
|
|
95
|
+
const err = new Error(`API error ${response.status}: ${body || response.statusText}`);
|
|
96
|
+
err.code = 'API_ERROR';
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return response;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function verifyAuth() {
|
|
104
|
+
const res = await apiRequest('/api/cli/whoami');
|
|
105
|
+
return res.json();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function listComponents({ category, framework, pro, free, search } = {}) {
|
|
109
|
+
const params = new URLSearchParams();
|
|
110
|
+
if (category) params.set('category', category);
|
|
111
|
+
if (framework) params.set('framework', framework);
|
|
112
|
+
if (pro) params.set('pro', 'true');
|
|
113
|
+
if (free) params.set('free', 'true');
|
|
114
|
+
if (search) params.set('search', search);
|
|
115
|
+
const res = await apiRequest(`/api/cli/components?${params}`);
|
|
116
|
+
return res.json();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export async function getComponent(slug, framework = 'html') {
|
|
120
|
+
const res = await apiRequest(`/api/cli/components/${encodeURIComponent(slug)}?framework=${encodeURIComponent(framework)}`);
|
|
121
|
+
return res.json();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function listBoosters({ framework, search, pro, free } = {}) {
|
|
125
|
+
const params = new URLSearchParams();
|
|
126
|
+
if (framework) params.set('framework', framework);
|
|
127
|
+
if (pro) params.set('pro', 'true');
|
|
128
|
+
if (free) params.set('free', 'true');
|
|
129
|
+
if (search) params.set('search', search);
|
|
130
|
+
const res = await apiRequest(`/api/cli/boosters?${params}`);
|
|
131
|
+
return res.json();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function getBooster(slug, framework = 'nextjs') {
|
|
135
|
+
const res = await apiRequest(`/api/cli/boosters/${encodeURIComponent(slug)}?framework=${encodeURIComponent(framework)}`);
|
|
136
|
+
return res.json();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export async function listWorkflows({ framework, search, pro, free } = {}) {
|
|
140
|
+
const params = new URLSearchParams();
|
|
141
|
+
if (framework) params.set('framework', framework);
|
|
142
|
+
if (pro) params.set('pro', 'true');
|
|
143
|
+
if (free) params.set('free', 'true');
|
|
144
|
+
if (search) params.set('search', search);
|
|
145
|
+
const res = await apiRequest(`/api/cli/workflows?${params}`);
|
|
146
|
+
return res.json();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function getWorkflow(slug, framework = 'nextjs') {
|
|
150
|
+
const res = await apiRequest(`/api/cli/workflows/${encodeURIComponent(slug)}?framework=${encodeURIComponent(framework)}`);
|
|
151
|
+
return res.json();
|
|
152
|
+
}
|