@relay-core/cli 0.3.4 → 0.3.6

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 +1 -110
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -1,111 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const { execSync } = require("child_process");
3
- const { existsSync, mkdirSync, readFileSync } = 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 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
- };
17
-
18
- const PACKAGE = process.env.npm_package_name || "@relay-core/cli";
19
- const VERSION = getVersion();
20
-
21
- // Map (os, arch) → GitHub release target
22
- function getTarget() {
23
- const os = process.platform;
24
- const arch = process.arch;
25
- const map = {
26
- "darwin-x64": "x86_64-apple-darwin",
27
- "darwin-arm64": "aarch64-apple-darwin",
28
- "linux-x64": "x86_64-unknown-linux-gnu",
29
- "win32-x64": "x86_64-pc-windows-msvc",
30
- };
31
- const key = `${os}-${arch}`;
32
- const target = map[key];
33
- if (!target) {
34
- console.error(`Unsupported platform: ${key}. Supported: macOS (x64/arm64), Linux (x64), Windows (x64).`);
35
- process.exit(1);
36
- }
37
- return target;
38
- }
39
-
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
- async function download(url, dest) {
51
- console.log(`Downloading ${url} → ${dest}`);
52
- return new Promise((resolve, reject) => {
53
- const file = createWriteStream(dest);
54
- https.get(url, (response) => {
55
- 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}`));
63
- return;
64
- }
65
- pipeline(response, file).then(resolve).catch(reject);
66
- }).on("error", reject);
67
- });
68
- }
69
-
70
- (async () => {
71
- try {
72
- const binDir = join(__dirname, "bin");
73
- mkdirSync(binDir, { recursive: true });
74
- const binaryName = getBinaryName();
75
- const binaryPath = getBinaryPath(binaryName);
76
-
77
- // Re-download if binary missing or version mismatch
78
- if (existsSync(binaryPath)) {
79
- try {
80
- const out = execSync(`"${binaryPath}" --version`, { encoding: "utf-8", timeout: 5000 }).trim();
81
- if (out.includes(VERSION)) {
82
- console.log(`${binaryName} v${VERSION} already installed.`);
83
- return;
84
- }
85
- console.log(`Installed ${out}, updating to v${VERSION}...`);
86
- } catch {
87
- console.log("Binary exists but failed --version check, re-downloading...");
88
- }
89
- }
90
-
91
- 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}`);
95
-
96
- await download(url, archivePath);
97
-
98
- console.log("Extracting...");
99
- if (process.platform === "win32") {
100
- execSync(`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${binDir}' -Force"`, { stdio: "inherit" });
101
- } else {
102
- execSync(`tar xzf ${archivePath} -C ${binDir}`, { stdio: "inherit" });
103
- execSync(`chmod +x ${binaryPath}`, { stdio: "inherit" });
104
- }
105
-
106
- console.log(`${binaryName} v${VERSION} installed.`);
107
- } catch (err) {
108
- console.error("Install failed:", err.message);
109
- process.exit(1);
110
- }
111
- })();
2
+ require("../shared/install")().catch(() => {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@relay-core/cli",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "RelayCore CLI — high-performance Rust traffic interception proxy with TUI",
5
5
  "license": "MIT",
6
6
  "repository": "github:relaycraft/relay-core",