@wahooks/cli 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.
Files changed (3) hide show
  1. package/bin/wahooks +3 -0
  2. package/install.js +78 -0
  3. package/package.json +19 -0
package/bin/wahooks ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ echo "wahooks CLI not installed. Run: npm rebuild @wahooks/cli"
3
+ exit 1
package/install.js ADDED
@@ -0,0 +1,78 @@
1
+ const { execSync } = require("child_process");
2
+ const fs = require("fs");
3
+ const https = require("https");
4
+ const path = require("path");
5
+ const os = require("os");
6
+
7
+ const REPO = "dhruvyad/wahooks";
8
+ const BIN_DIR = path.join(__dirname, "bin");
9
+ const BIN_PATH = path.join(BIN_DIR, process.platform === "win32" ? "wahooks.exe" : "wahooks");
10
+
11
+ function getPlatform() {
12
+ const platform = process.platform;
13
+ const arch = process.arch;
14
+
15
+ const osMap = { darwin: "darwin", linux: "linux", win32: "windows" };
16
+ const archMap = { x64: "amd64", arm64: "arm64" };
17
+
18
+ const goos = osMap[platform];
19
+ const goarch = archMap[arch];
20
+
21
+ if (!goos || !goarch) {
22
+ throw new Error(`Unsupported platform: ${platform}/${arch}`);
23
+ }
24
+
25
+ return { goos, goarch };
26
+ }
27
+
28
+ function fetch(url) {
29
+ return new Promise((resolve, reject) => {
30
+ https.get(url, { headers: { "User-Agent": "wahooks-cli-npm" } }, (res) => {
31
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
32
+ return fetch(res.headers.location).then(resolve, reject);
33
+ }
34
+ if (res.statusCode !== 200) {
35
+ return reject(new Error(`HTTP ${res.statusCode}`));
36
+ }
37
+ const chunks = [];
38
+ res.on("data", (c) => chunks.push(c));
39
+ res.on("end", () => resolve(Buffer.concat(chunks)));
40
+ res.on("error", reject);
41
+ }).on("error", reject);
42
+ });
43
+ }
44
+
45
+ async function install() {
46
+ const { goos, goarch } = getPlatform();
47
+ const ext = goos === "windows" ? ".exe" : "";
48
+ const assetName = `wahooks-${goos}-${goarch}${ext}`;
49
+
50
+ // Find latest CLI release
51
+ const releasesData = await fetch(`https://api.github.com/repos/${REPO}/releases`);
52
+ const releases = JSON.parse(releasesData.toString());
53
+ const cliRelease = releases.find((r) => r.tag_name.startsWith("cli-v"));
54
+
55
+ if (!cliRelease) {
56
+ throw new Error("No CLI release found. Please install from source: https://github.com/dhruvyad/wahooks/tree/main/cli");
57
+ }
58
+
59
+ const asset = cliRelease.assets.find((a) => a.name === assetName);
60
+ if (!asset) {
61
+ throw new Error(`No binary found for ${goos}/${goarch} in release ${cliRelease.tag_name}`);
62
+ }
63
+
64
+ console.log(`Downloading wahooks ${cliRelease.tag_name} for ${goos}/${goarch}...`);
65
+ const binary = await fetch(asset.browser_download_url);
66
+
67
+ fs.mkdirSync(BIN_DIR, { recursive: true });
68
+ fs.writeFileSync(BIN_PATH, binary);
69
+ fs.chmodSync(BIN_PATH, 0o755);
70
+
71
+ console.log("wahooks CLI installed successfully.");
72
+ }
73
+
74
+ install().catch((err) => {
75
+ console.error("Failed to install wahooks CLI:", err.message);
76
+ console.error("You can install manually: curl -fsSL https://raw.githubusercontent.com/dhruvyad/wahooks/main/cli/install.sh | bash");
77
+ process.exit(1);
78
+ });
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@wahooks/cli",
3
+ "version": "0.1.0",
4
+ "description": "WAHooks CLI — manage WhatsApp connections, webhooks, and billing",
5
+ "bin": {
6
+ "wahooks": "bin/wahooks"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "files": ["bin", "install.js"],
12
+ "keywords": ["wahooks", "whatsapp", "cli", "webhook"],
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/dhruvyad/wahooks",
17
+ "directory": "sdks/cli-npm"
18
+ }
19
+ }