@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/commands/list.js
CHANGED
|
@@ -1,186 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!grouped[cat]) grouped[cat] = [];
|
|
48
|
-
grouped[cat].push(comp);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.log(chalk.blue.bold(`AstralKit Components (${data.components.length} total)`));
|
|
52
|
-
console.log();
|
|
53
|
-
|
|
54
|
-
for (const [category, components] of Object.entries(grouped)) {
|
|
55
|
-
console.log(chalk.white.bold(` ${category}`));
|
|
56
|
-
for (const comp of components) {
|
|
57
|
-
const proTag = comp.is_pro ? chalk.magenta(' PRO') : '';
|
|
58
|
-
const frameworks = comp.supported_frameworks?.length
|
|
59
|
-
? chalk.gray(` [${comp.supported_frameworks.join(', ')}]`)
|
|
60
|
-
: '';
|
|
61
|
-
console.log(` ${chalk.cyan(comp.slug)}${proTag}${frameworks}`);
|
|
62
|
-
if (comp.short_description) {
|
|
63
|
-
console.log(` ${chalk.gray(comp.short_description)}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
console.log();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
console.log(chalk.gray('Run'), chalk.cyan('astralkit add <component>'), chalk.gray('to install.'));
|
|
70
|
-
|
|
71
|
-
} catch (err) {
|
|
72
|
-
spinner.fail('Failed to list components.');
|
|
73
|
-
console.error(chalk.red(err.message));
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
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
|
-
|
|
186
|
-
module.exports = { listCommand };
|
|
1
|
+
import pc from 'picocolors';
|
|
2
|
+
import * as p from '@clack/prompts';
|
|
3
|
+
import { listComponents, listBoosters, listWorkflows } from '../lib/api.js';
|
|
4
|
+
|
|
5
|
+
const FRAMEWORK_LABELS = { nextjs: 'Next.js', react: 'React', html: 'HTML' };
|
|
6
|
+
|
|
7
|
+
export async function listCommand(options) {
|
|
8
|
+
const ora = (await import('ora')).default;
|
|
9
|
+
const type = options.boosters ? 'boosters' : options.workflows ? 'workflows' : 'components';
|
|
10
|
+
const spinner = ora(`Fetching ${type}...`).start();
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
let items;
|
|
14
|
+
const filters = { framework: options.framework, pro: options.pro, free: options.free, category: options.category };
|
|
15
|
+
|
|
16
|
+
if (options.boosters) items = await listBoosters(filters);
|
|
17
|
+
else if (options.workflows) items = await listWorkflows(filters);
|
|
18
|
+
else items = await listComponents(filters);
|
|
19
|
+
|
|
20
|
+
spinner.stop();
|
|
21
|
+
|
|
22
|
+
if (!items?.length) {
|
|
23
|
+
p.log.info(`No ${type} found.`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log();
|
|
28
|
+
console.log(pc.bold(` ${items.length} ${type} available\n`));
|
|
29
|
+
|
|
30
|
+
for (const item of items) {
|
|
31
|
+
const proTag = item.is_pro ? pc.magenta(' [PRO]') : pc.green(' [FREE]');
|
|
32
|
+
const fw = item.frameworks?.map(f => FRAMEWORK_LABELS[f] || f).join(', ') || '';
|
|
33
|
+
console.log(` ${pc.cyan(item.slug || item.name)}${proTag}`);
|
|
34
|
+
if (item.description) console.log(pc.gray(` ${item.description}`));
|
|
35
|
+
if (fw) console.log(pc.gray(` Frameworks: ${fw}`));
|
|
36
|
+
console.log();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log(pc.gray(` astralkit add <name> to install`));
|
|
40
|
+
} catch (err) {
|
|
41
|
+
spinner.fail('Failed to fetch items.');
|
|
42
|
+
if (err.code === 'AUTH_REQUIRED') p.log.warn(err.message);
|
|
43
|
+
else console.error(pc.red(err.message));
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/commands/login.js
CHANGED
|
@@ -1,157 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (auth.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
res.writeHead(
|
|
87
|
-
res.end(JSON.stringify({ error: '
|
|
88
|
-
server.close();
|
|
89
|
-
reject(new Error('Authentication failed —
|
|
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
|
-
`Close the conflicting process or set ASTRALKIT_LOGIN_PORT to a different port.`
|
|
135
|
-
));
|
|
136
|
-
} else {
|
|
137
|
-
reject(err);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// Save credentials
|
|
143
|
-
saveAuth(token);
|
|
144
|
-
spinner.succeed('Authenticated successfully!');
|
|
145
|
-
console.log(chalk.gray(` Email: ${token.email || 'unknown'}`));
|
|
146
|
-
console.log(chalk.gray(` Plan: ${token.plan || 'free'}`));
|
|
147
|
-
console.log();
|
|
148
|
-
console.log(chalk.green('You can now install pro components:'));
|
|
149
|
-
console.log(chalk.cyan(' astralkit add pricing-table'));
|
|
150
|
-
|
|
151
|
-
} catch (err) {
|
|
152
|
-
spinner.fail(err.message);
|
|
153
|
-
process.exit(1);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
module.exports = { loginCommand };
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
import * as p from '@clack/prompts';
|
|
5
|
+
import { getAuth, saveAuth } from '../lib/auth.js';
|
|
6
|
+
import { API_BASE } from '../lib/api.js';
|
|
7
|
+
|
|
8
|
+
const DEFAULT_CALLBACK_PORT = 9876;
|
|
9
|
+
|
|
10
|
+
export async function loginCommand() {
|
|
11
|
+
p.intro(pc.bgBlue(pc.white(' AstralKit Login ')));
|
|
12
|
+
|
|
13
|
+
// CI/CD shortcut
|
|
14
|
+
if (process.env.ASTRALKIT_TOKEN) {
|
|
15
|
+
const auth = getAuth();
|
|
16
|
+
if (auth.token) {
|
|
17
|
+
p.outro(pc.green('Authenticated via ASTRALKIT_TOKEN'));
|
|
18
|
+
} else if (auth.expired) {
|
|
19
|
+
p.log.warn('ASTRALKIT_TOKEN is expired. Generate a new one.');
|
|
20
|
+
process.exit(1);
|
|
21
|
+
} else {
|
|
22
|
+
p.log.error('ASTRALKIT_TOKEN is set but invalid.');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const callbackPort = parseInt(process.env.ASTRALKIT_LOGIN_PORT || String(DEFAULT_CALLBACK_PORT), 10);
|
|
29
|
+
if (isNaN(callbackPort) || callbackPort < 1024 || callbackPort > 65535) {
|
|
30
|
+
p.log.error('Invalid ASTRALKIT_LOGIN_PORT. Must be 1024–65535.');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const state = crypto.randomBytes(32).toString('hex');
|
|
35
|
+
const ora = (await import('ora')).default;
|
|
36
|
+
const { default: open } = await import('open');
|
|
37
|
+
|
|
38
|
+
const spinner = ora('Waiting for browser authentication...').start();
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const authData = await new Promise((resolve, reject) => {
|
|
42
|
+
const server = http.createServer((req, res) => {
|
|
43
|
+
const url = new URL(req.url, `http://localhost:${callbackPort}`);
|
|
44
|
+
|
|
45
|
+
const origin = req.headers['origin'] || '';
|
|
46
|
+
const allowedOrigin = API_BASE.startsWith('http://localhost') ? origin : 'https://astralkit.com';
|
|
47
|
+
res.setHeader('Access-Control-Allow-Origin', allowedOrigin);
|
|
48
|
+
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
|
|
49
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
50
|
+
|
|
51
|
+
if (req.method === 'OPTIONS') { res.writeHead(204); res.end(); return; }
|
|
52
|
+
|
|
53
|
+
if (url.pathname === '/callback' && req.method === 'POST') {
|
|
54
|
+
let body = '';
|
|
55
|
+
let bodySize = 0;
|
|
56
|
+
|
|
57
|
+
req.on('data', chunk => {
|
|
58
|
+
bodySize += chunk.length;
|
|
59
|
+
if (bodySize > 1_048_576) {
|
|
60
|
+
res.writeHead(413);
|
|
61
|
+
res.end(JSON.stringify({ error: 'Request body too large' }));
|
|
62
|
+
server.close();
|
|
63
|
+
reject(new Error('Received oversized callback payload.'));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
body += chunk;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
req.on('end', () => {
|
|
70
|
+
try {
|
|
71
|
+
const data = JSON.parse(body);
|
|
72
|
+
if (data.state !== state) {
|
|
73
|
+
res.writeHead(403, { 'Content-Type': 'application/json' });
|
|
74
|
+
res.end(JSON.stringify({ error: 'State mismatch' }));
|
|
75
|
+
server.close();
|
|
76
|
+
reject(new Error('Authentication failed — state mismatch.'));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (data.token) {
|
|
81
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
82
|
+
res.end(JSON.stringify({ ok: true }));
|
|
83
|
+
server.close();
|
|
84
|
+
resolve(data);
|
|
85
|
+
} else {
|
|
86
|
+
res.writeHead(400, { 'Content-Type': 'application/json' });
|
|
87
|
+
res.end(JSON.stringify({ error: 'Missing token' }));
|
|
88
|
+
server.close();
|
|
89
|
+
reject(new Error('Authentication failed — no token received.'));
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
res.writeHead(400);
|
|
93
|
+
res.end(JSON.stringify({ error: 'Invalid body' }));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
res.writeHead(404); res.end();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
server.listen(callbackPort, () => {
|
|
102
|
+
const loginUrl = `${API_BASE}/cli-auth?callback=${encodeURIComponent(`http://localhost:${callbackPort}/callback`)}&state=${state}`;
|
|
103
|
+
open(loginUrl);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
server.close();
|
|
108
|
+
reject(new Error('Authentication timed out. Please try again.'));
|
|
109
|
+
}, 5 * 60 * 1000);
|
|
110
|
+
|
|
111
|
+
server.on('error', err => {
|
|
112
|
+
if (err.code === 'EADDRINUSE') {
|
|
113
|
+
reject(new Error(
|
|
114
|
+
`Port ${callbackPort} is in use. Set ASTRALKIT_LOGIN_PORT to a different port.`
|
|
115
|
+
));
|
|
116
|
+
} else {
|
|
117
|
+
reject(err);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
saveAuth(authData);
|
|
123
|
+
spinner.succeed('Authenticated successfully!');
|
|
124
|
+
console.log(pc.gray(` Email: ${authData.email || 'unknown'}`));
|
|
125
|
+
console.log(pc.gray(` Plan: ${authData.plan || 'free'}`));
|
|
126
|
+
console.log();
|
|
127
|
+
p.outro(pc.green('You can now install Pro components: ' + pc.cyan('astralkit add pricing-table')));
|
|
128
|
+
|
|
129
|
+
} catch (err) {
|
|
130
|
+
spinner.fail(err.message);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
}
|