@relay-core/cli 0.3.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.
Files changed (2) hide show
  1. package/install.js +86 -0
  2. package/package.json +22 -0
package/install.js ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env node
2
+ const { execSync } = require("child_process");
3
+ const { existsSync, mkdirSync } = require("fs");
4
+ const { createWriteStream } = require("fs");
5
+ const { pipeline } = require("stream/promises");
6
+ const { join } = require("path");
7
+ const https = require("https");
8
+
9
+ const PACKAGE = process.env.npm_package_name || "@relay-core/cli";
10
+ const VERSION = process.env.npm_package_version || "0.2.0";
11
+
12
+ // Map (os, arch) → GitHub release target
13
+ function getTarget() {
14
+ const os = process.platform;
15
+ const arch = process.arch;
16
+ const map = {
17
+ "darwin-x64": "x86_64-apple-darwin",
18
+ "darwin-arm64": "aarch64-apple-darwin",
19
+ "linux-x64": "x86_64-unknown-linux-gnu",
20
+ };
21
+ const key = `${os}-${arch}`;
22
+ const target = map[key];
23
+ if (!target) {
24
+ console.error(`Unsupported platform: ${key}. RelayCore currently supports macOS (Intel/Apple Silicon) and Linux (x86_64).`);
25
+ process.exit(1);
26
+ }
27
+ return target;
28
+ }
29
+
30
+ function getBinaryName() {
31
+ return PACKAGE.endsWith("mcp") ? "relay-core-probe" : "relay-core-cli";
32
+ }
33
+
34
+ async function download(url, dest) {
35
+ console.log(`Downloading ${url} → ${dest}`);
36
+ return new Promise((resolve, reject) => {
37
+ const file = createWriteStream(dest);
38
+ https.get(url, (response) => {
39
+ if (response.statusCode === 302 || response.statusCode === 301) {
40
+ https.get(response.headers.location, (redirectRes) => {
41
+ pipeline(redirectRes, file).then(resolve).catch(reject);
42
+ });
43
+ return;
44
+ }
45
+ if (response.statusCode !== 200) {
46
+ reject(new Error(`HTTP ${response.statusCode}`));
47
+ return;
48
+ }
49
+ pipeline(response, file).then(resolve).catch(reject);
50
+ }).on("error", reject);
51
+ });
52
+ }
53
+
54
+ (async () => {
55
+ try {
56
+ const binDir = join(__dirname, "bin");
57
+ const binaryName = getBinaryName();
58
+ const binaryPath = join(binDir, binaryName);
59
+
60
+ // Skip download if binary already exists (re-install)
61
+ if (existsSync(binaryPath)) {
62
+ console.log(`${binaryName} already installed.`);
63
+ return;
64
+ }
65
+
66
+ const target = getTarget();
67
+ const url = `https://github.com/relaycraft/relay-core/releases/download/v${VERSION}/${binaryName}-${target}.tar.gz`;
68
+ const archivePath = join(binDir, `${binaryName}.tar.gz`);
69
+
70
+ mkdirSync(binDir, { recursive: true });
71
+ await download(url, archivePath);
72
+
73
+ console.log("Extracting...");
74
+ execSync(`tar xzf ${archivePath} -C ${binDir}`, { stdio: "inherit" });
75
+
76
+ // Make executable
77
+ if (process.platform !== "win32") {
78
+ execSync(`chmod +x ${binaryPath}`, { stdio: "inherit" });
79
+ }
80
+
81
+ console.log(`${binaryName} v${VERSION} installed.`);
82
+ } catch (err) {
83
+ console.error("Install failed:", err.message);
84
+ process.exit(1);
85
+ }
86
+ })();
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@relay-core/cli",
3
+ "version": "0.3.0",
4
+ "description": "RelayCore CLI — high-performance Rust traffic interception proxy with TUI",
5
+ "license": "MIT",
6
+ "repository": "github:relaycraft/relay-core",
7
+ "bin": {
8
+ "relay-core": "./bin/relay-core-cli"
9
+ },
10
+ "files": [
11
+ "install.js",
12
+ "bin/"
13
+ ],
14
+ "scripts": {
15
+ "postinstall": "node install.js"
16
+ },
17
+ "engines": {
18
+ "node": ">=18"
19
+ },
20
+ "os": ["darwin", "linux"],
21
+ "cpu": ["x64", "arm64"]
22
+ }