@relay-core/cli 0.3.5 → 0.3.7

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 +30 -52
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -1,109 +1,87 @@
1
1
  #!/usr/bin/env node
2
+ "use strict";
3
+
2
4
  const { execSync } = require("child_process");
3
- const { existsSync, mkdirSync, readFileSync } = require("fs");
4
- const { createWriteStream } = require("fs");
5
+ const { existsSync, mkdirSync, readFileSync, createWriteStream } = require("fs");
5
6
  const { pipeline } = require("stream/promises");
6
7
  const { join } = require("path");
7
8
  const https = require("https");
8
9
 
9
- const getVersion = () => {
10
- try {
11
- const pkg = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf-8"));
12
- return pkg.version;
13
- } catch {
14
- return "0.3.0";
15
- }
16
- };
10
+ const PKG_DIR = join(__dirname, "..");
11
+ const BINARY_NAME = "relay-core-cli";
17
12
 
18
- const PACKAGE = process.env.npm_package_name || "@relay-core/cli";
19
- const VERSION = getVersion();
13
+ function getVersion() {
14
+ try {
15
+ return JSON.parse(readFileSync(join(PKG_DIR, "package.json"), "utf-8")).version;
16
+ } catch { return "0.3.0"; }
17
+ }
20
18
 
21
- // Map (os, arch) → GitHub release target
22
19
  function getTarget() {
23
- const os = process.platform;
24
- const arch = process.arch;
25
20
  const map = {
26
21
  "darwin-x64": "x86_64-apple-darwin",
27
22
  "darwin-arm64": "aarch64-apple-darwin",
28
23
  "linux-x64": "x86_64-unknown-linux-gnu",
24
+ "linux-arm64": "aarch64-unknown-linux-gnu",
29
25
  "win32-x64": "x86_64-pc-windows-msvc",
30
26
  };
31
- const key = `${os}-${arch}`;
32
- const target = map[key];
27
+ const target = map[`${process.platform}-${process.arch}`];
33
28
  if (!target) {
34
- console.error(`Unsupported platform: ${key}. Supported: macOS (x64/arm64), Linux (x64), Windows (x64).`);
29
+ console.error(`Unsupported platform: ${process.platform}-${process.arch}. macOS/Linux/Windows (x64/arm64) supported.`);
35
30
  process.exit(1);
36
31
  }
37
32
  return target;
38
33
  }
39
34
 
40
- function getBinaryName() {
41
- return PACKAGE.endsWith("mcp") ? "relay-core-probe" : "relay-core-cli";
42
- }
43
-
44
- function getBinaryPath(binaryName) {
45
- return process.platform === "win32"
46
- ? join(__dirname, "bin", binaryName + ".exe")
47
- : join(__dirname, "bin", binaryName);
48
- }
49
-
50
35
  async function download(url, dest) {
51
36
  console.log(`Downloading ${url} → ${dest}`);
52
37
  return new Promise((resolve, reject) => {
53
38
  const file = createWriteStream(dest);
54
39
  https.get(url, (response) => {
55
40
  if (response.statusCode === 302 || response.statusCode === 301) {
56
- https.get(response.headers.location, (redirectRes) => {
57
- pipeline(redirectRes, file).then(resolve).catch(reject);
58
- });
59
- return;
60
- }
61
- if (response.statusCode !== 200) {
62
- reject(new Error(`HTTP ${response.statusCode}`));
41
+ https.get(response.headers.location, (rr) => pipeline(rr, file).then(resolve, reject));
63
42
  return;
64
43
  }
65
- pipeline(response, file).then(resolve).catch(reject);
44
+ if (response.statusCode !== 200) return reject(new Error(`HTTP ${response.statusCode}`));
45
+ pipeline(response, file).then(resolve, reject);
66
46
  }).on("error", reject);
67
47
  });
68
48
  }
69
49
 
70
50
  (async () => {
71
51
  try {
72
- const binDir = join(__dirname, "bin");
52
+ const binDir = join(PKG_DIR, "bin");
73
53
  mkdirSync(binDir, { recursive: true });
74
- const binaryName = getBinaryName();
75
- const binaryPath = getBinaryPath(binaryName);
76
54
 
77
- // Re-download if binary missing or version mismatch
55
+ const ext = process.platform === "win32" ? ".exe" : "";
56
+ const binaryPath = join(binDir, BINARY_NAME + ext);
57
+ const version = getVersion();
58
+
78
59
  if (existsSync(binaryPath)) {
79
60
  try {
80
61
  const out = execSync(`"${binaryPath}" --version`, { encoding: "utf-8", timeout: 5000 }).trim();
81
- if (out.includes(VERSION)) {
82
- console.log(`${binaryName} v${VERSION} already installed.`);
62
+ if (out.includes(version)) {
63
+ console.log(`${BINARY_NAME} v${version} already installed.`);
83
64
  return;
84
65
  }
85
- console.log(`Installed ${out}, updating to v${VERSION}...`);
86
- } catch {
87
- console.log("Binary exists but failed --version check, re-downloading...");
88
- }
66
+ console.log(`Installed ${out}, updating to v${version}...`);
67
+ } catch { console.log("Re-downloading..."); }
89
68
  }
90
69
 
91
70
  const target = getTarget();
92
- const ext = process.platform === "win32" ? "zip" : "tar.gz";
93
- const url = `https://github.com/relaycraft/relay-core/releases/download/v${VERSION}/${binaryName}-${target}.${ext}`;
94
- const archivePath = join(binDir, `${binaryName}.${ext}`);
71
+ const archiveExt = process.platform === "win32" ? "zip" : "tar.gz";
72
+ const url = `https://github.com/relaycraft/relay-core/releases/download/v${version}/${BINARY_NAME}-${target}.${archiveExt}`;
73
+ const archivePath = join(binDir, `${BINARY_NAME}.${archiveExt}`);
95
74
 
96
75
  await download(url, archivePath);
97
-
98
76
  console.log("Extracting...");
77
+
99
78
  if (process.platform === "win32") {
100
79
  execSync(`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${binDir}' -Force"`, { stdio: "inherit" });
101
80
  } else {
102
81
  execSync(`tar xzf ${archivePath} -C ${binDir}`, { stdio: "inherit" });
103
82
  execSync(`chmod +x ${binaryPath}`, { stdio: "inherit" });
104
83
  }
105
-
106
- console.log(`${binaryName} v${VERSION} installed.`);
84
+ console.log(`${BINARY_NAME} v${version} installed.`);
107
85
  } catch (err) {
108
86
  console.error("Install failed:", err.message);
109
87
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relay-core/cli",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "RelayCore CLI — high-performance Rust traffic interception proxy with TUI",
5
5
  "license": "MIT",
6
6
  "repository": "github:relaycraft/relay-core",