@civiwave/mesh-edge 0.1.2

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 (3) hide show
  1. package/index.js +25 -0
  2. package/install.js +81 -0
  3. package/package.json +36 -0
package/index.js ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require("path");
4
+ const { spawn } = require("child_process");
5
+
6
+ const binaryPath = path.join(__dirname, "bin", "mesh-edge");
7
+
8
+ const child = spawn(binaryPath, process.argv.slice(2), {
9
+ stdio: "inherit",
10
+ });
11
+
12
+ child.on("error", (err) => {
13
+ if (err.code === "ENOENT") {
14
+ console.error(
15
+ "mesh-edge binary not found. Run `npm rebuild @civiwave/mesh-edge` to install it."
16
+ );
17
+ } else {
18
+ console.error(`Failed to start mesh-edge: ${err.message}`);
19
+ }
20
+ process.exit(1);
21
+ });
22
+
23
+ child.on("exit", (code) => {
24
+ process.exit(code || 0);
25
+ });
package/install.js ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const axios = require("axios");
6
+ const ProgressBar = require("progress");
7
+ const tar = require("tar");
8
+ const packageJson = require("./package.json");
9
+
10
+ const binaryDir = path.join(__dirname, "bin");
11
+ const binaryPath = path.join(binaryDir, "mesh-edge");
12
+ const version = packageJson.version;
13
+
14
+ function platformInfo() {
15
+ const platforms = { darwin: "darwin", linux: "linux", win32: "windows" };
16
+ const arches = { x64: "amd64", arm64: "arm64" };
17
+
18
+ const os = platforms[process.platform];
19
+ const arch = arches[process.arch];
20
+
21
+ if (!os || !arch) {
22
+ console.error(
23
+ `Unsupported platform: ${process.platform}/${process.arch}`
24
+ );
25
+ process.exit(1);
26
+ }
27
+
28
+ return { os, arch };
29
+ }
30
+
31
+ async function download() {
32
+ if (fs.existsSync(binaryPath)) {
33
+ return;
34
+ }
35
+
36
+ const { os, arch } = platformInfo();
37
+ const assetName = `mesh-edge_${version}_${os}_${arch}.tar.gz`;
38
+ const url = `https://github.com/civiwave/mesh-edge/releases/download/v${version}/${assetName}`;
39
+
40
+ console.log(`Downloading mesh-edge v${version} (${os}/${arch})...`);
41
+
42
+ const { data, headers } = await axios({
43
+ url,
44
+ method: "GET",
45
+ responseType: "stream",
46
+ });
47
+
48
+ const totalLength = headers["content-length"];
49
+ const bar = new ProgressBar(" [:bar] :percent :etas", {
50
+ width: 40,
51
+ complete: "=",
52
+ incomplete: " ",
53
+ total: parseInt(totalLength || "0"),
54
+ });
55
+
56
+ if (!fs.existsSync(binaryDir)) {
57
+ fs.mkdirSync(binaryDir, { recursive: true });
58
+ }
59
+
60
+ const tarPath = path.join(binaryDir, assetName);
61
+ const writer = fs.createWriteStream(tarPath);
62
+
63
+ data.on("data", (chunk) => bar.tick(chunk.length));
64
+ data.pipe(writer);
65
+
66
+ return new Promise((resolve, reject) => {
67
+ writer.on("finish", async () => {
68
+ await tar.x({ file: tarPath, C: binaryDir });
69
+ fs.unlinkSync(tarPath);
70
+ fs.chmodSync(binaryPath, 0o755);
71
+ console.log(`Installed mesh-edge v${version}`);
72
+ resolve();
73
+ });
74
+ writer.on("error", reject);
75
+ });
76
+ }
77
+
78
+ download().catch((err) => {
79
+ console.error(`Failed to install mesh-edge: ${err.message}`);
80
+ process.exit(1);
81
+ });
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@civiwave/mesh-edge",
3
+ "version": "0.1.2",
4
+ "description": "Civiwave edge runtime — decentralized compute node (keeper, miner, validator)",
5
+ "bin": {
6
+ "mesh-edge": "./index.js"
7
+ },
8
+ "main": "index.js",
9
+ "scripts": {
10
+ "postinstall": "node install.js",
11
+ "test": "echo \"No tests\" && exit 0"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/civiwave/mesh-edge.git"
16
+ },
17
+ "keywords": [
18
+ "civiwave",
19
+ "edge",
20
+ "keeper",
21
+ "wasm",
22
+ "ai",
23
+ "decentralized"
24
+ ],
25
+ "author": "Civiwave",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/civiwave/mesh-edge/issues"
29
+ },
30
+ "homepage": "https://github.com/civiwave/mesh-edge#readme",
31
+ "dependencies": {
32
+ "axios": "^1.7.0",
33
+ "progress": "^2.0.3",
34
+ "tar": "^7.4.0"
35
+ }
36
+ }