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