| @@ -1,5 +1,5 @@ |
| 1 | 1 | import { intro, outro, spinner, log } from "@clack/prompts"; |
| 2 | | import { mkdirSync, writeFileSync, readFileSync, existsSync, chmodSync } from "node:fs"; |
| 2 | import { mkdirSync, writeFileSync, readFileSync, existsSync, chmodSync, symlinkSync, unlinkSync } from "node:fs"; |
| 3 | 3 | import { join } from "node:path"; |
| 4 | 4 | import { homedir, platform, arch } from "node:os"; |
| 5 | 5 | import { execSync } from "node:child_process"; |
| @@ -110,16 +110,26 @@ |
| 110 | 110 | s.start("Installing Sapling (sl)"); |
| 111 | 111 | try { |
| 112 | 112 | const archName = arch() === "x64" ? "x86_64" : arch(); |
| 113 | | const binary = `sl-${os}-${archName}`; |
| 114 | | const res = await fetch(`${hub}/downloads/${binary}`); |
| 113 | const tarball = `sl-${os}-${archName}.tar.gz`; |
| 114 | const res = await fetch(`${hub}/downloads/${tarball}`); |
| 115 | 115 | if (!res.ok) { |
| 116 | 116 | s.stop("Sapling binary not available yet (non-fatal)"); |
| 117 | 117 | return; |
| 118 | 118 | } |
| 119 | 119 | const buf = Buffer.from(await res.arrayBuffer()); |
| 120 | | const dest = "/usr/local/bin/sl"; |
| 121 | | writeFileSync(dest, buf); |
| 122 | | chmodSync(dest, 0o755); |
| 120 | const installDir = "/usr/local/lib/sapling"; |
| 121 | const symlink = "/usr/local/bin/sl"; |
| 122 | |
| 123 | // Write tarball to temp file and extract |
| 124 | const tmpTar = "/tmp/sl-install.tar.gz"; |
| 125 | writeFileSync(tmpTar, buf); |
| 126 | execSync(`rm -rf ${installDir} && mkdir -p ${installDir} && tar xzf ${tmpTar} -C ${installDir}`, { stdio: "pipe" }); |
| 127 | execSync(`rm -f ${tmpTar}`, { stdio: "pipe" }); |
| 128 | |
| 129 | // Create symlink at /usr/local/bin/sl -> wrapper script |
| 130 | try { unlinkSync(symlink); } catch {} |
| 131 | symlinkSync(join(installDir, "sl"), symlink); |
| 132 | |
| 123 | 133 | s.stop("Sapling (sl) installed"); |
| 124 | 134 | } catch { |
| 125 | 135 | s.stop("Could not install Sapling (non-fatal)"); |
| 126 | 136 | |