22 lines · 1.2 KBRaw
| 1 | import type { Route } from "./+types/install"; |
| 2 | |
| 3 | export function installScript(origin: string): string { |
| 4 | return `#!/bin/sh |
| 5 | set -eu |
| 6 | ORIGIN="${origin}" |
| 7 | command -v node >/dev/null 2>&1 || { echo "refs needs Node.js 22 or later: https://nodejs.org" >&2; exit 1; } |
| 8 | if [ "$(node -p 'process.versions.node.split(".")[0]')" -lt 22 ]; then echo "refs needs Node.js 22 or later; you have $(node --version)." >&2; exit 1; fi |
| 9 | mkdir -p "$HOME/.refs/bin" |
| 10 | curl -fsSL "$ORIGIN/cli/refs.mjs" -o "$HOME/.refs/bin/refs.download.mjs" |
| 11 | node --check "$HOME/.refs/bin/refs.download.mjs" || { rm -f "$HOME/.refs/bin/refs.download.mjs"; echo "The refs CLI download is damaged. Run the installer again." >&2; exit 1; } |
| 12 | mv "$HOME/.refs/bin/refs.download.mjs" "$HOME/.refs/bin/refs.mjs" |
| 13 | printf '#!/bin/sh\\nexec node "$HOME/.refs/bin/refs.mjs" "$@"\\n' > "$HOME/.refs/bin/refs" |
| 14 | chmod +x "$HOME/.refs/bin/refs" |
| 15 | "$HOME/.refs/bin/refs" setup "$ORIGIN" |
| 16 | case ":$PATH:" in *":$HOME/.refs/bin:"*) ;; *) echo; echo "Add refs to your PATH: export PATH=\\"\\$HOME/.refs/bin:\\$PATH\\"";; esac |
| 17 | `; |
| 18 | } |
| 19 | |
| 20 | export function loader({ request }: Route.LoaderArgs) { |
| 21 | return new Response(installScript(new URL(request.url).origin), { headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-cache" } }); |
| 22 | } |