@astralkit/cli 3.1.0 → 4.1.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 +155 -479
- package/src/commands/diff.js +57 -107
- package/src/commands/init.js +108 -148
- 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 +127 -163
- package/src/lib/pkg-manager.js +25 -65
- package/src/lib/validators.js +50 -87
package/src/commands/add.js
CHANGED
|
@@ -1,279 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
getProjectConfig,
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
import * as p from '@clack/prompts';
|
|
5
|
+
import { getComponent, getBooster, getWorkflow } from '../lib/api.js';
|
|
6
|
+
import {
|
|
9
7
|
detectFramework,
|
|
8
|
+
detectTypeScript,
|
|
10
9
|
isAstralkitInstalled,
|
|
11
10
|
findCssEntryFile,
|
|
12
11
|
getMissingCssImports,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
nextjs: 'Next.js',
|
|
22
|
-
react: 'React',
|
|
23
|
-
html: 'HTML',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Route to the correct add handler.
|
|
28
|
-
* If no --booster or --workflow flag, try auto-detection then prompt.
|
|
29
|
-
*/
|
|
30
|
-
async function addCommand(nameOrSlug, options) {
|
|
31
|
-
// Save API key if provided via --api-key flag
|
|
12
|
+
} from '../lib/config.js';
|
|
13
|
+
import { validateSlug, validateFramework, isSafePath, writeFiles } from '../lib/validators.js';
|
|
14
|
+
import { detectPackageManager, getRunCommand, runInstall } from '../lib/pkg-manager.js';
|
|
15
|
+
import { saveApiKey, getApiKey, getAuth } from '../lib/auth.js';
|
|
16
|
+
|
|
17
|
+
const FRAMEWORK_LABELS = { nextjs: 'Next.js', react: 'React' };
|
|
18
|
+
|
|
19
|
+
export async function addCommand(nameOrSlug, options) {
|
|
32
20
|
if (options.apiKey) {
|
|
33
21
|
if (!options.apiKey.startsWith('ak_')) {
|
|
34
|
-
console.log(
|
|
22
|
+
console.log(pc.red('Invalid API key format. Keys start with ak_'));
|
|
35
23
|
process.exit(1);
|
|
36
24
|
}
|
|
37
25
|
saveApiKey(options.apiKey);
|
|
38
26
|
}
|
|
39
27
|
|
|
40
|
-
// Require API key or token
|
|
41
28
|
if (!getApiKey()) {
|
|
42
|
-
const { getAuth } = require('../lib/auth');
|
|
43
29
|
const auth = getAuth();
|
|
44
30
|
if (!auth.token) {
|
|
45
|
-
|
|
46
|
-
console.log(
|
|
31
|
+
p.log.warn('No API key found. Run ' + pc.cyan('astralkit init --api-key <key>') + ' first.');
|
|
32
|
+
console.log(pc.gray('Get yours at ') + pc.cyan('https://astralkit.com/account'));
|
|
47
33
|
process.exit(1);
|
|
48
34
|
}
|
|
49
35
|
}
|
|
50
36
|
|
|
51
|
-
|
|
52
|
-
if (options.
|
|
53
|
-
return addBooster(nameOrSlug, options);
|
|
54
|
-
}
|
|
55
|
-
if (options.workflow) {
|
|
56
|
-
return addWorkflow(nameOrSlug, options);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// No flag given — try to auto-detect what the slug is
|
|
60
|
-
if (!options.booster && !options.workflow) {
|
|
61
|
-
const type = await resolveItemType(nameOrSlug, options);
|
|
62
|
-
if (type === 'booster') return addBooster(nameOrSlug, options);
|
|
63
|
-
if (type === 'workflow') return addWorkflow(nameOrSlug, options);
|
|
64
|
-
return addComponent(nameOrSlug, options);
|
|
65
|
-
}
|
|
66
|
-
|
|
37
|
+
if (options.booster) return addBooster(nameOrSlug, options);
|
|
38
|
+
if (options.workflow) return addWorkflow(nameOrSlug, options);
|
|
67
39
|
return addComponent(nameOrSlug, options);
|
|
68
40
|
}
|
|
69
41
|
|
|
70
|
-
|
|
71
|
-
* Try to find the slug across all registries (component, booster, workflow).
|
|
72
|
-
* If found in one, use it. If found in multiple, prompt. If not found, prompt.
|
|
73
|
-
*/
|
|
74
|
-
async function resolveItemType(slug, options) {
|
|
75
|
-
const spinner = ora('Looking up ' + chalk.cyan(slug) + '...').start();
|
|
76
|
-
|
|
77
|
-
const found = [];
|
|
78
|
-
|
|
79
|
-
// Try all three in parallel
|
|
80
|
-
const checks = await Promise.allSettled([
|
|
81
|
-
tryFetch('component', slug, options),
|
|
82
|
-
tryFetch('booster', slug, options),
|
|
83
|
-
tryFetch('workflow', slug, options),
|
|
84
|
-
]);
|
|
85
|
-
|
|
86
|
-
if (checks[0].status === 'fulfilled' && checks[0].value) found.push('component');
|
|
87
|
-
if (checks[1].status === 'fulfilled' && checks[1].value) found.push('booster');
|
|
88
|
-
if (checks[2].status === 'fulfilled' && checks[2].value) found.push('workflow');
|
|
89
|
-
|
|
90
|
-
spinner.stop();
|
|
91
|
-
|
|
92
|
-
if (found.length === 1) {
|
|
93
|
-
return found[0];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (found.length > 1) {
|
|
97
|
-
// Found in multiple registries — ask the user
|
|
98
|
-
const { type } = await inquirer.prompt([{
|
|
99
|
-
type: 'list',
|
|
100
|
-
name: 'type',
|
|
101
|
-
message: `"${slug}" matches multiple items. What do you want to install?`,
|
|
102
|
-
choices: found.map(t => ({
|
|
103
|
-
name: t === 'component' ? 'Component (UI element)'
|
|
104
|
-
: t === 'booster' ? 'Booster (feature module)'
|
|
105
|
-
: 'Workflow (complete app)',
|
|
106
|
-
value: t,
|
|
107
|
-
})),
|
|
108
|
-
}]);
|
|
109
|
-
return type;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Not found anywhere — ask what they want to install
|
|
113
|
-
const { type } = await inquirer.prompt([{
|
|
114
|
-
type: 'list',
|
|
115
|
-
name: 'type',
|
|
116
|
-
message: `What are you installing?`,
|
|
117
|
-
choices: [
|
|
118
|
-
{ name: 'Component (UI element)', value: 'component' },
|
|
119
|
-
{ name: 'Booster (feature module)', value: 'booster' },
|
|
120
|
-
{ name: 'Workflow (complete app)', value: 'workflow' },
|
|
121
|
-
],
|
|
122
|
-
}]);
|
|
123
|
-
return type;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Quick check if a slug exists in a registry. Returns true/false.
|
|
128
|
-
*/
|
|
129
|
-
async function tryFetch(type, slug, options) {
|
|
130
|
-
try {
|
|
131
|
-
const config = getProjectConfig();
|
|
132
|
-
const framework = options.framework || config?.framework || detectFramework();
|
|
133
|
-
if (type === 'component') {
|
|
134
|
-
await getComponent(slug, framework);
|
|
135
|
-
} else if (type === 'booster') {
|
|
136
|
-
await getBooster(slug, framework);
|
|
137
|
-
} else {
|
|
138
|
-
await getWorkflow(slug, framework);
|
|
139
|
-
}
|
|
140
|
-
return true;
|
|
141
|
-
} catch (err) {
|
|
142
|
-
// 403 = exists but user doesn't have access — still counts as "found"
|
|
143
|
-
if (err.code === 'PRO_REQUIRED') return true;
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Resolve framework — use flag, config, auto-detect, or prompt the user.
|
|
150
|
-
*/
|
|
151
|
-
async function resolveFramework(options, itemType) {
|
|
152
|
-
// Explicit flag
|
|
42
|
+
function resolveFramework(options) {
|
|
153
43
|
if (options.framework) {
|
|
154
44
|
if (!validateFramework(options.framework)) process.exit(1);
|
|
155
45
|
return options.framework;
|
|
156
46
|
}
|
|
157
|
-
|
|
158
|
-
// From project config
|
|
159
|
-
const config = getProjectConfig();
|
|
160
|
-
if (config?.framework) return config.framework;
|
|
161
|
-
|
|
162
|
-
// Auto-detect from project files
|
|
163
47
|
const detected = detectFramework();
|
|
164
|
-
if (detected
|
|
165
|
-
|
|
166
|
-
console.log(chalk.gray(` Detected ${FRAMEWORK_LABELS[detected] || detected} project`));
|
|
167
|
-
return detected;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// For boosters and workflows, default to nextjs instead of prompting for html
|
|
171
|
-
if (itemType === 'booster' || itemType === 'workflow') {
|
|
172
|
-
const { framework } = await inquirer.prompt([{
|
|
173
|
-
type: 'list',
|
|
174
|
-
name: 'framework',
|
|
175
|
-
message: 'Which framework?',
|
|
176
|
-
choices: [
|
|
177
|
-
{ name: 'Next.js', value: 'nextjs' },
|
|
178
|
-
{ name: 'React', value: 'react' },
|
|
179
|
-
{ name: 'HTML', value: 'html' },
|
|
180
|
-
],
|
|
181
|
-
default: 'nextjs',
|
|
182
|
-
}]);
|
|
183
|
-
return framework;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// For components, prompt with all options
|
|
187
|
-
const { framework } = await inquirer.prompt([{
|
|
188
|
-
type: 'list',
|
|
189
|
-
name: 'framework',
|
|
190
|
-
message: 'Which framework?',
|
|
191
|
-
choices: [
|
|
192
|
-
{ name: 'HTML (no framework needed)', value: 'html' },
|
|
193
|
-
{ name: 'React', value: 'react' },
|
|
194
|
-
{ name: 'Next.js', value: 'nextjs' },
|
|
195
|
-
],
|
|
196
|
-
}]);
|
|
197
|
-
return framework;
|
|
48
|
+
if (detected === 'nextjs' || detected === 'react') return detected;
|
|
49
|
+
return 'react';
|
|
198
50
|
}
|
|
199
51
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
function checkProjectContext(itemType) {
|
|
205
|
-
const pkgExists = fs.existsSync(path.join(process.cwd(), 'package.json'));
|
|
206
|
-
|
|
207
|
-
if (!pkgExists && itemType !== 'workflow') {
|
|
208
|
-
console.log(chalk.yellow('⚠ No package.json found in the current directory.'));
|
|
209
|
-
console.log(chalk.gray(' Run this inside a project, or use --workflow to scaffold a new app.'));
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
return true;
|
|
52
|
+
function resolveExtension(framework) {
|
|
53
|
+
const isTS = detectTypeScript();
|
|
54
|
+
if (framework === 'nextjs') return '.tsx';
|
|
55
|
+
return isTS ? '.tsx' : '.jsx';
|
|
213
56
|
}
|
|
214
57
|
|
|
215
|
-
// ─── Add Component ──────────────────────────────────
|
|
216
|
-
|
|
217
58
|
async function addComponent(componentSlug, options) {
|
|
218
59
|
if (!validateSlug(componentSlug)) process.exit(1);
|
|
60
|
+
if (!fs.existsSync(path.join(process.cwd(), 'package.json'))) {
|
|
61
|
+
p.log.warn('No package.json found. Run this inside a project directory.');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
219
64
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
const componentsDir = options.dir || config?.componentsDir || 'src/components/ui';
|
|
225
|
-
|
|
226
|
-
const ext = framework === 'nextjs' ? '.tsx' : framework === 'react' ? '.jsx' : '.html';
|
|
65
|
+
const ora = (await import('ora')).default;
|
|
66
|
+
const framework = resolveFramework(options);
|
|
67
|
+
const ext = resolveExtension(framework);
|
|
68
|
+
const componentsDir = options.dir || 'src/components/ui';
|
|
227
69
|
const targetFile = path.resolve(process.cwd(), componentsDir, `${componentSlug}${ext}`);
|
|
228
70
|
|
|
229
71
|
if (fs.existsSync(targetFile) && !options.overwrite) {
|
|
230
|
-
|
|
231
|
-
console.log(
|
|
72
|
+
p.log.warn(`Already exists: ${componentsDir}/${componentSlug}${ext}`);
|
|
73
|
+
console.log(pc.gray('Use --overwrite to replace.'));
|
|
232
74
|
return;
|
|
233
75
|
}
|
|
234
76
|
|
|
235
|
-
const spinner = ora(`Fetching ${componentSlug} (${FRAMEWORK_LABELS[framework]
|
|
77
|
+
const spinner = ora(`Fetching ${pc.cyan(componentSlug)} (${FRAMEWORK_LABELS[framework]})...`).start();
|
|
236
78
|
|
|
237
79
|
try {
|
|
238
|
-
|
|
239
|
-
let actualFramework = framework;
|
|
240
|
-
try {
|
|
241
|
-
data = await getComponent(componentSlug, framework);
|
|
242
|
-
} catch (fetchErr) {
|
|
243
|
-
// Pro required for React/Next.js — fall back to HTML for free users
|
|
244
|
-
if (fetchErr.code === 'PRO_REQUIRED' && framework !== 'html') {
|
|
245
|
-
spinner.warn(`${FRAMEWORK_LABELS[framework] || framework} requires a Pro subscription.`);
|
|
246
|
-
console.log(chalk.gray(' Fetching HTML version instead (free tier).'));
|
|
247
|
-
actualFramework = 'html';
|
|
248
|
-
const htmlSpinner = ora(`Fetching ${componentSlug} (HTML)...`).start();
|
|
249
|
-
try {
|
|
250
|
-
data = await getComponent(componentSlug, 'html');
|
|
251
|
-
htmlSpinner.succeed(`Fetched ${componentSlug} (HTML)`);
|
|
252
|
-
} catch (htmlErr) {
|
|
253
|
-
htmlSpinner.fail(`Failed to add component.`);
|
|
254
|
-
console.log(chalk.yellow(htmlErr.message));
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
} else {
|
|
258
|
-
throw fetchErr;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
80
|
+
const data = await getComponent(componentSlug, framework);
|
|
261
81
|
|
|
262
|
-
if (!data.files
|
|
82
|
+
if (!data.files?.length) {
|
|
263
83
|
spinner.fail(`No ${framework} code available for "${componentSlug}".`);
|
|
264
84
|
if (data.supported_frameworks?.length) {
|
|
265
|
-
console.log(
|
|
85
|
+
console.log(pc.gray(`Available: ${data.supported_frameworks.map(f => FRAMEWORK_LABELS[f] || f).join(', ')}`));
|
|
266
86
|
}
|
|
267
87
|
return;
|
|
268
88
|
}
|
|
269
89
|
|
|
270
|
-
// Dry run
|
|
271
90
|
if (options.dryRun) {
|
|
272
91
|
spinner.stop();
|
|
273
|
-
console.log(
|
|
92
|
+
console.log(pc.bold('\nDry run — no files will be written:\n'));
|
|
274
93
|
for (const file of data.files) {
|
|
275
94
|
const exists = fs.existsSync(path.resolve(process.cwd(), componentsDir, file.path));
|
|
276
|
-
console.log(` ${exists ?
|
|
95
|
+
console.log(` ${exists ? pc.yellow('overwrite') : pc.green('+ create')} ${componentsDir}/${file.path}`);
|
|
277
96
|
}
|
|
278
97
|
return;
|
|
279
98
|
}
|
|
@@ -283,7 +102,7 @@ async function addComponent(componentSlug, options) {
|
|
|
283
102
|
|
|
284
103
|
for (const file of data.files) {
|
|
285
104
|
if (!isSafePath(dir, file.path)) {
|
|
286
|
-
console.log(
|
|
105
|
+
console.log(pc.red(` Skipping suspicious path: ${file.path}`));
|
|
287
106
|
continue;
|
|
288
107
|
}
|
|
289
108
|
const filePath = path.resolve(dir, file.path);
|
|
@@ -291,43 +110,31 @@ async function addComponent(componentSlug, options) {
|
|
|
291
110
|
fs.writeFileSync(filePath, file.content);
|
|
292
111
|
}
|
|
293
112
|
|
|
294
|
-
spinner.succeed(`Added ${
|
|
113
|
+
spinner.succeed(`Added ${pc.cyan(data.name || componentSlug)} (${FRAMEWORK_LABELS[framework]})`);
|
|
114
|
+
console.log(pc.gray(` ${componentsDir}/`));
|
|
115
|
+
for (const file of data.files) console.log(pc.gray(` ${file.path}`));
|
|
295
116
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
console.log(chalk.gray(` ${file.path}`));
|
|
117
|
+
if (!isAstralkitInstalled()) {
|
|
118
|
+
p.log.warn('Run ' + pc.cyan('astralkit init') + ' to set up design tokens.');
|
|
299
119
|
}
|
|
300
120
|
|
|
301
|
-
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
console.log(chalk.yellow('astralkit design tokens not found.'));
|
|
307
|
-
console.log(chalk.cyan(' Run `astralkit init` to set up your project.'));
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
const cssEntry = findCssEntryFile();
|
|
311
|
-
if (cssEntry) {
|
|
312
|
-
const missing = getMissingCssImports(cssEntry.path);
|
|
313
|
-
if (missing.length > 0) {
|
|
314
|
-
console.log(chalk.yellow(`Missing CSS imports in ${cssEntry.relative}:`));
|
|
315
|
-
for (const imp of missing) {
|
|
316
|
-
console.log(chalk.cyan(` ${imp}`));
|
|
317
|
-
}
|
|
318
|
-
console.log(chalk.gray('Run `astralkit init` to set up automatically.'));
|
|
319
|
-
}
|
|
320
|
-
} else {
|
|
321
|
-
console.log(chalk.yellow('No CSS entry file found. Add these to your main CSS:'));
|
|
322
|
-
for (const imp of REQUIRED_CSS_IMPORTS) {
|
|
323
|
-
console.log(chalk.cyan(` ${imp}`));
|
|
324
|
-
}
|
|
121
|
+
const cssEntry = findCssEntryFile();
|
|
122
|
+
if (cssEntry) {
|
|
123
|
+
const missing = getMissingCssImports(cssEntry.path);
|
|
124
|
+
if (missing.length > 0) {
|
|
125
|
+
p.log.warn(`Missing CSS imports in ${cssEntry.relative}. Run ${pc.cyan('astralkit init')} to fix.`);
|
|
325
126
|
}
|
|
326
127
|
}
|
|
327
128
|
|
|
328
|
-
if (data.
|
|
329
|
-
|
|
330
|
-
|
|
129
|
+
if (data.dependencies?.length) {
|
|
130
|
+
const pm = detectPackageManager();
|
|
131
|
+
const depList = data.dependencies.filter(d => d !== 'astralkit' && d !== 'clsx' && d !== 'tailwind-merge');
|
|
132
|
+
if (depList.length > 0) {
|
|
133
|
+
const s = ora(`Installing ${depList.join(', ')}...`).start();
|
|
134
|
+
const result = await runInstall(pm, process.cwd(), depList);
|
|
135
|
+
if (result.success) s.succeed(`Installed ${depList.join(', ')}`);
|
|
136
|
+
else { s.fail(result.error); if (result.hint) console.log(pc.gray(` ${result.hint}`)); }
|
|
137
|
+
}
|
|
331
138
|
}
|
|
332
139
|
|
|
333
140
|
} catch (err) {
|
|
@@ -336,299 +143,198 @@ async function addComponent(componentSlug, options) {
|
|
|
336
143
|
}
|
|
337
144
|
}
|
|
338
145
|
|
|
339
|
-
// ─── Add Booster ────────────────────────────────────
|
|
340
|
-
|
|
341
146
|
async function addBooster(slug, options) {
|
|
342
147
|
if (!validateSlug(slug, 'booster name')) process.exit(1);
|
|
343
148
|
|
|
344
|
-
const
|
|
149
|
+
const ora = (await import('ora')).default;
|
|
150
|
+
const framework = resolveFramework(options);
|
|
345
151
|
const pm = detectPackageManager();
|
|
346
|
-
|
|
347
|
-
const spinner = ora(`Fetching booster ${chalk.cyan(slug)} (${FRAMEWORK_LABELS[framework] || framework})...`).start();
|
|
152
|
+
const spinner = ora(`Fetching booster ${pc.cyan(slug)} (${FRAMEWORK_LABELS[framework] || framework})...`).start();
|
|
348
153
|
|
|
349
154
|
try {
|
|
350
155
|
const data = await getBooster(slug, framework);
|
|
351
|
-
|
|
352
156
|
const coreFiles = data.core_files || [];
|
|
353
157
|
const adapterFiles = data.adapter_files || [];
|
|
354
158
|
|
|
355
159
|
if (coreFiles.length === 0 && adapterFiles.length === 0) {
|
|
356
160
|
spinner.fail(`No files available for booster "${slug}" (${framework}).`);
|
|
357
|
-
if (data.frameworks?.length) {
|
|
358
|
-
console.log(chalk.gray(`Available: ${data.frameworks.map(f => FRAMEWORK_LABELS[f] || f).join(', ')}`));
|
|
359
|
-
}
|
|
360
161
|
return;
|
|
361
162
|
}
|
|
362
163
|
|
|
363
|
-
|
|
364
|
-
const corePath = options.dir || data.install_paths?.core || `src/lib/${slug}`;
|
|
164
|
+
const corePath = options.dir || data.install_paths?.core || `src/lib/${slug}`;
|
|
365
165
|
const adapterPath = data.install_paths?.adapter || `src/components/${slug}`;
|
|
366
|
-
const coreDir
|
|
166
|
+
const coreDir = path.resolve(process.cwd(), corePath);
|
|
367
167
|
const adapterDir = path.resolve(process.cwd(), adapterPath);
|
|
368
168
|
|
|
369
|
-
// Dry run — show what would be written
|
|
370
169
|
if (options.dryRun) {
|
|
371
170
|
spinner.stop();
|
|
372
|
-
console.log(
|
|
171
|
+
console.log(pc.bold('\nDry run — no files will be written:\n'));
|
|
373
172
|
if (coreFiles.length > 0) {
|
|
374
|
-
console.log(
|
|
375
|
-
for (const
|
|
376
|
-
const exists = fs.existsSync(path.resolve(coreDir,
|
|
377
|
-
console.log(` ${exists ?
|
|
173
|
+
console.log(pc.gray(` Core: ${corePath}/`));
|
|
174
|
+
for (const f of coreFiles) {
|
|
175
|
+
const exists = fs.existsSync(path.resolve(coreDir, f.path));
|
|
176
|
+
console.log(` ${exists ? pc.yellow('overwrite') : pc.green('+ create')} ${f.path}`);
|
|
378
177
|
}
|
|
379
178
|
}
|
|
380
179
|
if (adapterFiles.length > 0) {
|
|
381
|
-
console.log(
|
|
382
|
-
for (const
|
|
383
|
-
const exists = fs.existsSync(path.resolve(adapterDir,
|
|
384
|
-
console.log(` ${exists ?
|
|
180
|
+
console.log(pc.gray(` Adapter: ${adapterPath}/`));
|
|
181
|
+
for (const f of adapterFiles) {
|
|
182
|
+
const exists = fs.existsSync(path.resolve(adapterDir, f.path));
|
|
183
|
+
console.log(` ${exists ? pc.yellow('overwrite') : pc.green('+ create')} ${f.path}`);
|
|
385
184
|
}
|
|
386
185
|
}
|
|
387
|
-
if (data.dependencies?.npm?.length) {
|
|
388
|
-
console.log(chalk.gray(`\n Dependencies: ${data.dependencies.npm.join(', ')}`));
|
|
389
|
-
}
|
|
390
186
|
return;
|
|
391
187
|
}
|
|
392
188
|
|
|
393
|
-
// Check for existing files
|
|
394
189
|
if (!options.overwrite) {
|
|
395
|
-
const conflicts = [
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
400
|
-
for (const file of adapterFiles) {
|
|
401
|
-
const fp = path.resolve(adapterDir, file.path);
|
|
402
|
-
if (fs.existsSync(fp)) conflicts.push(`${adapterPath}/${file.path}`);
|
|
403
|
-
}
|
|
190
|
+
const conflicts = [
|
|
191
|
+
...coreFiles.filter(f => fs.existsSync(path.resolve(coreDir, f.path))).map(f => `${corePath}/${f.path}`),
|
|
192
|
+
...adapterFiles.filter(f => fs.existsSync(path.resolve(adapterDir, f.path))).map(f => `${adapterPath}/${f.path}`),
|
|
193
|
+
];
|
|
404
194
|
if (conflicts.length > 0) {
|
|
405
195
|
spinner.stop();
|
|
406
|
-
console.log(
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
const { overwrite } = await inquirer.prompt([{
|
|
411
|
-
type: 'confirm',
|
|
412
|
-
name: 'overwrite',
|
|
413
|
-
message: 'Overwrite existing files?',
|
|
414
|
-
default: false,
|
|
415
|
-
}]);
|
|
416
|
-
if (!overwrite) return;
|
|
196
|
+
console.log(pc.yellow('\nThese files already exist:'));
|
|
197
|
+
conflicts.forEach(c => console.log(pc.gray(` ${c}`)));
|
|
198
|
+
const overwrite = await p.confirm({ message: 'Overwrite existing files?', initialValue: false });
|
|
199
|
+
if (p.isCancel(overwrite) || !overwrite) return;
|
|
417
200
|
}
|
|
418
201
|
}
|
|
419
202
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const adapterCount = writeFiles(adapterDir, adapterFiles);
|
|
203
|
+
writeFiles(coreDir, coreFiles);
|
|
204
|
+
writeFiles(adapterDir, adapterFiles);
|
|
423
205
|
|
|
424
|
-
spinner.succeed(`Added booster ${
|
|
206
|
+
spinner.succeed(`Added booster ${pc.cyan(data.name || slug)} (${FRAMEWORK_LABELS[framework] || framework})`);
|
|
425
207
|
|
|
426
|
-
if (
|
|
427
|
-
console.log(
|
|
428
|
-
|
|
429
|
-
console.log(chalk.gray(` ${file.path}`));
|
|
430
|
-
}
|
|
208
|
+
if (coreFiles.length > 0) {
|
|
209
|
+
console.log(pc.gray(` Core: ${corePath}/`));
|
|
210
|
+
coreFiles.forEach(f => console.log(pc.gray(` ${f.path}`)));
|
|
431
211
|
}
|
|
432
|
-
if (
|
|
433
|
-
console.log(
|
|
434
|
-
|
|
435
|
-
console.log(chalk.gray(` ${file.path}`));
|
|
436
|
-
}
|
|
212
|
+
if (adapterFiles.length > 0) {
|
|
213
|
+
console.log(pc.gray(` Adapter: ${adapterPath}/`));
|
|
214
|
+
adapterFiles.forEach(f => console.log(pc.gray(` ${f.path}`)));
|
|
437
215
|
}
|
|
438
216
|
|
|
439
|
-
// Install npm dependencies
|
|
440
217
|
if (data.dependencies?.npm?.length) {
|
|
441
218
|
console.log();
|
|
442
|
-
const
|
|
443
|
-
type: 'confirm',
|
|
444
|
-
name: 'install',
|
|
219
|
+
const install = await p.confirm({
|
|
445
220
|
message: `Install dependencies? (${data.dependencies.npm.join(', ')})`,
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
if (result.
|
|
453
|
-
installSpinner.succeed('Dependencies installed');
|
|
454
|
-
} else {
|
|
455
|
-
installSpinner.fail(result.error);
|
|
456
|
-
if (result.hint) console.log(chalk.gray(` ${result.hint}`));
|
|
457
|
-
}
|
|
221
|
+
initialValue: true,
|
|
222
|
+
});
|
|
223
|
+
if (!p.isCancel(install) && install) {
|
|
224
|
+
const s = ora('Installing dependencies...').start();
|
|
225
|
+
const result = await runInstall(pm, process.cwd(), data.dependencies.npm);
|
|
226
|
+
if (result.success) s.succeed('Dependencies installed');
|
|
227
|
+
else { s.fail(result.error); if (result.hint) console.log(pc.gray(` ${result.hint}`)); }
|
|
458
228
|
}
|
|
459
229
|
}
|
|
460
230
|
|
|
461
|
-
|
|
462
|
-
printPostInstallInfo(data, { pm });
|
|
463
|
-
|
|
464
|
-
// Next steps
|
|
465
|
-
printNextSteps({ type: 'booster', name: data.name || slug, data, pm });
|
|
466
|
-
|
|
467
|
-
if (data.is_pro) {
|
|
231
|
+
if (data.dependencies?.env?.length) {
|
|
468
232
|
console.log();
|
|
469
|
-
|
|
233
|
+
p.log.warn('Add these to your .env:');
|
|
234
|
+
data.dependencies.env.forEach(v => console.log(pc.gray(` ${v}=`)));
|
|
470
235
|
}
|
|
471
236
|
|
|
237
|
+
if (data.post_install) { console.log(); console.log(pc.gray(data.post_install)); }
|
|
238
|
+
|
|
472
239
|
} catch (err) {
|
|
473
240
|
spinner.fail('Failed to add booster.');
|
|
474
241
|
handleAddError(err, slug, framework);
|
|
475
242
|
}
|
|
476
243
|
}
|
|
477
244
|
|
|
478
|
-
// ─── Add Workflow ───────────────────────────────────
|
|
479
|
-
|
|
480
245
|
async function addWorkflow(slug, options) {
|
|
481
246
|
if (!validateSlug(slug, 'workflow name')) process.exit(1);
|
|
482
247
|
|
|
483
|
-
const
|
|
484
|
-
|
|
485
|
-
const spinner = ora(`Fetching workflow ${
|
|
248
|
+
const ora = (await import('ora')).default;
|
|
249
|
+
const framework = resolveFramework(options);
|
|
250
|
+
const spinner = ora(`Fetching workflow ${pc.cyan(slug)} (${FRAMEWORK_LABELS[framework] || framework})...`).start();
|
|
486
251
|
|
|
487
252
|
try {
|
|
488
253
|
const data = await getWorkflow(slug, framework);
|
|
489
254
|
|
|
490
|
-
if (!data.files
|
|
255
|
+
if (!data.files?.length) {
|
|
491
256
|
spinner.fail(`No files available for workflow "${slug}" (${framework}).`);
|
|
492
|
-
if (data.frameworks?.length) {
|
|
493
|
-
console.log(chalk.gray(`Available: ${data.frameworks.map(f => FRAMEWORK_LABELS[f] || f).join(', ')}`));
|
|
494
|
-
}
|
|
495
257
|
return;
|
|
496
258
|
}
|
|
497
259
|
|
|
498
|
-
// Determine target directory
|
|
499
260
|
let targetDir;
|
|
500
261
|
if (options.overlay) {
|
|
501
262
|
targetDir = path.resolve(process.cwd());
|
|
502
263
|
} else {
|
|
503
264
|
let dirName = options.dir || slug;
|
|
504
265
|
|
|
505
|
-
// If directory exists, ask the user
|
|
506
266
|
if (fs.existsSync(path.resolve(process.cwd(), dirName)) && !options.overwrite) {
|
|
507
267
|
spinner.stop();
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
{
|
|
514
|
-
{ name: 'Use a different name', value: 'rename' },
|
|
515
|
-
{ name: 'Cancel', value: 'cancel' },
|
|
268
|
+
const action = await p.select({
|
|
269
|
+
message: `Directory "${dirName}/" already exists.`,
|
|
270
|
+
options: [
|
|
271
|
+
{ label: 'Overwrite it', value: 'overwrite' },
|
|
272
|
+
{ label: 'Use a different name', value: 'rename' },
|
|
273
|
+
{ label: 'Cancel', value: 'cancel' },
|
|
516
274
|
],
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
if (action === 'cancel') return;
|
|
275
|
+
});
|
|
276
|
+
if (p.isCancel(action) || action === 'cancel') return;
|
|
520
277
|
if (action === 'rename') {
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
name: 'newDir',
|
|
524
|
-
message: 'Enter a directory name:',
|
|
525
|
-
default: `${slug}-app`,
|
|
526
|
-
}]);
|
|
278
|
+
const newDir = await p.text({ message: 'Enter a directory name:', placeholder: `${slug}-app` });
|
|
279
|
+
if (p.isCancel(newDir)) return;
|
|
527
280
|
dirName = newDir;
|
|
528
281
|
}
|
|
529
282
|
}
|
|
530
|
-
|
|
531
283
|
targetDir = path.resolve(process.cwd(), dirName);
|
|
532
284
|
}
|
|
533
285
|
|
|
534
|
-
// Check for conflicts in overlay mode
|
|
535
286
|
if (options.overlay && !options.overwrite) {
|
|
536
|
-
const conflicts =
|
|
537
|
-
for (const file of data.files) {
|
|
538
|
-
const fp = path.resolve(targetDir, file.path);
|
|
539
|
-
if (fs.existsSync(fp)) conflicts.push(file.path);
|
|
540
|
-
}
|
|
287
|
+
const conflicts = data.files.filter(f => fs.existsSync(path.resolve(targetDir, f.path))).map(f => f.path);
|
|
541
288
|
if (conflicts.length > 0) {
|
|
542
289
|
spinner.stop();
|
|
543
|
-
console.log(
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
if (
|
|
548
|
-
console.log(chalk.gray(` ... and ${conflicts.length - 10} more`));
|
|
549
|
-
}
|
|
550
|
-
const { overwrite } = await inquirer.prompt([{
|
|
551
|
-
type: 'confirm',
|
|
552
|
-
name: 'overwrite',
|
|
553
|
-
message: 'Overwrite these files?',
|
|
554
|
-
default: false,
|
|
555
|
-
}]);
|
|
556
|
-
if (!overwrite) return;
|
|
290
|
+
console.log(pc.yellow(`${conflicts.length} file(s) would be overwritten:`));
|
|
291
|
+
conflicts.slice(0, 10).forEach(c => console.log(pc.gray(` ${c}`)));
|
|
292
|
+
if (conflicts.length > 10) console.log(pc.gray(` ... and ${conflicts.length - 10} more`));
|
|
293
|
+
const overwrite = await p.confirm({ message: 'Overwrite these files?', initialValue: false });
|
|
294
|
+
if (p.isCancel(overwrite) || !overwrite) return;
|
|
557
295
|
}
|
|
558
296
|
}
|
|
559
297
|
|
|
560
|
-
const dirName = path.basename(targetDir);
|
|
561
|
-
const targetLabel = options.overlay ? './' : `${dirName}/`;
|
|
562
|
-
const pm = detectPackageManager(options.overlay ? process.cwd() : targetDir);
|
|
563
|
-
|
|
564
|
-
// Dry run — show what would be written
|
|
565
298
|
if (options.dryRun) {
|
|
566
299
|
spinner.stop();
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
console.log(chalk.gray(`\n Dependencies: ${data.dependencies.npm.join(', ')}`));
|
|
574
|
-
}
|
|
300
|
+
const label = options.overlay ? './' : `${path.basename(targetDir)}/`;
|
|
301
|
+
console.log(pc.bold(`\nDry run — no files will be written to ${label}:\n`));
|
|
302
|
+
data.files.forEach(f => {
|
|
303
|
+
const exists = fs.existsSync(path.resolve(targetDir, f.path));
|
|
304
|
+
console.log(` ${exists ? pc.yellow('overwrite') : pc.green('+ create')} ${f.path}`);
|
|
305
|
+
});
|
|
575
306
|
return;
|
|
576
307
|
}
|
|
577
308
|
|
|
578
|
-
|
|
309
|
+
const pm = detectPackageManager(options.overlay ? process.cwd() : targetDir);
|
|
579
310
|
const fileCount = writeFiles(targetDir, data.files);
|
|
311
|
+
const label = options.overlay ? './' : `${path.basename(targetDir)}/`;
|
|
580
312
|
|
|
581
|
-
spinner.succeed(`Scaffolded workflow ${
|
|
313
|
+
spinner.succeed(`Scaffolded workflow ${pc.cyan(data.name || slug)} in ${label}`);
|
|
314
|
+
console.log(pc.gray(` ${fileCount} files written`));
|
|
582
315
|
|
|
583
|
-
console.log(chalk.gray(` ${fileCount} files written to ${targetLabel}`));
|
|
584
|
-
|
|
585
|
-
// Offer to install dependencies
|
|
586
316
|
if (!options.overlay) {
|
|
587
317
|
console.log();
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
if (install) {
|
|
596
|
-
const installSpinner = ora(`Installing dependencies with ${pm}...`).start();
|
|
597
|
-
const result = runInstall(pm, targetDir);
|
|
598
|
-
if (result.success) {
|
|
599
|
-
installSpinner.succeed('Dependencies installed');
|
|
600
|
-
} else {
|
|
601
|
-
installSpinner.fail(result.error);
|
|
602
|
-
if (result.hint) console.log(chalk.gray(` ${result.hint}`));
|
|
603
|
-
}
|
|
318
|
+
const install = await p.confirm({ message: `Install dependencies with ${pm}?`, initialValue: true });
|
|
319
|
+
if (!p.isCancel(install) && install) {
|
|
320
|
+
const s = ora(`Installing with ${pm}...`).start();
|
|
321
|
+
const result = await runInstall(pm, targetDir);
|
|
322
|
+
if (result.success) s.succeed('Dependencies installed');
|
|
323
|
+
else { s.fail(result.error); if (result.hint) console.log(pc.gray(` ${result.hint}`)); }
|
|
604
324
|
}
|
|
605
325
|
}
|
|
606
326
|
|
|
607
|
-
// Next steps
|
|
608
327
|
console.log();
|
|
609
|
-
console.log(
|
|
610
|
-
|
|
611
|
-
console.log(chalk.white(` cd ${dirName}`));
|
|
612
|
-
}
|
|
613
|
-
console.log(chalk.white(` ${getRunCommand(pm, 'dev')}`));
|
|
328
|
+
if (!options.overlay) console.log(pc.white(` cd ${path.basename(targetDir)}`));
|
|
329
|
+
console.log(pc.white(` ${getRunCommand(pm, 'dev')}`));
|
|
614
330
|
|
|
615
331
|
if (data.dependencies?.env?.length) {
|
|
616
332
|
console.log();
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
console.log(chalk.gray(` ${envVar}=`));
|
|
620
|
-
}
|
|
333
|
+
p.log.warn('Set up your environment variables:');
|
|
334
|
+
data.dependencies.env.forEach(v => console.log(pc.gray(` ${v}=`)));
|
|
621
335
|
}
|
|
622
336
|
|
|
623
|
-
if (data.post_install) {
|
|
624
|
-
console.log();
|
|
625
|
-
console.log(chalk.gray(data.post_install));
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
if (data.is_pro) {
|
|
629
|
-
console.log();
|
|
630
|
-
console.log(chalk.magenta('✨ Pro workflow — thank you for your subscription!'));
|
|
631
|
-
}
|
|
337
|
+
if (data.post_install) { console.log(); console.log(pc.gray(data.post_install)); }
|
|
632
338
|
|
|
633
339
|
} catch (err) {
|
|
634
340
|
spinner.fail('Failed to add workflow.');
|
|
@@ -636,52 +342,22 @@ async function addWorkflow(slug, options) {
|
|
|
636
342
|
}
|
|
637
343
|
}
|
|
638
344
|
|
|
639
|
-
// ─── Helpers ────────────────────────────────────────
|
|
640
|
-
|
|
641
|
-
function printPostInstallInfo(data, { pm = 'npm' } = {}) {
|
|
642
|
-
if (data.dependencies?.env?.length) {
|
|
643
|
-
console.log();
|
|
644
|
-
console.log(chalk.yellow('Add these environment variables to your .env:'));
|
|
645
|
-
for (const envVar of data.dependencies.env) {
|
|
646
|
-
console.log(chalk.gray(` ${envVar}=`));
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
if (data.post_install) {
|
|
650
|
-
console.log();
|
|
651
|
-
console.log(chalk.white.bold('Setup:'));
|
|
652
|
-
console.log(chalk.gray(data.post_install));
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
function printNextSteps({ type, name, data, pm = 'npm' }) {
|
|
657
|
-
console.log();
|
|
658
|
-
console.log(chalk.green.bold(`✅ ${name} installed successfully!\n`));
|
|
659
|
-
|
|
660
|
-
if (type === 'booster') {
|
|
661
|
-
console.log(chalk.gray('Import and use the booster in your code.'));
|
|
662
|
-
console.log(chalk.gray(`To remove later: astralkit remove ${data.slug || name}`));
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
345
|
function handleAddError(err, slug, framework) {
|
|
667
346
|
if (err.code === 'AUTH_REQUIRED') {
|
|
668
|
-
|
|
347
|
+
p.log.warn(err.message);
|
|
669
348
|
} else if (err.code === 'PRO_REQUIRED') {
|
|
670
|
-
|
|
349
|
+
p.log.warn(`${FRAMEWORK_LABELS[framework] || framework} version requires a Pro subscription.`);
|
|
350
|
+
console.log(pc.gray(' Upgrade at ') + pc.cyan('https://astralkit.com/pricing'));
|
|
671
351
|
} else {
|
|
672
352
|
try {
|
|
673
353
|
const body = JSON.parse(err.message.replace(/^API error \d+: /, ''));
|
|
674
354
|
if (body.supported_frameworks) {
|
|
675
|
-
|
|
676
|
-
console.log(
|
|
355
|
+
p.log.warn(`No ${framework} version available for "${slug}".`);
|
|
356
|
+
console.log(pc.gray(`Available: ${body.supported_frameworks.map(f => FRAMEWORK_LABELS[f] || f).join(', ')}`));
|
|
677
357
|
process.exit(1);
|
|
678
358
|
}
|
|
679
|
-
} catch {
|
|
680
|
-
|
|
681
|
-
}
|
|
682
|
-
console.error(chalk.red(err.message));
|
|
359
|
+
} catch { /* not json */ }
|
|
360
|
+
console.error(pc.red(err.message));
|
|
683
361
|
}
|
|
684
362
|
process.exit(1);
|
|
685
363
|
}
|
|
686
|
-
|
|
687
|
-
module.exports = { addCommand };
|