@decodeex/bifu-cli 1.0.1

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.
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ // Thin launcher: exec the native bifu-cli binary fetched by install.js.
3
+ "use strict";
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+ const { spawnSync } = require("child_process");
7
+
8
+ const bin = path.join(
9
+ __dirname,
10
+ process.platform === "win32" ? "bifu-cli.exe" : "bifu-cli"
11
+ );
12
+
13
+ if (!fs.existsSync(bin)) {
14
+ console.error(
15
+ "bifu-cli binary not found. Reinstall the package, or grab a build from " +
16
+ "https://github.com/decodeex/bifu-cli-releases/releases"
17
+ );
18
+ process.exit(1);
19
+ }
20
+
21
+ const res = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
22
+ if (res.error) {
23
+ console.error(res.error.message);
24
+ process.exit(1);
25
+ }
26
+ process.exit(res.status === null ? 1 : res.status);
package/install.js ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ // postinstall: download the platform-matching bifu-cli release binary from
3
+ // GitHub into ./bin, so the bin/bifu-cli.js launcher can exec it.
4
+ "use strict";
5
+ const fs = require("fs");
6
+ const os = require("os");
7
+ const path = require("path");
8
+ const https = require("https");
9
+ const { execFileSync } = require("child_process");
10
+
11
+ const REPO = "decodeex/bifu-cli-releases"; // public repo hosting the binaries
12
+ const pkg = require("./package.json");
13
+
14
+ const OS = { darwin: "darwin", linux: "linux", win32: "windows" }[process.platform];
15
+ const ARCH = { x64: "amd64", arm64: "arm64" }[process.arch];
16
+
17
+ function fail(msg) {
18
+ console.error("bifu-cli install: " + msg);
19
+ console.error(" Download manually: https://github.com/" + REPO + "/releases");
20
+ process.exit(0); // don't hard-fail npm install; the launcher will warn if missing
21
+ }
22
+
23
+ if (!OS || !ARCH) fail("unsupported platform " + process.platform + "/" + process.arch);
24
+ if (!pkg.version || pkg.version === "0.0.0") fail("no release version set");
25
+
26
+ const asset = `bifu-cli_${OS}_${ARCH}.tar.gz`;
27
+ const url = `https://github.com/${REPO}/releases/download/v${pkg.version}/${asset}`;
28
+ const binDir = path.join(__dirname, "bin");
29
+ const tmp = path.join(os.tmpdir(), asset);
30
+
31
+ function download(u, dest, cb, redirects) {
32
+ redirects = redirects || 0;
33
+ if (redirects > 10) return cb(new Error("too many redirects"));
34
+ https
35
+ .get(u, { headers: { "User-Agent": "bifu-cli-npm" } }, (res) => {
36
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
37
+ res.resume();
38
+ return download(res.headers.location, dest, cb, redirects + 1);
39
+ }
40
+ if (res.statusCode !== 200) {
41
+ res.resume();
42
+ return cb(new Error("HTTP " + res.statusCode + " for " + u));
43
+ }
44
+ const file = fs.createWriteStream(dest);
45
+ res.pipe(file);
46
+ file.on("finish", () => file.close(cb));
47
+ })
48
+ .on("error", cb);
49
+ }
50
+
51
+ fs.mkdirSync(binDir, { recursive: true });
52
+ console.log("bifu-cli: downloading " + asset + " ...");
53
+ download(url, tmp, (err) => {
54
+ if (err) return fail(err.message);
55
+ try {
56
+ // tar handles both .tar.gz and .zip on macOS/Linux/Windows 10+ (bsdtar).
57
+ execFileSync("tar", ["-xf", tmp, "-C", binDir], { stdio: "ignore" });
58
+ const bin = path.join(binDir, OS === "windows" ? "bifu-cli.exe" : "bifu-cli");
59
+ if (!fs.existsSync(bin)) return fail("binary missing after extract");
60
+ if (OS !== "windows") fs.chmodSync(bin, 0o755);
61
+ fs.unlinkSync(tmp);
62
+ console.log("bifu-cli: installed " + pkg.version + " (" + OS + "/" + ARCH + ")");
63
+ } catch (e) {
64
+ fail("extract failed: " + e.message);
65
+ }
66
+ });
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@decodeex/bifu-cli",
3
+ "version": "1.0.1",
4
+ "description": "BifuFX trading platform CLI — spot, contract, forex, WebSocket, MCP",
5
+ "bin": {
6
+ "bifu-cli": "bin/bifu-cli.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node ./install.js"
10
+ },
11
+ "files": [
12
+ "bin/bifu-cli.js",
13
+ "install.js"
14
+ ],
15
+ "engines": {
16
+ "node": ">=16"
17
+ },
18
+ "os": [
19
+ "darwin",
20
+ "linux",
21
+ "win32"
22
+ ],
23
+ "cpu": [
24
+ "x64",
25
+ "arm64"
26
+ ],
27
+ "keywords": [
28
+ "bifu",
29
+ "bifufx",
30
+ "trading",
31
+ "cli",
32
+ "crypto",
33
+ "forex",
34
+ "mcp"
35
+ ],
36
+ "homepage": "https://cli.bifu.dev",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/decodeex/bifu-cli.git"
40
+ },
41
+ "license": "MIT"
42
+ }