@rahul1616/flo42 0.0.0-master-202607081302

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.
Binary file
Binary file
package/cli.js ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ "use strict"
3
+ const { spawnSync, spawn, execSync } = require("child_process")
4
+ const { existsSync, mkdirSync, chmodSync, createWriteStream } = require("fs")
5
+ const { homedir, platform, arch } = require("os")
6
+ const { join } = require("path")
7
+ const https = require("https")
8
+
9
+ const CACHE = join(homedir(), ".flo42", "bun")
10
+ const BUN = join(CACHE, platform() === "win32" ? "bun.exe" : "bun")
11
+
12
+ function getBun() {
13
+ try { spawnSync("bun", ["--version"], { stdio: "ignore" }); return "bun" } catch {}
14
+ if (existsSync(BUN)) return BUN
15
+ return null
16
+ }
17
+
18
+ function download(url, dest) {
19
+ return new Promise((resolve, reject) => {
20
+ const file = createWriteStream(dest)
21
+ https.get(url, (res) => {
22
+ if (res.statusCode >= 300 && res.headers.location)
23
+ return download(res.headers.location, dest).then(resolve, reject)
24
+ if (res.statusCode !== 200) { reject(new Error(`HTTP ${res.statusCode}`)); return }
25
+ res.pipe(file)
26
+ file.on("finish", () => { file.close(); resolve() })
27
+ }).on("error", reject)
28
+ })
29
+ }
30
+
31
+ async function main() {
32
+ let bun = getBun()
33
+ if (!bun) {
34
+ console.error("Downloading Bun runtime (one-time, ~60MB)...")
35
+ mkdirSync(CACHE, { recursive: true })
36
+ const os = { win32: "windows", darwin: "darwin", linux: "linux" }[platform()]
37
+ const zip = join(CACHE, "bun.zip")
38
+ await download(`https://github.com/oven-sh/bun/releases/latest/download/bun-${os}-${arch()}.zip`, zip)
39
+ if (platform() === "win32") {
40
+ execSync(`powershell -Command "Expand-Archive -Path '${zip}' -DestinationPath '${CACHE}' -Force"`, { stdio: "inherit" })
41
+ } else {
42
+ execSync(`unzip -o -q "${zip}" -d "${CACHE}"`, { stdio: "inherit" })
43
+ }
44
+ chmodSync(BUN, 0o755)
45
+ bun = BUN
46
+ }
47
+ const p = spawn(bun, [join(__dirname, "flo42.js"), ...process.argv.slice(2)], { stdio: "inherit", windowsHide: false })
48
+ p.on("exit", (c) => process.exit(c ?? 1))
49
+ }
50
+
51
+ main().catch((e) => { console.error(e.message); process.exit(1) })