@yossydev/entire 0.5.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/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @yossydev/entire
2
+
3
+ npm binary wrapper for the [Entire CLI](https://github.com/entireio/cli).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g @yossydev/entire
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ entire --help
15
+ entire --version
16
+ ```
17
+
18
+ ## How it works
19
+
20
+ This package installs the correct native binary for your platform via `optionalDependencies`. Supported platforms:
21
+
22
+ - macOS ARM64 (Apple Silicon)
23
+ - macOS x64 (Intel)
24
+ - Linux ARM64
25
+ - Linux x64
26
+
27
+ If `--no-optional` is used during installation, the `postinstall` script will download the binary directly from GitHub Releases as a fallback.
28
+
29
+ ## License
30
+
31
+ MIT
package/bin/entire ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { execFileSync } = require("child_process");
6
+ const { binPathForCurrentPlatform } = require("../platform");
7
+
8
+ try {
9
+ const binPath = binPathForCurrentPlatform();
10
+ const result = execFileSync(binPath, process.argv.slice(2), {
11
+ stdio: "inherit",
12
+ });
13
+ } catch (err) {
14
+ if (err.status !== undefined) {
15
+ process.exit(err.status);
16
+ }
17
+ if (err.signal) {
18
+ process.kill(process.pid, err.signal);
19
+ }
20
+ console.error(err.message);
21
+ process.exit(1);
22
+ }
package/install.js ADDED
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ const https = require("https");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const zlib = require("zlib");
7
+ const { pkgForCurrentPlatform } = require("./platform");
8
+
9
+ const version = require("./package.json").version;
10
+
11
+ const PKG_TO_ASSET = {
12
+ "@yossydev/entire-darwin-arm64": "entire_darwin_arm64.tar.gz",
13
+ "@yossydev/entire-darwin-x64": "entire_darwin_amd64.tar.gz",
14
+ "@yossydev/entire-linux-arm64": "entire_linux_arm64.tar.gz",
15
+ "@yossydev/entire-linux-x64": "entire_linux_amd64.tar.gz",
16
+ };
17
+
18
+ function alreadyInstalled() {
19
+ const pkg = pkgForCurrentPlatform();
20
+ try {
21
+ require.resolve(`${pkg}/bin/entire`);
22
+ return true;
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+
28
+ function fetch(url) {
29
+ return new Promise((resolve, reject) => {
30
+ https
31
+ .get(url, (res) => {
32
+ if (
33
+ (res.statusCode === 301 || res.statusCode === 302) &&
34
+ res.headers.location
35
+ ) {
36
+ return fetch(res.headers.location).then(resolve, reject);
37
+ }
38
+ if (res.statusCode !== 200) {
39
+ return reject(
40
+ new Error(`Server responded with ${res.statusCode} for ${url}`)
41
+ );
42
+ }
43
+ const chunks = [];
44
+ res.on("data", (chunk) => chunks.push(chunk));
45
+ res.on("end", () => resolve(Buffer.concat(chunks)));
46
+ })
47
+ .on("error", reject);
48
+ });
49
+ }
50
+
51
+ function extractBinaryFromTarGzip(buffer) {
52
+ const tar = zlib.gunzipSync(buffer);
53
+
54
+ let offset = 0;
55
+ while (offset < tar.length) {
56
+ const header = tar.subarray(offset, offset + 512);
57
+
58
+ // Check for end-of-archive (two consecutive zero blocks)
59
+ if (header.every((b) => b === 0)) {
60
+ break;
61
+ }
62
+
63
+ const name = header
64
+ .subarray(0, 100)
65
+ .toString()
66
+ .replace(/\0.*$/, "");
67
+ const sizeStr = header
68
+ .subarray(124, 136)
69
+ .toString()
70
+ .replace(/\0.*$/, "")
71
+ .trim();
72
+ const size = parseInt(sizeStr, 8);
73
+
74
+ offset += 512;
75
+
76
+ if (!isNaN(size) && size > 0) {
77
+ if (name === "entire" || name === "./entire") {
78
+ return tar.subarray(offset, offset + size);
79
+ }
80
+ offset += Math.ceil(size / 512) * 512;
81
+ }
82
+ }
83
+ throw new Error('Could not find "entire" binary in archive');
84
+ }
85
+
86
+ async function main() {
87
+ if (alreadyInstalled()) {
88
+ return;
89
+ }
90
+
91
+ const pkg = pkgForCurrentPlatform();
92
+ const asset = PKG_TO_ASSET[pkg];
93
+ if (!asset) {
94
+ console.error(`[entire] No download available for package "${pkg}"`);
95
+ process.exit(1);
96
+ }
97
+
98
+ const url = `https://github.com/entireio/cli/releases/download/v${version}/${asset}`;
99
+ console.error(
100
+ `[entire] Platform package not found. Downloading from ${url}`
101
+ );
102
+
103
+ try {
104
+ const tgz = await fetch(url);
105
+ const binary = extractBinaryFromTarGzip(tgz);
106
+
107
+ const binDir = path.join(__dirname, "bin");
108
+ const binPath = path.join(binDir, "entire-binary");
109
+
110
+ fs.mkdirSync(binDir, { recursive: true });
111
+ fs.writeFileSync(binPath, binary);
112
+ fs.chmodSync(binPath, 0o755);
113
+
114
+ console.error(`[entire] Successfully downloaded binary to ${binPath}`);
115
+ } catch (err) {
116
+ console.error(`[entire] Failed to download binary: ${err.message}`);
117
+ console.error(
118
+ `[entire] You can download manually from: https://github.com/entireio/cli/releases`
119
+ );
120
+ process.exit(1);
121
+ }
122
+ }
123
+
124
+ main();
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@yossydev/entire",
3
+ "version": "0.5.0",
4
+ "description": "The Entire CLI - npm binary wrapper",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/entireio/cli.git"
8
+ },
9
+ "license": "MIT",
10
+ "engines": {
11
+ "node": ">=18"
12
+ },
13
+ "bin": {
14
+ "entire": "bin/entire"
15
+ },
16
+ "files": [
17
+ "bin/",
18
+ "platform.js",
19
+ "install.js"
20
+ ],
21
+ "scripts": {
22
+ "postinstall": "node install.js"
23
+ },
24
+ "optionalDependencies": {
25
+ "@yossydev/entire-darwin-arm64": "0.5.0",
26
+ "@yossydev/entire-darwin-x64": "0.5.0",
27
+ "@yossydev/entire-linux-arm64": "0.5.0",
28
+ "@yossydev/entire-linux-x64": "0.5.0"
29
+ }
30
+ }
package/platform.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ const os = require("os");
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+
7
+ const PLATFORMS = {
8
+ "darwin arm64": "@yossydev/entire-darwin-arm64",
9
+ "darwin x64": "@yossydev/entire-darwin-x64",
10
+ "linux arm64": "@yossydev/entire-linux-arm64",
11
+ "linux x64": "@yossydev/entire-linux-x64",
12
+ };
13
+
14
+ function pkgForCurrentPlatform() {
15
+ const key = `${process.platform} ${os.arch()}`;
16
+ const pkg = PLATFORMS[key];
17
+ if (!pkg) {
18
+ throw new Error(
19
+ `Unsupported platform: ${key}. Entire CLI supports: ${Object.keys(PLATFORMS).join(", ")}`
20
+ );
21
+ }
22
+ return pkg;
23
+ }
24
+
25
+ function binPathForCurrentPlatform() {
26
+ const pkg = pkgForCurrentPlatform();
27
+
28
+ // Try to resolve from optionalDependencies first
29
+ try {
30
+ return require.resolve(`${pkg}/bin/entire`);
31
+ } catch {
32
+ // Check if the fallback download placed the binary
33
+ const downloadedPath = path.join(__dirname, "bin", "entire-binary");
34
+ if (fs.existsSync(downloadedPath)) {
35
+ return downloadedPath;
36
+ }
37
+ throw new Error(
38
+ `Could not find the "${pkg}" package. Make sure it is installed. ` +
39
+ `If you use "--no-optional", run the postinstall script manually: node install.js`
40
+ );
41
+ }
42
+ }
43
+
44
+ module.exports = { pkgForCurrentPlatform, binPathForCurrentPlatform, PLATFORMS };