@astralkit/cli 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +155 -156
- package/package.json +42 -48
- package/src/commands/add.js +162 -444
- package/src/commands/diff.js +57 -107
- package/src/commands/init.js +117 -128
- package/src/commands/list.js +46 -186
- package/src/commands/login.js +133 -157
- package/src/commands/remove.js +42 -118
- package/src/commands/search.js +58 -156
- package/src/commands/update.js +90 -120
- package/src/lib/ai-rules.js +49 -50
- package/src/lib/api.js +152 -197
- package/src/lib/auth.js +98 -142
- package/src/lib/config.js +156 -163
- package/src/lib/pkg-manager.js +25 -65
- package/src/lib/validators.js +50 -87
package/src/lib/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,156 @@
|
|
|
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
|
-
fs.existsSync(path.join(dir, 'next.config.
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
+
// Config file support — kept for backwards compatibility with existing projects
|
|
5
|
+
// New installs don't create this file; detection is automatic.
|
|
6
|
+
export const CONFIG_FILENAME = 'astralkit.config.json';
|
|
7
|
+
|
|
8
|
+
export function getProjectConfig(dir = process.cwd()) {
|
|
9
|
+
let searchDir = dir;
|
|
10
|
+
while (true) {
|
|
11
|
+
const configPath = path.join(searchDir, CONFIG_FILENAME);
|
|
12
|
+
if (fs.existsSync(configPath)) {
|
|
13
|
+
try {
|
|
14
|
+
const raw = fs.readFileSync(configPath, 'utf8');
|
|
15
|
+
return { ...JSON.parse(raw), _path: configPath };
|
|
16
|
+
} catch { return null; }
|
|
17
|
+
}
|
|
18
|
+
const parent = path.dirname(searchDir);
|
|
19
|
+
if (parent === searchDir) break;
|
|
20
|
+
searchDir = parent;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const CSS_ENTRY_CANDIDATES = [
|
|
26
|
+
'src/index.css',
|
|
27
|
+
'src/app/globals.css',
|
|
28
|
+
'src/styles/globals.css',
|
|
29
|
+
'src/styles/index.css',
|
|
30
|
+
'app/globals.css',
|
|
31
|
+
'styles/globals.css',
|
|
32
|
+
'styles/global.css',
|
|
33
|
+
'index.css',
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* CSS imports needed for AstralKit.
|
|
38
|
+
* Tailwind import is version-dependent — use getRequiredCssImports() instead.
|
|
39
|
+
*/
|
|
40
|
+
export const REQUIRED_CSS_IMPORTS = [
|
|
41
|
+
'@import "tailwindcss";',
|
|
42
|
+
'@import "astralkit/theme";',
|
|
43
|
+
'@import "astralkit/utilities";',
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the correct CSS imports for the project's Tailwind version.
|
|
48
|
+
*/
|
|
49
|
+
export function getRequiredCssImports(dir = process.cwd()) {
|
|
50
|
+
const twVersion = detectTailwindVersion(dir);
|
|
51
|
+
const tailwindImport = twVersion === 3
|
|
52
|
+
? '@tailwind base;\n@tailwind components;\n@tailwind utilities;'
|
|
53
|
+
: '@import "tailwindcss";';
|
|
54
|
+
return [
|
|
55
|
+
tailwindImport,
|
|
56
|
+
'@import "astralkit/theme";',
|
|
57
|
+
'@import "astralkit/utilities";',
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function detectFramework(dir = process.cwd()) {
|
|
62
|
+
if (
|
|
63
|
+
fs.existsSync(path.join(dir, 'next.config.js')) ||
|
|
64
|
+
fs.existsSync(path.join(dir, 'next.config.mjs')) ||
|
|
65
|
+
fs.existsSync(path.join(dir, 'next.config.ts'))
|
|
66
|
+
) return 'nextjs';
|
|
67
|
+
|
|
68
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
69
|
+
if (fs.existsSync(pkgPath)) {
|
|
70
|
+
try {
|
|
71
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
72
|
+
const allDeps = { ...pkgJson.dependencies, ...pkgJson.devDependencies };
|
|
73
|
+
if (allDeps['react']) return 'react';
|
|
74
|
+
} catch { /* ignore */ }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return 'html';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Detect Tailwind CSS version from package.json.
|
|
82
|
+
* Returns 3, 4, or null.
|
|
83
|
+
*/
|
|
84
|
+
export function detectTailwindVersion(dir = process.cwd()) {
|
|
85
|
+
try {
|
|
86
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
87
|
+
if (!fs.existsSync(pkgPath)) return null;
|
|
88
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
89
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
90
|
+
const ver = deps['tailwindcss'];
|
|
91
|
+
if (!ver) return null;
|
|
92
|
+
const major = parseInt(ver.replace(/[^0-9]/, ''), 10);
|
|
93
|
+
if (major >= 4) return 4;
|
|
94
|
+
if (major === 3) return 3;
|
|
95
|
+
return null;
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Detect if the project uses TypeScript (tsconfig.json exists).
|
|
103
|
+
*/
|
|
104
|
+
export function isTypeScriptProject(dir = process.cwd()) {
|
|
105
|
+
return fs.existsSync(path.join(dir, 'tsconfig.json'));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function isAstralkitInstalled(dir = process.cwd()) {
|
|
109
|
+
return fs.existsSync(path.join(dir, 'node_modules', 'astralkit', 'package.json'));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function findCssEntryFile(dir = process.cwd()) {
|
|
113
|
+
for (const candidate of CSS_ENTRY_CANDIDATES) {
|
|
114
|
+
const filePath = path.join(dir, candidate);
|
|
115
|
+
if (fs.existsSync(filePath)) return { path: filePath, relative: candidate };
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function getMissingCssImports(cssFilePath) {
|
|
121
|
+
try {
|
|
122
|
+
const content = fs.readFileSync(cssFilePath, 'utf8');
|
|
123
|
+
// Check for both v3 and v4 Tailwind directives
|
|
124
|
+
const hasTailwind = content.includes('@import "tailwindcss"') || content.includes('@tailwind base');
|
|
125
|
+
const hasTheme = content.includes('astralkit/theme');
|
|
126
|
+
const hasUtilities = content.includes('astralkit/utilities');
|
|
127
|
+
|
|
128
|
+
const missing = [];
|
|
129
|
+
if (!hasTailwind) missing.push('tailwind');
|
|
130
|
+
if (!hasTheme) missing.push('@import "astralkit/theme";');
|
|
131
|
+
if (!hasUtilities) missing.push('@import "astralkit/utilities";');
|
|
132
|
+
return missing;
|
|
133
|
+
} catch {
|
|
134
|
+
return ['tailwind', '@import "astralkit/theme";', '@import "astralkit/utilities";'];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function addCssImports(cssFilePath, missing, dir = process.cwd()) {
|
|
139
|
+
const existing = fs.existsSync(cssFilePath) ? fs.readFileSync(cssFilePath, 'utf8') : '';
|
|
140
|
+
const twVersion = detectTailwindVersion(dir);
|
|
141
|
+
|
|
142
|
+
const lines = [];
|
|
143
|
+
for (const imp of missing) {
|
|
144
|
+
if (imp === 'tailwind') {
|
|
145
|
+
if (twVersion === 3) {
|
|
146
|
+
lines.push('@tailwind base;', '@tailwind components;', '@tailwind utilities;');
|
|
147
|
+
} else {
|
|
148
|
+
lines.push('@import "tailwindcss";');
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
lines.push(imp);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
fs.writeFileSync(cssFilePath, lines.join('\n') + '\n\n' + existing);
|
|
156
|
+
}
|