goldy-cli 1.2.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/goldy +34 -0
  2. package/install.js +127 -0
  3. package/package.json +33 -0
package/bin/goldy ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ const { execFileSync, execSync } = require("child_process");
3
+ const path = require("path");
4
+ const os = require("os");
5
+ const fs = require("fs");
6
+
7
+ const binSuffix = os.platform() === "win32" ? ".exe" : "";
8
+ const binPath = path.join(__dirname, `goldy${binSuffix}`);
9
+
10
+ // If binary exists locally (global install or npx cache), just run it
11
+ if (fs.existsSync(binPath)) {
12
+ try {
13
+ execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
14
+ } catch (err) {
15
+ if (err.status !== undefined) process.exit(err.status);
16
+ process.exit(1);
17
+ }
18
+ process.exit(0);
19
+ }
20
+
21
+ // Binary not found — we're running via npx without a cached binary
22
+ // Install globally so `goldy` works as a standalone command next time
23
+ console.log("Installing goldy globally...\n");
24
+ try {
25
+ execSync("npm install -g goldy-cli", { stdio: "inherit" });
26
+ console.log("\nDone! You can now run: goldy");
27
+
28
+ // Run it immediately after global install
29
+ execSync("goldy " + process.argv.slice(2).join(" "), { stdio: "inherit" });
30
+ } catch (err) {
31
+ if (err.status !== undefined) process.exit(err.status);
32
+ console.error("Global install failed. Try manually: npm install -g goldy-cli");
33
+ process.exit(1);
34
+ }
package/install.js ADDED
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env node
2
+ const { execSync } = require("child_process");
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const https = require("https");
6
+ const os = require("os");
7
+
8
+ const REPO = "SacredTexts/goldy";
9
+ const BIN_NAME = "goldy";
10
+ const BIN_DIR = path.join(__dirname, "bin");
11
+
12
+ function getPlatform() {
13
+ const platform = os.platform();
14
+ const arch = os.arch();
15
+
16
+ const platformMap = {
17
+ darwin: "darwin",
18
+ linux: "linux",
19
+ win32: "windows",
20
+ };
21
+
22
+ const archMap = {
23
+ x64: "amd64",
24
+ arm64: "arm64",
25
+ };
26
+
27
+ const goos = platformMap[platform];
28
+ const goarch = archMap[arch];
29
+
30
+ if (!goos || !goarch) {
31
+ console.error(`Unsupported platform: ${platform}/${arch}`);
32
+ process.exit(1);
33
+ }
34
+
35
+ return { goos, goarch, isWindows: platform === "win32" };
36
+ }
37
+
38
+ function getVersion() {
39
+ const pkg = require("./package.json");
40
+ return pkg.version;
41
+ }
42
+
43
+ function downloadFile(url) {
44
+ return new Promise((resolve, reject) => {
45
+ const follow = (url, redirects = 0) => {
46
+ if (redirects > 5) return reject(new Error("Too many redirects"));
47
+
48
+ https
49
+ .get(url, { headers: { "User-Agent": "goldy-npm" } }, (res) => {
50
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
51
+ return follow(res.headers.location, redirects + 1);
52
+ }
53
+ if (res.statusCode !== 200) {
54
+ return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
55
+ }
56
+ const chunks = [];
57
+ res.on("data", (chunk) => chunks.push(chunk));
58
+ res.on("end", () => resolve(Buffer.concat(chunks)));
59
+ res.on("error", reject);
60
+ })
61
+ .on("error", reject);
62
+ };
63
+ follow(url);
64
+ });
65
+ }
66
+
67
+ async function extractTarGz(buffer, destDir) {
68
+ const tmpFile = path.join(os.tmpdir(), `goldy-${Date.now()}.tar.gz`);
69
+ fs.writeFileSync(tmpFile, buffer);
70
+ fs.mkdirSync(destDir, { recursive: true });
71
+ execSync(`tar -xzf "${tmpFile}" -C "${destDir}"`, { stdio: "pipe" });
72
+ fs.unlinkSync(tmpFile);
73
+ }
74
+
75
+ async function extractZip(buffer, destDir) {
76
+ const tmpFile = path.join(os.tmpdir(), `goldy-${Date.now()}.zip`);
77
+ fs.writeFileSync(tmpFile, buffer);
78
+ fs.mkdirSync(destDir, { recursive: true });
79
+ execSync(`unzip -o "${tmpFile}" -d "${destDir}"`, { stdio: "pipe" });
80
+ fs.unlinkSync(tmpFile);
81
+ }
82
+
83
+ async function main() {
84
+ const { goos, goarch, isWindows } = getPlatform();
85
+ const version = getVersion();
86
+ const ext = isWindows ? "zip" : "tar.gz";
87
+ const binSuffix = isWindows ? ".exe" : "";
88
+
89
+ const archiveName = `${BIN_NAME}_${goos}_${goarch}.${ext}`;
90
+ const url = `https://github.com/${REPO}/releases/download/v${version}/${archiveName}`;
91
+
92
+ console.log(`Downloading goldy v${version} for ${goos}/${goarch}...`);
93
+
94
+ try {
95
+ const buffer = await downloadFile(url);
96
+ const tmpDir = path.join(os.tmpdir(), `goldy-extract-${Date.now()}`);
97
+
98
+ if (isWindows) {
99
+ await extractZip(buffer, tmpDir);
100
+ } else {
101
+ await extractTarGz(buffer, tmpDir);
102
+ }
103
+
104
+ fs.mkdirSync(BIN_DIR, { recursive: true });
105
+
106
+ const srcBin = path.join(tmpDir, `${BIN_NAME}${binSuffix}`);
107
+ const destBin = path.join(BIN_DIR, `${BIN_NAME}${binSuffix}`);
108
+
109
+ fs.copyFileSync(srcBin, destBin);
110
+ if (!isWindows) {
111
+ fs.chmodSync(destBin, 0o755);
112
+ }
113
+
114
+ fs.rmSync(tmpDir, { recursive: true, force: true });
115
+
116
+ console.log(`Installed goldy to ${destBin}`);
117
+ } catch (err) {
118
+ console.error(`Failed to download goldy: ${err.message}`);
119
+ console.error(`URL: ${url}`);
120
+ console.error("");
121
+ console.error("You can install manually:");
122
+ console.error(" cd ~/.goldy/cmd/goldy-install && go install .");
123
+ process.exit(1);
124
+ }
125
+ }
126
+
127
+ main();
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "goldy-cli",
3
+ "version": "1.2.0",
4
+ "description": "GOLDY toolkit for Claude Code",
5
+ "bin": {
6
+ "goldy": "bin/goldy"
7
+ },
8
+ "preferGlobal": true,
9
+ "scripts": {
10
+ "postinstall": "node install.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/SacredTexts/goldy.git"
15
+ },
16
+ "keywords": [
17
+ "goldy",
18
+ "claude",
19
+ "claude-code",
20
+ "installer",
21
+ "cli"
22
+ ],
23
+ "license": "MIT",
24
+ "os": [
25
+ "darwin",
26
+ "linux",
27
+ "win32"
28
+ ],
29
+ "cpu": [
30
+ "x64",
31
+ "arm64"
32
+ ]
33
+ }