zyphor 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/bin/zyphor.js +38 -0
- package/package.json +36 -0
- package/scripts/install.js +91 -0
package/bin/zyphor.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const { spawnSync } = require("child_process");
|
|
6
|
+
const { getPlatformInfo, main: installBinary } = require("../scripts/install");
|
|
7
|
+
|
|
8
|
+
async function run() {
|
|
9
|
+
const { binaryName } = getPlatformInfo();
|
|
10
|
+
const binDir = path.join(__dirname);
|
|
11
|
+
const binaryPath = path.join(binDir, binaryName);
|
|
12
|
+
|
|
13
|
+
if (!fs.existsSync(binaryPath)) {
|
|
14
|
+
await installBinary();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(binaryPath)) {
|
|
18
|
+
console.error(`\x1b[31m[Zyphor Error] Native binary not found at ${binaryPath}.\x1b[0m`);
|
|
19
|
+
console.error(`Please install directly via: https://github.com/miyaniakshar1234/Zyphor#readme`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const args = process.argv.slice(2);
|
|
24
|
+
const result = spawnSync(binaryPath, args, {
|
|
25
|
+
stdio: "inherit",
|
|
26
|
+
windowsHide: false,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (result.error) {
|
|
30
|
+
console.error(`[Zyphor Error] Failed to launch binary: ${result.error.message}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
process.exit(result.status !== null ? result.status : 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
run();
|
|
38
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zyphor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Next-generation native terminal system observatory written in pure Zig",
|
|
5
|
+
"main": "bin/zyphor.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"zyphor": "bin/zyphor.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "node scripts/install.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"system-monitor",
|
|
14
|
+
"htop",
|
|
15
|
+
"btop",
|
|
16
|
+
"observability",
|
|
17
|
+
"tui",
|
|
18
|
+
"zig",
|
|
19
|
+
"telemetry",
|
|
20
|
+
"diagnostics",
|
|
21
|
+
"cli"
|
|
22
|
+
],
|
|
23
|
+
"author": "Akshar Miyani <miyaniakshar1234@gmail.com>",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/miyaniakshar1234/Zyphor.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/miyaniakshar1234/Zyphor/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/miyaniakshar1234/Zyphor#readme",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=14.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const { execSync } = require("child_process");
|
|
5
|
+
|
|
6
|
+
const pkg = require("../package.json");
|
|
7
|
+
const REPO = "miyaniakshar1234/Zyphor";
|
|
8
|
+
const VERSION = "v" + pkg.version;
|
|
9
|
+
|
|
10
|
+
function getPlatformInfo() {
|
|
11
|
+
const type = process.platform;
|
|
12
|
+
const arch = process.arch;
|
|
13
|
+
|
|
14
|
+
let os = "";
|
|
15
|
+
if (type === "win32") os = "windows";
|
|
16
|
+
else if (type === "darwin") os = "macos";
|
|
17
|
+
else if (type === "linux") os = "linux";
|
|
18
|
+
else throw new Error(`Unsupported OS platform: ${type}`);
|
|
19
|
+
|
|
20
|
+
let targetArch = "";
|
|
21
|
+
if (arch === "x64") targetArch = "x86_64";
|
|
22
|
+
else if (arch === "arm64") targetArch = "aarch64";
|
|
23
|
+
else throw new Error(`Unsupported CPU architecture: ${arch}`);
|
|
24
|
+
|
|
25
|
+
const ext = os === "windows" ? ".zip" : ".tar.gz";
|
|
26
|
+
const binaryName = os === "windows" ? "zyphor.exe" : "zyphor";
|
|
27
|
+
const assetName = `zyphor-${os}-${targetArch}${ext}`;
|
|
28
|
+
|
|
29
|
+
return { os, arch: targetArch, ext, binaryName, assetName };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function downloadFile(url, dest) {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
https.get(url, (res) => {
|
|
35
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
36
|
+
return downloadFile(res.headers.location, dest).then(resolve).catch(reject);
|
|
37
|
+
}
|
|
38
|
+
if (res.statusCode !== 200) {
|
|
39
|
+
return reject(new Error(`Download failed with HTTP status ${res.statusCode} from ${url}`));
|
|
40
|
+
}
|
|
41
|
+
const fileStream = fs.createWriteStream(dest);
|
|
42
|
+
res.pipe(fileStream);
|
|
43
|
+
fileStream.on("finish", () => {
|
|
44
|
+
fileStream.close();
|
|
45
|
+
resolve();
|
|
46
|
+
});
|
|
47
|
+
fileStream.on("error", reject);
|
|
48
|
+
}).on("error", reject);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function main() {
|
|
53
|
+
try {
|
|
54
|
+
const { os, binaryName, assetName } = getPlatformInfo();
|
|
55
|
+
const binDir = path.join(__dirname, "..", "bin");
|
|
56
|
+
const targetBinary = path.join(binDir, binaryName);
|
|
57
|
+
|
|
58
|
+
if (fs.existsSync(targetBinary)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const downloadUrl = `https://github.com/${REPO}/releases/download/${VERSION}/${assetName}`;
|
|
63
|
+
const tmpArchive = path.join(binDir, assetName);
|
|
64
|
+
|
|
65
|
+
console.log(`[Zyphor] Fetching native binary from ${downloadUrl}...`);
|
|
66
|
+
await downloadFile(downloadUrl, tmpArchive);
|
|
67
|
+
|
|
68
|
+
console.log(`[Zyphor] Unpacking binary package...`);
|
|
69
|
+
if (os === "windows") {
|
|
70
|
+
execSync(`powershell -Command "Expand-Archive -Path '${tmpArchive}' -DestinationPath '${binDir}' -Force"`);
|
|
71
|
+
} else {
|
|
72
|
+
execSync(`tar -xzf "${tmpArchive}" -C "${binDir}"`);
|
|
73
|
+
fs.chmodSync(targetBinary, 0o755);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (fs.existsSync(tmpArchive)) {
|
|
77
|
+
fs.unlinkSync(tmpArchive);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
console.log(`[Zyphor] Native executable successfully installed.`);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.warn(`[Zyphor] Postinstall note: Binary download deferred to initial runtime execution (${err.message})`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (require.main === module) {
|
|
87
|
+
main();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = { getPlatformInfo, downloadFile, main };
|
|
91
|
+
|