@land007/claw 0.1.5
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/claw.js +8 -0
- package/lib/install.js +128 -0
- package/package.json +22 -0
package/bin/claw.js
ADDED
package/lib/install.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const os = require("os");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const { spawnSync } = require("child_process");
|
|
5
|
+
const https = require("https");
|
|
6
|
+
const tar = require("tar");
|
|
7
|
+
|
|
8
|
+
const VERSION = "v0.1.4";
|
|
9
|
+
const REPO = process.env.CLAW_REPO || "land007/claw-code-parity";
|
|
10
|
+
|
|
11
|
+
function platformSlug() {
|
|
12
|
+
switch (process.platform) {
|
|
13
|
+
case "linux":
|
|
14
|
+
return "linux";
|
|
15
|
+
case "darwin":
|
|
16
|
+
return "macos";
|
|
17
|
+
case "win32":
|
|
18
|
+
return "windows";
|
|
19
|
+
default:
|
|
20
|
+
throw new Error(`Unsupported platform: ${process.platform}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function archSlug() {
|
|
25
|
+
switch (process.arch) {
|
|
26
|
+
case "x64":
|
|
27
|
+
return "x86_64";
|
|
28
|
+
case "arm64":
|
|
29
|
+
return "arm64";
|
|
30
|
+
default:
|
|
31
|
+
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function assetName() {
|
|
36
|
+
const osSlug = platformSlug();
|
|
37
|
+
const cpuSlug = archSlug();
|
|
38
|
+
if (osSlug === "windows") {
|
|
39
|
+
return `claw-${VERSION}-windows-${cpuSlug}.zip`;
|
|
40
|
+
}
|
|
41
|
+
return `claw-${VERSION}-${osSlug}-${cpuSlug}.tar.gz`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function binaryName() {
|
|
45
|
+
return process.platform === "win32" ? "claw.exe" : "claw";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function cacheDir() {
|
|
49
|
+
return path.join(os.homedir(), ".cache", "claw", VERSION, `${platformSlug()}-${archSlug()}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function binaryPath() {
|
|
53
|
+
return path.join(cacheDir(), binaryName());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function download(url, dest) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const file = fs.createWriteStream(dest);
|
|
59
|
+
https
|
|
60
|
+
.get(url, (response) => {
|
|
61
|
+
if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
|
|
62
|
+
file.close();
|
|
63
|
+
fs.rmSync(dest, { force: true });
|
|
64
|
+
return resolve(download(response.headers.location, dest));
|
|
65
|
+
}
|
|
66
|
+
if (response.statusCode !== 200) {
|
|
67
|
+
file.close();
|
|
68
|
+
fs.rmSync(dest, { force: true });
|
|
69
|
+
return reject(new Error(`Download failed: ${response.statusCode} ${response.statusMessage}`));
|
|
70
|
+
}
|
|
71
|
+
response.pipe(file);
|
|
72
|
+
file.on("finish", () => file.close(resolve));
|
|
73
|
+
})
|
|
74
|
+
.on("error", (error) => {
|
|
75
|
+
file.close();
|
|
76
|
+
fs.rmSync(dest, { force: true });
|
|
77
|
+
reject(error);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function ensureInstalled() {
|
|
83
|
+
const bin = binaryPath();
|
|
84
|
+
if (fs.existsSync(bin)) return bin;
|
|
85
|
+
|
|
86
|
+
const dir = cacheDir();
|
|
87
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
88
|
+
const asset = assetName();
|
|
89
|
+
const url = `https://github.com/${REPO}/releases/download/${VERSION}/${asset}`;
|
|
90
|
+
const archivePath = path.join(dir, asset);
|
|
91
|
+
|
|
92
|
+
await download(url, archivePath);
|
|
93
|
+
|
|
94
|
+
if (archivePath.endsWith(".tar.gz")) {
|
|
95
|
+
await tar.x({ file: archivePath, cwd: dir });
|
|
96
|
+
} else {
|
|
97
|
+
const result = spawnSync("powershell.exe", ["-NoProfile", "-Command", `Expand-Archive -Path "${archivePath}" -DestinationPath "${dir}" -Force`], {
|
|
98
|
+
stdio: "inherit"
|
|
99
|
+
});
|
|
100
|
+
if (result.status !== 0) {
|
|
101
|
+
throw new Error("Failed to extract Windows archive");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const extractedDir = fs
|
|
106
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
107
|
+
.find((entry) => entry.isDirectory() && entry.name.startsWith("claw-"));
|
|
108
|
+
if (!extractedDir) {
|
|
109
|
+
throw new Error("Downloaded archive did not contain an extracted bundle directory");
|
|
110
|
+
}
|
|
111
|
+
const extractedBinary = path.join(dir, extractedDir.name, binaryName());
|
|
112
|
+
if (!fs.existsSync(extractedBinary)) {
|
|
113
|
+
throw new Error("Downloaded archive did not contain the claw binary");
|
|
114
|
+
}
|
|
115
|
+
fs.copyFileSync(extractedBinary, bin);
|
|
116
|
+
if (process.platform !== "win32") {
|
|
117
|
+
fs.chmodSync(bin, 0o755);
|
|
118
|
+
}
|
|
119
|
+
return bin;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function installAndRun(args) {
|
|
123
|
+
const bin = await ensureInstalled();
|
|
124
|
+
const result = spawnSync(bin, args, { stdio: "inherit" });
|
|
125
|
+
process.exit(result.status === null ? 1 : result.status);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = { installAndRun };
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@land007/claw",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "Cross-platform launcher for claw release binaries",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"claw": "bin/claw.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin",
|
|
14
|
+
"lib"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"tar": "^7.4.3"
|
|
21
|
+
}
|
|
22
|
+
}
|