import type { Route } from "./+types/install"; export function installScript(origin: string): string { return `#!/bin/sh set -eu ORIGIN="${origin}" command -v node >/dev/null 2>&1 || { echo "refs needs Node.js 22 or later: https://nodejs.org" >&2; exit 1; } 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 mkdir -p "$HOME/.refs/bin" curl -fsSL "$ORIGIN/cli/refs.mjs" -o "$HOME/.refs/bin/refs.download.mjs" 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; } mv "$HOME/.refs/bin/refs.download.mjs" "$HOME/.refs/bin/refs.mjs" printf '#!/bin/sh\\nexec node "$HOME/.refs/bin/refs.mjs" "$@"\\n' > "$HOME/.refs/bin/refs" chmod +x "$HOME/.refs/bin/refs" "$HOME/.refs/bin/refs" setup "$ORIGIN" case ":$PATH:" in *":$HOME/.refs/bin:"*) ;; *) echo; echo "Add refs to your PATH: export PATH=\\"\\$HOME/.refs/bin:\\$PATH\\"";; esac `; } export function loader({ request }: Route.LoaderArgs) { return new Response(installScript(new URL(request.url).origin), { headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-cache" } }); }