kessler-cli 0.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/kessler +21 -0
- package/install.js +107 -0
- package/package.json +30 -0
package/bin/kessler
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execFileSync } = require("child_process");
|
|
4
|
+
const { join } = require("path");
|
|
5
|
+
const { existsSync } = require("fs");
|
|
6
|
+
|
|
7
|
+
const binaryName = process.platform === "win32" ? "kessler.exe" : "kessler";
|
|
8
|
+
const binaryPath = join(__dirname, binaryName);
|
|
9
|
+
|
|
10
|
+
if (!existsSync(binaryPath)) {
|
|
11
|
+
console.error("kessler binary not found. Run 'npm install' to download it.");
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const result = execFileSync(binaryPath, process.argv.slice(2), {
|
|
17
|
+
stdio: "inherit",
|
|
18
|
+
});
|
|
19
|
+
} catch (err) {
|
|
20
|
+
process.exit(err.status || 1);
|
|
21
|
+
}
|
package/install.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execFileSync } = require("child_process");
|
|
4
|
+
const { createWriteStream, mkdirSync, existsSync, unlinkSync } = require("fs");
|
|
5
|
+
const { get } = require("https");
|
|
6
|
+
const { join } = require("path");
|
|
7
|
+
|
|
8
|
+
const pkg = require("./package.json");
|
|
9
|
+
const VERSION = pkg.version;
|
|
10
|
+
const REPO = "hariharen9/kessler";
|
|
11
|
+
|
|
12
|
+
const PLATFORM_MAP = {
|
|
13
|
+
darwin: "darwin",
|
|
14
|
+
linux: "linux",
|
|
15
|
+
win32: "windows",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ARCH_MAP = {
|
|
19
|
+
x64: "amd64",
|
|
20
|
+
arm64: "arm64",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function getBinaryName() {
|
|
24
|
+
return process.platform === "win32" ? "kessler.exe" : "kessler";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getDownloadUrl() {
|
|
28
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
29
|
+
const arch = ARCH_MAP[process.arch];
|
|
30
|
+
|
|
31
|
+
if (!platform || !arch) {
|
|
32
|
+
console.error(`Unsupported platform: ${process.platform} ${process.arch}`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ext = process.platform === "win32" ? "zip" : "tar.gz";
|
|
37
|
+
return `https://github.com/${REPO}/releases/download/v${VERSION}/kessler_${VERSION}_${platform}_${arch}.${ext}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function download(url, dest) {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
get(url, (res) => {
|
|
43
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
44
|
+
return download(res.headers.location, dest).then(resolve).catch(reject);
|
|
45
|
+
}
|
|
46
|
+
if (res.statusCode !== 200) {
|
|
47
|
+
return reject(new Error(`Download failed: HTTP ${res.statusCode}`));
|
|
48
|
+
}
|
|
49
|
+
const file = createWriteStream(dest);
|
|
50
|
+
res.pipe(file);
|
|
51
|
+
file.on("finish", () => {
|
|
52
|
+
file.close();
|
|
53
|
+
resolve();
|
|
54
|
+
});
|
|
55
|
+
file.on("error", reject);
|
|
56
|
+
}).on("error", reject);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function install() {
|
|
61
|
+
const binDir = join(__dirname, "bin");
|
|
62
|
+
const binaryPath = join(binDir, getBinaryName());
|
|
63
|
+
|
|
64
|
+
if (existsSync(binaryPath)) {
|
|
65
|
+
return; // Already installed
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
mkdirSync(binDir, { recursive: true });
|
|
69
|
+
|
|
70
|
+
const url = getDownloadUrl();
|
|
71
|
+
const isWindows = process.platform === "win32";
|
|
72
|
+
const archiveExt = isWindows ? "zip" : "tar.gz";
|
|
73
|
+
const tmpFile = join(binDir, `kessler.${archiveExt}`);
|
|
74
|
+
|
|
75
|
+
console.log(`Downloading kessler v${VERSION}...`);
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
await download(url, tmpFile);
|
|
79
|
+
|
|
80
|
+
// Extract using system tar (available on macOS, Linux, and modern Windows)
|
|
81
|
+
if (isWindows) {
|
|
82
|
+
execFileSync("tar", ["-xf", tmpFile, "-C", binDir, getBinaryName()]);
|
|
83
|
+
} else {
|
|
84
|
+
execFileSync("tar", ["-xzf", tmpFile, "-C", binDir, getBinaryName()]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
unlinkSync(tmpFile);
|
|
88
|
+
|
|
89
|
+
// Make binary executable on Unix
|
|
90
|
+
if (!isWindows) {
|
|
91
|
+
const { chmodSync } = require("fs");
|
|
92
|
+
chmodSync(binaryPath, 0o755);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.log(`kessler v${VERSION} installed successfully!`);
|
|
96
|
+
} catch (err) {
|
|
97
|
+
// Clean up temp file on failure
|
|
98
|
+
if (existsSync(tmpFile)) {
|
|
99
|
+
try { unlinkSync(tmpFile); } catch (_) { }
|
|
100
|
+
}
|
|
101
|
+
console.error(`Failed to install kessler: ${err.message}`);
|
|
102
|
+
console.error(`You can manually download from: https://github.com/${REPO}/releases`);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
install();
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kessler-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "🛰️ Intelligent CLI tool to find and safely clean build artifacts & caches",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cleanup",
|
|
7
|
+
"node_modules",
|
|
8
|
+
"build-artifacts",
|
|
9
|
+
"disk-space",
|
|
10
|
+
"cli",
|
|
11
|
+
"devtools"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/hariharen9/kessler",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/hariharen9/kessler.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Hariharen",
|
|
20
|
+
"bin": {
|
|
21
|
+
"kessler": "bin/kessler"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"postinstall": "node install.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin/",
|
|
28
|
+
"install.js"
|
|
29
|
+
]
|
|
30
|
+
}
|