solforge 0.2.1 → 0.2.3

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/cli.cjs ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+ // SolForge CLI bootstrapper
3
+ // - Prefers a prebuilt vendor binary (downloaded via postinstall or on first run)
4
+ // - Falls back to Bun-based TS entry if available
5
+
6
+ const fs = require("node:fs");
7
+ const path = require("node:path");
8
+ const https = require("node:https");
9
+ const { spawn } = require("node:child_process");
10
+
11
+ function pkg() {
12
+ // Resolve package.json next to this file regardless of install location
13
+ const p = path.join(__dirname, "package.json");
14
+ try { return require(p); } catch { return { version: "" }; }
15
+ }
16
+
17
+ function assetName() {
18
+ const p = process.platform;
19
+ const a = process.arch;
20
+ if (p === "darwin" && a === "arm64") return "solforge-darwin-arm64";
21
+ if (p === "darwin" && a === "x64") return "solforge-darwin-x64";
22
+ if (p === "linux" && a === "x64") return "solforge-linux-x64";
23
+ if (p === "linux" && a === "arm64") return "solforge-linux-arm64";
24
+ if (p === "win32" && a === "x64") return "solforge-windows-x64.exe";
25
+ return null;
26
+ }
27
+
28
+ function vendorPath() {
29
+ const name = assetName();
30
+ if (!name) return null;
31
+ return path.join(__dirname, "vendor", name);
32
+ }
33
+
34
+ function download(url, outPath) {
35
+ return new Promise((resolve, reject) => {
36
+ const req = https.get(url, (res) => {
37
+ if ([301, 302, 307, 308].includes(res.statusCode) && res.headers.location) {
38
+ return resolve(download(res.headers.location, outPath));
39
+ }
40
+ if (res.statusCode !== 200) {
41
+ return reject(new Error(`HTTP ${res.statusCode}`));
42
+ }
43
+ const file = fs.createWriteStream(outPath, { mode: process.platform === "win32" ? undefined : 0o755 });
44
+ res.pipe(file);
45
+ file.on("finish", () => file.close(() => resolve()));
46
+ file.on("error", reject);
47
+ });
48
+ req.on("error", reject);
49
+ });
50
+ }
51
+
52
+ async function ensureBinary() {
53
+ const vp = vendorPath();
54
+ if (!vp) return null;
55
+ if (fs.existsSync(vp)) return vp;
56
+
57
+ // Respect opt-out
58
+ if (String(process.env.SOLFORGE_SKIP_DOWNLOAD || "").toLowerCase() === "true") {
59
+ return null;
60
+ }
61
+
62
+ const { version, repository } = pkg();
63
+ const repo = process.env.SOLFORGE_REPO || (repository && (typeof repository === "string" ? repository.replace(/^github:/, "") : (repository.url && (repository.url.match(/github\.com[:/](.+?)\.git$/) || [])[1]))) || "nitishxyz/solforge";
64
+ if (!version) return null;
65
+ const asset = path.basename(vp);
66
+ const url = `https://github.com/${repo}/releases/download/v${version}/${asset}`;
67
+
68
+ try {
69
+ fs.mkdirSync(path.dirname(vp), { recursive: true });
70
+ await download(url, vp);
71
+ if (process.platform !== "win32") {
72
+ try { fs.chmodSync(vp, 0o755); } catch {}
73
+ }
74
+ return fs.existsSync(vp) ? vp : null;
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+
80
+ function run(cmd, args) {
81
+ return new Promise((resolve) => {
82
+ const child = spawn(cmd, args, { stdio: "inherit" });
83
+ child.on("exit", (code) => resolve(typeof code === "number" ? code : 0));
84
+ });
85
+ }
86
+
87
+ (async () => {
88
+ const vp = await ensureBinary();
89
+ if (vp) {
90
+ const code = await run(vp, process.argv.slice(2));
91
+ process.exit(code);
92
+ }
93
+ // Fallback: try to run TS entry via Bun
94
+ const bun = process.env.SOLFORGE_BUN || "bun";
95
+ const entry = path.join(__dirname, "src", "cli", "main.ts");
96
+ const code = await run(bun, [entry, ...process.argv.slice(2)]);
97
+ if (code !== 0) {
98
+ console.error("solforge: failed to run binary and Bun fallback. Install Bun or ensure a release asset exists.");
99
+ }
100
+ process.exit(code);
101
+ })();
102
+
package/package.json CHANGED
@@ -1,14 +1,23 @@
1
1
  {
2
2
  "name": "solforge",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "private": false,
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/nitishxyz/solforge.git"
10
+ },
11
+ "homepage": "https://github.com/nitishxyz/solforge#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/nitishxyz/solforge/issues"
14
+ },
7
15
  "bin": {
8
- "solforge": "dist/solforge"
16
+ "solforge": "cli.cjs"
9
17
  },
10
18
  "files": [
11
- "dist",
19
+ "cli.cjs",
20
+ "scripts",
12
21
  "src",
13
22
  "server",
14
23
  "docs",
@@ -16,21 +25,24 @@
16
25
  "LICENSE"
17
26
  ],
18
27
  "scripts": {
19
- "lint": "biome check",
20
- "cli": "bun src/cli/main.ts",
21
- "build:gui": "bun build src/gui/src/main.tsx --outdir src/gui/public/build --target=browser --minify",
22
- "build:css": "bunx tailwindcss -i src/gui/src/index.css -o src/gui/public/app.css --minify",
23
28
  "build": "bun run build:bin",
24
29
  "build:bin": "bun run build:css && bun run build:gui && bun build --compile src/cli/main.ts --outfile dist/solforge",
30
+ "build:bin:all": "bun run build:bin:darwin-arm64 && bun run build:bin:darwin-x64 && bun run build:bin:linux-x64 && bun run build:bin:linux-arm64 && bun run build:bin:windows-x64",
25
31
  "build:bin:darwin-arm64": "bun run build:css && bun run build:gui && bun build --compile --target=bun-darwin-arm64 src/cli/main.ts --outfile dist/solforge-darwin-arm64",
26
32
  "build:bin:darwin-x64": "bun run build:css && bun run build:gui && bun build --compile --target=bun-darwin-x64 src/cli/main.ts --outfile dist/solforge-darwin-x64",
27
- "build:bin:linux-x64": "bun run build:css && bun run build:gui && bun build --compile --target=bun-linux-x64 src/cli/main.ts --outfile dist/solforge-linux-x64",
28
33
  "build:bin:linux-arm64": "bun run build:css && bun run build:gui && bun build --compile --target=bun-linux-arm64 src/cli/main.ts --outfile dist/solforge-linux-arm64",
34
+ "build:bin:linux-x64": "bun run build:css && bun run build:gui && bun build --compile --target=bun-linux-x64 src/cli/main.ts --outfile dist/solforge-linux-x64",
29
35
  "build:bin:windows-x64": "bun run build:css && bun run build:gui && bun build --compile --target=bun-windows-x64 src/cli/main.ts --outfile dist/solforge-windows-x64.exe",
30
- "build:bin:all": "bun run build:bin:darwin-arm64 && bun run build:bin:darwin-x64 && bun run build:bin:linux-x64 && bun run build:bin:linux-arm64 && bun run build:bin:windows-x64"
36
+ "build:css": "bunx tailwindcss -i src/gui/src/index.css -o src/gui/public/app.css --minify",
37
+ "build:gui": "bun build src/gui/src/main.tsx --outdir src/gui/public/build --target=browser --minify",
38
+ "cli": "bun src/cli/main.ts",
39
+ "lint": "biome check",
40
+ "postinstall": "node scripts/postinstall.cjs || true",
41
+ "prepack": "chmod +x cli.cjs || true"
31
42
  },
32
43
  "devDependencies": {
33
44
  "@biomejs/biome": "2.2.4",
45
+ "@types/aws-lambda": "8.10.152",
34
46
  "@types/bun": "latest",
35
47
  "@types/react": "^19.1.13",
36
48
  "@types/react-dom": "^19.1.9",
@@ -53,6 +65,7 @@
53
65
  "drizzle-orm": "^0.44.5",
54
66
  "litesvm": "^0.3.3",
55
67
  "react": "^19.1.1",
56
- "react-dom": "^19.1.1"
68
+ "react-dom": "^19.1.1",
69
+ "sst": "3.17.13"
57
70
  }
58
71
  }
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ SolForge postinstall: fetch the platform-specific prebuilt binary from GitHub Releases.
4
+ - Skips if SOLFORGE_SKIP_DOWNLOAD=true
5
+ - Falls back silently on errors (CLI will still work via Bun if installed)
6
+ */
7
+ const fs = require("fs");
8
+ const path = require("path");
9
+ const https = require("https");
10
+
11
+ function log(msg) {
12
+ console.log(`[solforge] ${msg}`);
13
+ }
14
+ function warn(msg) {
15
+ console.warn(`[solforge] ${msg}`);
16
+ }
17
+
18
+ if (String(process.env.SOLFORGE_SKIP_DOWNLOAD || "").toLowerCase() === "true") {
19
+ log("Skipping binary download due to SOLFORGE_SKIP_DOWNLOAD=true");
20
+ process.exit(0);
21
+ }
22
+
23
+ function assetName() {
24
+ const p = process.platform;
25
+ const a = process.arch;
26
+ if (p === "darwin" && a === "arm64") return "solforge-darwin-arm64";
27
+ if (p === "darwin" && a === "x64") return "solforge-darwin-x64";
28
+ if (p === "linux" && a === "x64") return "solforge-linux-x64";
29
+ if (p === "linux" && a === "arm64") return "solforge-linux-arm64";
30
+ if (p === "win32" && a === "x64") return "solforge-windows-x64.exe";
31
+ return null;
32
+ }
33
+
34
+ function getRepo() {
35
+ try {
36
+ const pkg = require(path.join(__dirname, "..", "package.json"));
37
+ if (pkg.repository) {
38
+ if (typeof pkg.repository === "string") return pkg.repository.replace(/^github:/, "");
39
+ if (pkg.repository.url) {
40
+ const m = pkg.repository.url.match(/github\.com[:/](.+?)\.git$/);
41
+ if (m) return m[1];
42
+ }
43
+ }
44
+ } catch {}
45
+ return process.env.SOLFORGE_REPO || "nitishxyz/solforge";
46
+ }
47
+
48
+ function getVersion() {
49
+ try {
50
+ const pkg = require(path.join(__dirname, "..", "package.json"));
51
+ return pkg.version;
52
+ } catch {
53
+ return process.env.npm_package_version || "";
54
+ }
55
+ }
56
+
57
+ const name = assetName();
58
+ if (!name) {
59
+ warn(`No prebuilt binary for ${process.platform}/${process.arch}; skipping`);
60
+ process.exit(0);
61
+ }
62
+
63
+ const version = getVersion();
64
+ if (!version) {
65
+ warn("Unable to determine package version; skipping binary download");
66
+ process.exit(0);
67
+ }
68
+
69
+ const repo = getRepo();
70
+ const url = `https://github.com/${repo}/releases/download/v${version}/${name}`;
71
+
72
+ const vendorDir = path.join(__dirname, "..", "vendor");
73
+ const outPath = path.join(vendorDir, name);
74
+
75
+ if (fs.existsSync(outPath)) {
76
+ log(`Binary already present at vendor/${name}`);
77
+ process.exit(0);
78
+ }
79
+
80
+ fs.mkdirSync(vendorDir, { recursive: true });
81
+
82
+ function download(to, from, cb, redirects = 0) {
83
+ const req = https.get(from, (res) => {
84
+ if ([301, 302, 307, 308].includes(res.statusCode) && res.headers.location && redirects < 5) {
85
+ return download(to, res.headers.location, cb, redirects + 1);
86
+ }
87
+ if (res.statusCode !== 200) {
88
+ return cb(new Error(`HTTP ${res.statusCode} for ${from}`));
89
+ }
90
+ const file = fs.createWriteStream(to, { mode: 0o755 });
91
+ res.pipe(file);
92
+ file.on("finish", () => file.close(cb));
93
+ });
94
+ req.on("error", (err) => cb(err));
95
+ }
96
+
97
+ log(`Fetching ${name} for v${version}...`);
98
+ download(outPath, url, (err) => {
99
+ if (err) {
100
+ warn(`Could not download prebuilt binary: ${err.message}`);
101
+ warn("CLI will fall back to running via Bun if available.");
102
+ try { fs.unlinkSync(outPath); } catch {}
103
+ process.exit(0);
104
+ }
105
+ if (process.platform !== "win32") {
106
+ try { fs.chmodSync(outPath, 0o755); } catch {}
107
+ }
108
+ log(`Installed vendor/${name}`);
109
+ });
110
+