@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/lib/auth.js
CHANGED
|
@@ -1,142 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const CONFIG_DIR
|
|
6
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
7
|
-
|
|
8
|
-
function ensureConfigDir() {
|
|
9
|
-
if (!fs.existsSync(CONFIG_DIR)) {
|
|
10
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const config = { ...existing, apiKey };
|
|
100
|
-
// Clear legacy JWT fields when switching to API key
|
|
101
|
-
delete config.token;
|
|
102
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Get the stored API key (if any).
|
|
107
|
-
*/
|
|
108
|
-
function getApiKey() {
|
|
109
|
-
const envKey = process.env.ASTRALKIT_API_KEY;
|
|
110
|
-
if (envKey) return envKey;
|
|
111
|
-
|
|
112
|
-
const config = getFullConfig();
|
|
113
|
-
return config.apiKey || null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Remove stored auth.
|
|
118
|
-
*/
|
|
119
|
-
function clearToken() {
|
|
120
|
-
ensureConfigDir();
|
|
121
|
-
const config = getFullConfig();
|
|
122
|
-
delete config.token;
|
|
123
|
-
delete config.email;
|
|
124
|
-
delete config.plan;
|
|
125
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Read the full config file (preserving non-auth fields).
|
|
130
|
-
*/
|
|
131
|
-
function getFullConfig() {
|
|
132
|
-
try {
|
|
133
|
-
if (fs.existsSync(CONFIG_FILE)) {
|
|
134
|
-
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
135
|
-
}
|
|
136
|
-
} catch {
|
|
137
|
-
// Ignore
|
|
138
|
-
}
|
|
139
|
-
return {};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
module.exports = { getAuth, saveAuth, saveApiKey, getApiKey, clearToken, isTokenExpired, CONFIG_DIR, CONFIG_FILE };
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
|
|
5
|
+
const CONFIG_DIR = path.join(os.homedir(), '.astralkit');
|
|
6
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
7
|
+
|
|
8
|
+
function ensureConfigDir() {
|
|
9
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
10
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function decodeJwtPayload(token) {
|
|
15
|
+
try {
|
|
16
|
+
const parts = token.split('.');
|
|
17
|
+
if (parts.length !== 3) return null;
|
|
18
|
+
const payload = parts[1].replace(/-/g, '+').replace(/_/g, '/');
|
|
19
|
+
return JSON.parse(Buffer.from(payload, 'base64').toString('utf8'));
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isTokenExpired(token) {
|
|
26
|
+
if (!token) return true;
|
|
27
|
+
const payload = decodeJwtPayload(token);
|
|
28
|
+
if (!payload || !payload.exp) return false;
|
|
29
|
+
return Date.now() >= payload.exp * 1000;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getAuth() {
|
|
33
|
+
const envToken = process.env.ASTRALKIT_TOKEN;
|
|
34
|
+
if (envToken) {
|
|
35
|
+
if (isTokenExpired(envToken)) {
|
|
36
|
+
return { token: null, email: null, plan: null, expired: true, source: 'env' };
|
|
37
|
+
}
|
|
38
|
+
return { token: envToken, email: null, plan: null, source: 'env' };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
43
|
+
const config = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
44
|
+
const token = config.token || null;
|
|
45
|
+
|
|
46
|
+
if (token && isTokenExpired(token)) {
|
|
47
|
+
return { token: null, email: config.email || null, plan: config.plan || null, expired: true, source: 'config' };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { token, email: config.email || null, plan: config.plan || null, source: 'config' };
|
|
51
|
+
}
|
|
52
|
+
} catch {
|
|
53
|
+
// Ignore corrupt config
|
|
54
|
+
}
|
|
55
|
+
return { token: null, email: null, plan: null };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function saveAuth({ token, email, plan }) {
|
|
59
|
+
ensureConfigDir();
|
|
60
|
+
const existing = getFullConfig();
|
|
61
|
+
const config = { ...existing, token, email, plan };
|
|
62
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function saveApiKey(apiKey) {
|
|
66
|
+
ensureConfigDir();
|
|
67
|
+
const existing = getFullConfig();
|
|
68
|
+
const config = { ...existing, apiKey };
|
|
69
|
+
delete config.token;
|
|
70
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getApiKey() {
|
|
74
|
+
const envKey = process.env.ASTRALKIT_API_KEY;
|
|
75
|
+
if (envKey) return envKey;
|
|
76
|
+
const config = getFullConfig();
|
|
77
|
+
return config.apiKey || null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function clearToken() {
|
|
81
|
+
ensureConfigDir();
|
|
82
|
+
const config = getFullConfig();
|
|
83
|
+
delete config.token;
|
|
84
|
+
delete config.email;
|
|
85
|
+
delete config.plan;
|
|
86
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getFullConfig() {
|
|
90
|
+
try {
|
|
91
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
92
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
93
|
+
}
|
|
94
|
+
} catch { /* ignore */ }
|
|
95
|
+
return {};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { CONFIG_DIR, CONFIG_FILE };
|
package/src/lib/config.js
CHANGED
|
@@ -1,163 +1,127 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
* Returns array of missing import lines.
|
|
129
|
-
*/
|
|
130
|
-
function getMissingCssImports(cssFilePath) {
|
|
131
|
-
try {
|
|
132
|
-
const content = fs.readFileSync(cssFilePath, 'utf8');
|
|
133
|
-
return REQUIRED_CSS_IMPORTS.filter(imp => !content.includes(imp));
|
|
134
|
-
} catch {
|
|
135
|
-
return REQUIRED_CSS_IMPORTS;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Add missing CSS imports to the top of a file.
|
|
141
|
-
*/
|
|
142
|
-
function addCssImports(cssFilePath, imports) {
|
|
143
|
-
const existing = fs.existsSync(cssFilePath)
|
|
144
|
-
? fs.readFileSync(cssFilePath, 'utf8')
|
|
145
|
-
: '';
|
|
146
|
-
const newContent = imports.join('\n') + '\n\n' + existing;
|
|
147
|
-
fs.writeFileSync(cssFilePath, newContent);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
module.exports = {
|
|
151
|
-
CONFIG_FILENAME,
|
|
152
|
-
defaultConfig,
|
|
153
|
-
findConfigFile,
|
|
154
|
-
getProjectConfig,
|
|
155
|
-
writeProjectConfig,
|
|
156
|
-
detectFramework,
|
|
157
|
-
isAstralkitInstalled,
|
|
158
|
-
CSS_ENTRY_CANDIDATES,
|
|
159
|
-
REQUIRED_CSS_IMPORTS,
|
|
160
|
-
findCssEntryFile,
|
|
161
|
-
getMissingCssImports,
|
|
162
|
-
addCssImports,
|
|
163
|
-
};
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
// ─── CSS entry file candidates (searched in order) ────────
|
|
5
|
+
export const CSS_ENTRY_CANDIDATES = [
|
|
6
|
+
'src/app/globals.css',
|
|
7
|
+
'src/index.css',
|
|
8
|
+
'src/styles/globals.css',
|
|
9
|
+
'src/styles/index.css',
|
|
10
|
+
'app/globals.css',
|
|
11
|
+
'styles/globals.css',
|
|
12
|
+
'index.css',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
// ─── Framework detection ──────────────────────────────────
|
|
16
|
+
|
|
17
|
+
export function detectFramework(dir = process.cwd()) {
|
|
18
|
+
// Next.js
|
|
19
|
+
if (
|
|
20
|
+
fs.existsSync(path.join(dir, 'next.config.js')) ||
|
|
21
|
+
fs.existsSync(path.join(dir, 'next.config.mjs')) ||
|
|
22
|
+
fs.existsSync(path.join(dir, 'next.config.ts'))
|
|
23
|
+
) return 'nextjs';
|
|
24
|
+
|
|
25
|
+
// React (Vite, CRA, etc.)
|
|
26
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
27
|
+
if (fs.existsSync(pkgPath)) {
|
|
28
|
+
try {
|
|
29
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
30
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
31
|
+
if (allDeps['react']) return 'react';
|
|
32
|
+
} catch { /* ignore */ }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return 'html';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ─── Tailwind version detection ───────────────────────────
|
|
39
|
+
|
|
40
|
+
export function detectTailwindVersion(dir = process.cwd()) {
|
|
41
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
42
|
+
if (!fs.existsSync(pkgPath)) return null;
|
|
43
|
+
try {
|
|
44
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
45
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
46
|
+
const ver = allDeps['tailwindcss'];
|
|
47
|
+
if (!ver) return null;
|
|
48
|
+
const major = parseInt(ver.replace(/[^0-9]/, ''), 10);
|
|
49
|
+
if (major >= 4) return 4;
|
|
50
|
+
if (major >= 3) return 3;
|
|
51
|
+
return null;
|
|
52
|
+
} catch { return null; }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ─── TypeScript detection ─────────────────────────────────
|
|
56
|
+
|
|
57
|
+
export function detectTypeScript(dir = process.cwd()) {
|
|
58
|
+
return fs.existsSync(path.join(dir, 'tsconfig.json'));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ─── astralkit installed check ────────────────────────────
|
|
62
|
+
|
|
63
|
+
export function isAstralkitInstalled(dir = process.cwd()) {
|
|
64
|
+
return fs.existsSync(path.join(dir, 'node_modules', 'astralkit', 'package.json'));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ─── CSS entry file search ────────────────────────────────
|
|
68
|
+
|
|
69
|
+
export function findCssEntryFile(dir = process.cwd()) {
|
|
70
|
+
for (const candidate of CSS_ENTRY_CANDIDATES) {
|
|
71
|
+
const filePath = path.join(dir, candidate);
|
|
72
|
+
if (fs.existsSync(filePath)) return { path: filePath, relative: candidate };
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ─── CSS imports (Tailwind v3 vs v4 aware) ────────────────
|
|
78
|
+
|
|
79
|
+
export function getRequiredCssImports(tailwindVersion) {
|
|
80
|
+
if (tailwindVersion === 3) {
|
|
81
|
+
return [
|
|
82
|
+
'@tailwind base;',
|
|
83
|
+
'@tailwind components;',
|
|
84
|
+
'@tailwind utilities;',
|
|
85
|
+
'@import "astralkit/theme";',
|
|
86
|
+
'@import "astralkit/utilities";',
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
// v4 or unknown — default to v4 syntax
|
|
90
|
+
return [
|
|
91
|
+
'@import "tailwindcss";',
|
|
92
|
+
'@import "astralkit/theme";',
|
|
93
|
+
'@import "astralkit/utilities";',
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function getMissingCssImports(cssFilePath, tailwindVersion) {
|
|
98
|
+
try {
|
|
99
|
+
const content = fs.readFileSync(cssFilePath, 'utf8');
|
|
100
|
+
const required = getRequiredCssImports(tailwindVersion);
|
|
101
|
+
|
|
102
|
+
return required.filter(imp => {
|
|
103
|
+
// For tailwind directives, check if either v3 or v4 syntax is present
|
|
104
|
+
if (imp === '@import "tailwindcss";') {
|
|
105
|
+
return !content.includes('@import "tailwindcss"') && !content.includes('@tailwind base');
|
|
106
|
+
}
|
|
107
|
+
if (imp === '@tailwind base;') {
|
|
108
|
+
return !content.includes('@tailwind base') && !content.includes('@import "tailwindcss"');
|
|
109
|
+
}
|
|
110
|
+
if (imp === '@tailwind components;') {
|
|
111
|
+
return !content.includes('@tailwind components');
|
|
112
|
+
}
|
|
113
|
+
if (imp === '@tailwind utilities;') {
|
|
114
|
+
return !content.includes('@tailwind utilities');
|
|
115
|
+
}
|
|
116
|
+
// AstralKit imports — check directly
|
|
117
|
+
return !content.includes(imp);
|
|
118
|
+
});
|
|
119
|
+
} catch {
|
|
120
|
+
return getRequiredCssImports(tailwindVersion);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function addCssImports(cssFilePath, imports) {
|
|
125
|
+
const existing = fs.existsSync(cssFilePath) ? fs.readFileSync(cssFilePath, 'utf8') : '';
|
|
126
|
+
fs.writeFileSync(cssFilePath, imports.join('\n') + '\n\n' + existing);
|
|
127
|
+
}
|