binthere-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/README.md +24 -0
- package/bin/binthere.js +24 -0
- package/install.js +114 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# npm wrapper
|
|
2
|
+
|
|
3
|
+
This folder contains an npm package that installs the prebuilt BinThere binary from GitHub Releases and exposes the `binthere` command.
|
|
4
|
+
|
|
5
|
+
## Setup before publish
|
|
6
|
+
|
|
7
|
+
1. Edit `package.json` and set `binthereBinary.repo` to your repository, for example:
|
|
8
|
+
- `ilyas/binthere`
|
|
9
|
+
2. Ensure a matching GitHub release exists for the npm version, for example:
|
|
10
|
+
- npm version `0.1.0` -> git tag/release `v0.1.0`
|
|
11
|
+
|
|
12
|
+
## Publish
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
cd npm
|
|
16
|
+
npm publish --access public
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Install for users
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm i -g binthere-cli
|
|
23
|
+
binthere --help
|
|
24
|
+
```
|
package/bin/binthere.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const cp = require("node:child_process");
|
|
5
|
+
|
|
6
|
+
const isWin = process.platform === "win32";
|
|
7
|
+
const exeName = isWin ? "binthere.exe" : "binthere";
|
|
8
|
+
const binPath = path.join(__dirname, exeName);
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(binPath)) {
|
|
11
|
+
console.error(
|
|
12
|
+
"BinThere binary is missing. Reinstall package or run: npm rebuild binthere-cli"
|
|
13
|
+
);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const child = cp.spawn(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
18
|
+
child.on("exit", (code, signal) => {
|
|
19
|
+
if (signal) {
|
|
20
|
+
process.kill(process.pid, signal);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
process.exit(code ?? 1);
|
|
24
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const https = require("node:https");
|
|
5
|
+
const os = require("node:os");
|
|
6
|
+
const AdmZip = require("adm-zip");
|
|
7
|
+
const tar = require("tar");
|
|
8
|
+
|
|
9
|
+
const pkg = require("./package.json");
|
|
10
|
+
const outDir = path.join(__dirname, "bin");
|
|
11
|
+
|
|
12
|
+
const map = {
|
|
13
|
+
"win32-x64": {
|
|
14
|
+
asset: "binthere-x86_64-pc-windows-msvc.zip",
|
|
15
|
+
binary: "binthere.exe",
|
|
16
|
+
kind: "zip",
|
|
17
|
+
},
|
|
18
|
+
"linux-x64": {
|
|
19
|
+
asset: "binthere-x86_64-unknown-linux-gnu.tar.gz",
|
|
20
|
+
binary: "binthere",
|
|
21
|
+
kind: "tar",
|
|
22
|
+
},
|
|
23
|
+
"darwin-x64": {
|
|
24
|
+
asset: "binthere-x86_64-apple-darwin.tar.gz",
|
|
25
|
+
binary: "binthere",
|
|
26
|
+
kind: "tar",
|
|
27
|
+
},
|
|
28
|
+
"darwin-arm64": {
|
|
29
|
+
asset: "binthere-aarch64-apple-darwin.tar.gz",
|
|
30
|
+
binary: "binthere",
|
|
31
|
+
kind: "tar",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const key = `${process.platform}-${process.arch}`;
|
|
36
|
+
const target = map[key];
|
|
37
|
+
|
|
38
|
+
if (!target) {
|
|
39
|
+
console.error(`Unsupported platform: ${key}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const repo = process.env.BINTHERE_REPO || pkg.binthereBinary?.repo;
|
|
44
|
+
if (!repo || repo.includes("REPLACE_WITH")) {
|
|
45
|
+
console.error(
|
|
46
|
+
"npm package is missing GitHub repo config. Set package.json -> binthereBinary.repo."
|
|
47
|
+
);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const version = pkg.version;
|
|
52
|
+
const tagPrefix = pkg.binthereBinary?.tagPrefix || "v";
|
|
53
|
+
const tag = `${tagPrefix}${version}`;
|
|
54
|
+
const url = `https://github.com/${repo}/releases/download/${tag}/${target.asset}`;
|
|
55
|
+
|
|
56
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
57
|
+
const archivePath = path.join(os.tmpdir(), target.asset);
|
|
58
|
+
|
|
59
|
+
console.log(`Downloading BinThere ${version} for ${key}...`);
|
|
60
|
+
download(url, archivePath)
|
|
61
|
+
.then(async () => {
|
|
62
|
+
if (target.kind === "zip") {
|
|
63
|
+
const zip = new AdmZip(archivePath);
|
|
64
|
+
zip.extractAllTo(outDir, true);
|
|
65
|
+
} else {
|
|
66
|
+
await tar.x({ file: archivePath, cwd: outDir });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const binPath = path.join(outDir, target.binary);
|
|
70
|
+
if (!fs.existsSync(binPath)) {
|
|
71
|
+
throw new Error(`Binary not found after extraction: ${binPath}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (process.platform !== "win32") {
|
|
75
|
+
fs.chmodSync(binPath, 0o755);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log(`Installed ${target.binary}`);
|
|
79
|
+
})
|
|
80
|
+
.catch((err) => {
|
|
81
|
+
console.error(`Failed to install binary: ${err.message}`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
function download(url, dest) {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
const file = fs.createWriteStream(dest);
|
|
88
|
+
https
|
|
89
|
+
.get(url, (res) => {
|
|
90
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
91
|
+
file.close();
|
|
92
|
+
fs.unlink(dest, () => {
|
|
93
|
+
download(res.headers.location, dest).then(resolve).catch(reject);
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (res.statusCode !== 200) {
|
|
99
|
+
file.close();
|
|
100
|
+
fs.unlink(dest, () => reject(new Error(`HTTP ${res.statusCode} from ${url}`)));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
res.pipe(file);
|
|
105
|
+
file.on("finish", () => {
|
|
106
|
+
file.close(resolve);
|
|
107
|
+
});
|
|
108
|
+
})
|
|
109
|
+
.on("error", (err) => {
|
|
110
|
+
file.close();
|
|
111
|
+
fs.unlink(dest, () => reject(err));
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "binthere-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "BinThere CLI binary installer",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"bin": {
|
|
7
|
+
"binthere": "bin/binthere.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "node install.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin",
|
|
14
|
+
"install.js"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"adm-zip": "^0.5.16",
|
|
21
|
+
"tar": "^7.4.3"
|
|
22
|
+
},
|
|
23
|
+
"binthereBinary": {
|
|
24
|
+
"repo": "iliasmahboub/binthere",
|
|
25
|
+
"tagPrefix": "v"
|
|
26
|
+
}
|
|
27
|
+
}
|