#!/bin/bash
# Exit immediately on error, treat unset variables as errors, propagate pipe failures.
set -euo pipefail
# Load shared log/skip/warn/err helpers from the installer library.
source "$(dirname "${BASH_SOURCE[0]}")/../../lib/logging.sh"

log "Installing LocalTunnel..."
# LocalTunnel exposes a local port to the internet via a public URL.
# Prefer the npm global install because it tracks npm's own Node version and keeps
# the tool alongside other npm globals already managed on the system.
# Fall back to the AUR package if npm is not available (e.g. Node installed via pacman
# without nvm, or npm not yet on PATH in this session).
if command -v npm &>/dev/null; then
    npm install -g localtunnel
else
    # --answerdiff None / --answerclean All suppress interactive PKGBUILD/clean prompts.
    # The AUR package is named nodejs-localtunnel (there is no plain "localtunnel").
    yay -S --answerdiff None --answerclean All --noconfirm --needed nodejs-localtunnel
fi
log "LocalTunnel installed."
