Skip to content
refs
22 lines · 1.2 KBRaw
1import type { Route } from "./+types/install";
2
3export function installScript(origin: string): string {
4 return `#!/bin/sh
5set -eu
6ORIGIN="${origin}"
7command -v node >/dev/null 2>&1 || { echo "refs needs Node.js 22 or later: https://nodejs.org" >&2; exit 1; }
8if [ "$(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
9mkdir -p "$HOME/.refs/bin"
10curl -fsSL "$ORIGIN/cli/refs.mjs" -o "$HOME/.refs/bin/refs.download.mjs"
11node --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; }
12mv "$HOME/.refs/bin/refs.download.mjs" "$HOME/.refs/bin/refs.mjs"
13printf '#!/bin/sh\\nexec node "$HOME/.refs/bin/refs.mjs" "$@"\\n' > "$HOME/.refs/bin/refs"
14chmod +x "$HOME/.refs/bin/refs"
15"$HOME/.refs/bin/refs" setup "$ORIGIN"
16case ":$PATH:" in *":$HOME/.refs/bin:"*) ;; *) echo; echo "Add refs to your PATH: export PATH=\\"\\$HOME/.refs/bin:\\$PATH\\"";; esac
17`;
18}
19
20export 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}