@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/pkg-manager.js
CHANGED
|
@@ -1,86 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { execa } from 'execa';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Detect the package manager from lockfiles in the project directory.
|
|
7
|
-
* Falls back to npm if nothing detected.
|
|
8
|
-
*/
|
|
9
|
-
function detectPackageManager(dir = process.cwd()) {
|
|
5
|
+
export function detectPackageManager(dir = process.cwd()) {
|
|
10
6
|
if (fs.existsSync(path.join(dir, 'bun.lockb')) || fs.existsSync(path.join(dir, 'bun.lock'))) return 'bun';
|
|
11
7
|
if (fs.existsSync(path.join(dir, 'pnpm-lock.yaml'))) return 'pnpm';
|
|
12
8
|
if (fs.existsSync(path.join(dir, 'yarn.lock'))) return 'yarn';
|
|
13
9
|
return 'npm';
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
* Get the install command for a package manager.
|
|
18
|
-
*/
|
|
19
|
-
function getInstallCommand(pm, packages = []) {
|
|
12
|
+
export function getInstallCommand(pm, packages = []) {
|
|
20
13
|
if (packages.length === 0) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
case 'bun': return 'bun install';
|
|
24
|
-
case 'pnpm': return 'pnpm install';
|
|
25
|
-
case 'yarn': return 'yarn';
|
|
26
|
-
default: return 'npm install';
|
|
27
|
-
}
|
|
14
|
+
const cmds = { bun: 'bun install', pnpm: 'pnpm install', yarn: 'yarn', npm: 'npm install' };
|
|
15
|
+
return cmds[pm] ?? 'npm install';
|
|
28
16
|
}
|
|
29
|
-
|
|
30
|
-
// Install specific packages
|
|
31
17
|
const pkgList = packages.join(' ');
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
case 'pnpm': return `pnpm add ${pkgList}`;
|
|
35
|
-
case 'yarn': return `yarn add ${pkgList}`;
|
|
36
|
-
default: return `npm install ${pkgList}`;
|
|
37
|
-
}
|
|
18
|
+
const cmds = { bun: `bun add ${pkgList}`, pnpm: `pnpm add ${pkgList}`, yarn: `yarn add ${pkgList}`, npm: `npm install ${pkgList}` };
|
|
19
|
+
return cmds[pm] ?? `npm install ${pkgList}`;
|
|
38
20
|
}
|
|
39
21
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
function getRunCommand(pm, script) {
|
|
44
|
-
switch (pm) {
|
|
45
|
-
case 'bun': return `bun run ${script}`;
|
|
46
|
-
case 'pnpm': return `pnpm ${script}`;
|
|
47
|
-
case 'yarn': return `yarn ${script}`;
|
|
48
|
-
default: return `npm run ${script}`;
|
|
49
|
-
}
|
|
22
|
+
export function getRunCommand(pm, script) {
|
|
23
|
+
const cmds = { bun: `bun run ${script}`, pnpm: `pnpm ${script}`, yarn: `yarn ${script}`, npm: `npm run ${script}` };
|
|
24
|
+
return cmds[pm] ?? `npm run ${script}`;
|
|
50
25
|
}
|
|
51
26
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
function getExecCommand(pm) {
|
|
56
|
-
switch (pm) {
|
|
57
|
-
case 'bun': return 'bunx';
|
|
58
|
-
case 'pnpm': return 'pnpx';
|
|
59
|
-
case 'yarn': return 'yarn dlx';
|
|
60
|
-
default: return 'npx';
|
|
61
|
-
}
|
|
27
|
+
export function getExecCommand(pm) {
|
|
28
|
+
const cmds = { bun: 'bunx', pnpm: 'pnpx', yarn: 'yarn dlx', npm: 'npx' };
|
|
29
|
+
return cmds[pm] ?? 'npx';
|
|
62
30
|
}
|
|
63
31
|
|
|
64
32
|
/**
|
|
65
|
-
* Run an install command
|
|
66
|
-
* Returns { success, error
|
|
33
|
+
* Run an install command using execa.
|
|
34
|
+
* Returns { success: true } or { success: false, error, hint, raw }
|
|
67
35
|
*/
|
|
68
|
-
function runInstall(pm, cwd, packages = []) {
|
|
69
|
-
const
|
|
36
|
+
export async function runInstall(pm, cwd, packages = []) {
|
|
37
|
+
const [bin, ...args] = getInstallCommand(pm, packages).split(' ');
|
|
38
|
+
|
|
70
39
|
try {
|
|
71
|
-
|
|
40
|
+
await execa(bin, args, { cwd, timeout: 120_000 });
|
|
72
41
|
return { success: true };
|
|
73
42
|
} catch (err) {
|
|
74
|
-
const stderr = err.stderr
|
|
43
|
+
const stderr = err.stderr || '';
|
|
75
44
|
|
|
76
|
-
// Detect common errors and provide friendly messages
|
|
77
45
|
if (stderr.includes('ERESOLVE') || stderr.includes('peer dep')) {
|
|
78
46
|
return {
|
|
79
47
|
success: false,
|
|
80
48
|
error: 'Dependency conflict detected.',
|
|
81
49
|
hint: pm === 'npm'
|
|
82
50
|
? `Try: npm install ${packages.join(' ')} --legacy-peer-deps`
|
|
83
|
-
: `Try: ${
|
|
51
|
+
: `Try: ${getInstallCommand(pm, packages)} --force`,
|
|
84
52
|
raw: stderr,
|
|
85
53
|
};
|
|
86
54
|
}
|
|
@@ -88,7 +56,7 @@ function runInstall(pm, cwd, packages = []) {
|
|
|
88
56
|
if (stderr.includes('ENOENT') || stderr.includes('not found')) {
|
|
89
57
|
return {
|
|
90
58
|
success: false,
|
|
91
|
-
error: `${pm}
|
|
59
|
+
error: `${pm} not found in PATH.`,
|
|
92
60
|
hint: `Install ${pm} or use a different package manager.`,
|
|
93
61
|
raw: stderr,
|
|
94
62
|
};
|
|
@@ -97,16 +65,8 @@ function runInstall(pm, cwd, packages = []) {
|
|
|
97
65
|
return {
|
|
98
66
|
success: false,
|
|
99
67
|
error: 'Install failed.',
|
|
100
|
-
hint: `Run manually: ${
|
|
68
|
+
hint: `Run manually: ${getInstallCommand(pm, packages)}`,
|
|
101
69
|
raw: stderr.slice(0, 500),
|
|
102
70
|
};
|
|
103
71
|
}
|
|
104
72
|
}
|
|
105
|
-
|
|
106
|
-
module.exports = {
|
|
107
|
-
detectPackageManager,
|
|
108
|
-
getInstallCommand,
|
|
109
|
-
getRunCommand,
|
|
110
|
-
getExecCommand,
|
|
111
|
-
runInstall,
|
|
112
|
-
};
|
package/src/lib/validators.js
CHANGED
|
@@ -1,87 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const VALID_FRAMEWORKS = ['html', 'react', 'nextjs'];
|
|
6
|
-
const SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
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
|
-
* Check if a file path is safely contained within a base directory.
|
|
53
|
-
* Prevents path traversal attacks (e.g., ../../etc/passwd).
|
|
54
|
-
*/
|
|
55
|
-
function isSafePath(basedir, filepath) {
|
|
56
|
-
const resolved = path.resolve(basedir, filepath);
|
|
57
|
-
const relative = path.relative(basedir, resolved);
|
|
58
|
-
return !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Write files to a base directory with path-traversal protection.
|
|
63
|
-
* Returns the number of files successfully written.
|
|
64
|
-
*/
|
|
65
|
-
function writeFiles(baseDir, files) {
|
|
66
|
-
let count = 0;
|
|
67
|
-
for (const file of files) {
|
|
68
|
-
if (!isSafePath(baseDir, file.path)) {
|
|
69
|
-
console.log(chalk.red(` Skipping suspicious file path: ${file.path}`));
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
const filePath = path.resolve(baseDir, file.path);
|
|
73
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
74
|
-
fs.writeFileSync(filePath, file.content);
|
|
75
|
-
count++;
|
|
76
|
-
}
|
|
77
|
-
return count;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
module.exports = {
|
|
81
|
-
VALID_FRAMEWORKS,
|
|
82
|
-
SLUG_PATTERN,
|
|
83
|
-
validateFramework,
|
|
84
|
-
validateSlug,
|
|
85
|
-
isSafePath,
|
|
86
|
-
writeFiles,
|
|
87
|
-
};
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
|
|
5
|
+
export const VALID_FRAMEWORKS = ['html', 'react', 'nextjs'];
|
|
6
|
+
export const SLUG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
7
|
+
|
|
8
|
+
export function validateFramework(framework) {
|
|
9
|
+
if (!framework) return true;
|
|
10
|
+
if (VALID_FRAMEWORKS.includes(framework)) return true;
|
|
11
|
+
console.error(pc.red(`Invalid framework "${framework}".`), pc.gray(`Valid options: ${VALID_FRAMEWORKS.join(', ')}`));
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function validateSlug(slug, label = 'name') {
|
|
16
|
+
if (!slug || typeof slug !== 'string') {
|
|
17
|
+
console.error(pc.red(`${label.charAt(0).toUpperCase() + label.slice(1)} is required.`));
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (slug.length > 128) {
|
|
21
|
+
console.error(pc.red(`${label.charAt(0).toUpperCase() + label.slice(1)} is too long (max 128 chars).`));
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (!SLUG_PATTERN.test(slug)) {
|
|
25
|
+
console.error(pc.red(`Invalid ${label} "${slug}".`), pc.gray('Use lowercase letters, numbers, and hyphens only.'));
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isSafePath(basedir, filepath) {
|
|
32
|
+
const resolved = path.resolve(basedir, filepath);
|
|
33
|
+
const relative = path.relative(basedir, resolved);
|
|
34
|
+
return !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function writeFiles(baseDir, files) {
|
|
38
|
+
let count = 0;
|
|
39
|
+
for (const file of files) {
|
|
40
|
+
if (!isSafePath(baseDir, file.path)) {
|
|
41
|
+
console.log(pc.red(` Skipping suspicious path: ${file.path}`));
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const filePath = path.resolve(baseDir, file.path);
|
|
45
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
46
|
+
fs.writeFileSync(filePath, file.content);
|
|
47
|
+
count++;
|
|
48
|
+
}
|
|
49
|
+
return count;
|
|
50
|
+
}
|