@followrabbit/cli 0.1.0-beta.1

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.
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { execFileSync } = require("child_process");
6
+ const path = require("path");
7
+ const fs = require("fs");
8
+
9
+ const ext = process.platform === "win32" ? ".exe" : "";
10
+ const binary = path.join(__dirname, `followrabbit${ext}`);
11
+
12
+ if (!fs.existsSync(binary)) {
13
+ console.error(`Error: followrabbit binary not found at ${binary}`);
14
+ console.error("Try reinstalling: npm install -g @followrabbit/cli");
15
+ process.exit(1);
16
+ }
17
+
18
+ try {
19
+ const result = execFileSync(binary, process.argv.slice(2), {
20
+ stdio: "inherit",
21
+ });
22
+ } catch (err) {
23
+ process.exit(err.status || 1);
24
+ }
package/install.js ADDED
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const crypto = require("crypto");
6
+ const https = require("https");
7
+ const fs = require("fs");
8
+ const path = require("path");
9
+ const { execSync } = require("child_process");
10
+ const os = require("os");
11
+
12
+ const REPO = "followrabbit-ai/rabbit-agentic";
13
+ const BINARY_NAME = "followrabbit";
14
+
15
+ function getPlatformInfo() {
16
+ const platform = os.platform();
17
+ const arch = os.arch();
18
+
19
+ const platformMap = {
20
+ darwin: "darwin",
21
+ linux: "linux",
22
+ win32: "windows",
23
+ };
24
+
25
+ const archMap = {
26
+ x64: "amd64",
27
+ arm64: "arm64",
28
+ };
29
+
30
+ const goos = platformMap[platform];
31
+ const goarch = archMap[arch];
32
+
33
+ if (!goos) {
34
+ throw new Error(`Unsupported platform: ${platform}`);
35
+ }
36
+ if (!goarch) {
37
+ throw new Error(`Unsupported architecture: ${arch}`);
38
+ }
39
+
40
+ return { goos, goarch };
41
+ }
42
+
43
+ function getPackageVersion() {
44
+ const pkg = JSON.parse(
45
+ fs.readFileSync(path.join(__dirname, "package.json"), "utf8")
46
+ );
47
+ return pkg.version;
48
+ }
49
+
50
+ function getDownloadUrl(version, goos, goarch) {
51
+ const ext = goos === "windows" ? "zip" : "tar.gz";
52
+ const tag = `cli/v${version}`;
53
+ return `https://github.com/${REPO}/releases/download/${tag}/${BINARY_NAME}_${version}_${goos}_${goarch}.${ext}`;
54
+ }
55
+
56
+ function getChecksumsUrl(version) {
57
+ const tag = `cli/v${version}`;
58
+ return `https://github.com/${REPO}/releases/download/${tag}/checksums.txt`;
59
+ }
60
+
61
+ function downloadFile(url) {
62
+ return new Promise((resolve, reject) => {
63
+ const follow = (url, redirectCount) => {
64
+ if (redirectCount > 5) {
65
+ reject(new Error("Too many redirects"));
66
+ return;
67
+ }
68
+
69
+ const proto = url.startsWith("https") ? https : require("http");
70
+ proto
71
+ .get(url, (res) => {
72
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
73
+ follow(res.headers.location, redirectCount + 1);
74
+ return;
75
+ }
76
+
77
+ if (res.statusCode !== 200) {
78
+ reject(new Error(`Download failed with status ${res.statusCode}: ${url}`));
79
+ return;
80
+ }
81
+
82
+ const chunks = [];
83
+ res.on("data", (chunk) => chunks.push(chunk));
84
+ res.on("end", () => resolve(Buffer.concat(chunks)));
85
+ res.on("error", reject);
86
+ })
87
+ .on("error", reject);
88
+ };
89
+
90
+ follow(url, 0);
91
+ });
92
+ }
93
+
94
+ function verifyChecksum(buffer, checksums, assetName) {
95
+ const lines = checksums.toString("utf8").split("\n");
96
+ const entry = lines.find((line) => line.includes(assetName));
97
+ if (!entry) {
98
+ throw new Error(
99
+ `Checksum entry not found for ${assetName} in checksums.txt`
100
+ );
101
+ }
102
+
103
+ const expectedHash = entry.trim().split(/\s+/)[0];
104
+ const actualHash = crypto.createHash("sha256").update(buffer).digest("hex");
105
+
106
+ if (actualHash !== expectedHash) {
107
+ throw new Error(
108
+ `SHA256 checksum mismatch for ${assetName}:\n` +
109
+ ` expected: ${expectedHash}\n` +
110
+ ` actual: ${actualHash}`
111
+ );
112
+ }
113
+ }
114
+
115
+ async function extractBinary(buffer, goos) {
116
+ const binDir = path.join(__dirname, "bin");
117
+ fs.mkdirSync(binDir, { recursive: true });
118
+
119
+ const binaryName = goos === "windows" ? `${BINARY_NAME}.exe` : BINARY_NAME;
120
+ const destPath = path.join(binDir, binaryName);
121
+
122
+ if (goos === "windows") {
123
+ // Write zip and extract with PowerShell
124
+ const zipPath = path.join(os.tmpdir(), `${BINARY_NAME}.zip`);
125
+ fs.writeFileSync(zipPath, buffer);
126
+ execSync(
127
+ `powershell -Command "Expand-Archive -Path '${zipPath}' -DestinationPath '${binDir}' -Force"`,
128
+ { stdio: "inherit" }
129
+ );
130
+ fs.unlinkSync(zipPath);
131
+ } else {
132
+ // Write tar.gz and extract with tar
133
+ const tarPath = path.join(os.tmpdir(), `${BINARY_NAME}.tar.gz`);
134
+ fs.writeFileSync(tarPath, buffer);
135
+ execSync(`tar -xzf "${tarPath}" -C "${binDir}" ${BINARY_NAME}`, {
136
+ stdio: "inherit",
137
+ });
138
+ fs.unlinkSync(tarPath);
139
+ }
140
+
141
+ // Ensure binary is executable
142
+ if (goos !== "windows") {
143
+ fs.chmodSync(destPath, 0o755);
144
+ }
145
+
146
+ return destPath;
147
+ }
148
+
149
+ async function main() {
150
+ try {
151
+ const { goos, goarch } = getPlatformInfo();
152
+ const version = getPackageVersion();
153
+ const url = getDownloadUrl(version, goos, goarch);
154
+ const ext = goos === "windows" ? "zip" : "tar.gz";
155
+ const assetName = `${BINARY_NAME}_${version}_${goos}_${goarch}.${ext}`;
156
+
157
+ console.log(`Downloading followrabbit v${version} for ${goos}/${goarch}...`);
158
+
159
+ const [buffer, checksums] = await Promise.all([
160
+ downloadFile(url),
161
+ downloadFile(getChecksumsUrl(version)),
162
+ ]);
163
+
164
+ console.log("Verifying SHA256 checksum...");
165
+ verifyChecksum(buffer, checksums, assetName);
166
+
167
+ const destPath = await extractBinary(buffer, goos);
168
+
169
+ console.log(`Installed followrabbit to ${destPath}`);
170
+ } catch (err) {
171
+ console.error(`Failed to install followrabbit: ${err.message}`);
172
+ console.error(
173
+ "You can download the binary manually from https://github.com/followrabbit-ai/rabbit-agentic/releases"
174
+ );
175
+ process.exit(1);
176
+ }
177
+ }
178
+
179
+ main();
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@followrabbit/cli",
3
+ "version": "0.1.0-beta.1",
4
+ "description": "Rabbit cloud cost optimization CLI",
5
+ "homepage": "https://followrabbit.ai",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/followrabbit-ai/rabbit-agentic.git",
9
+ "directory": "cli/npm"
10
+ },
11
+ "license": "Apache-2.0",
12
+ "bin": {
13
+ "followrabbit": "bin/followrabbit.js"
14
+ },
15
+ "scripts": {
16
+ "postinstall": "node install.js"
17
+ },
18
+ "engines": {
19
+ "node": ">=16"
20
+ },
21
+ "keywords": [
22
+ "cloud",
23
+ "cost",
24
+ "optimization",
25
+ "terraform",
26
+ "gcp",
27
+ "cli"
28
+ ]
29
+ }