Files
2026-04-23 18:40:05 -05:00

106 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
usage() {
cat <<'EOF'
Usage:
./scripts/install-pi-package.sh --global
./scripts/install-pi-package.sh --local
Options:
--global Install the repo path into ~/.pi/agent/settings.json
--local Install the repo path into .pi/settings.json for the current project
EOF
}
require_command() {
local command_name=$1
if ! command -v "$command_name" >/dev/null 2>&1; then
echo "Missing required command: $command_name" >&2
exit 1
fi
}
pnpm_cmd=()
resolve_pnpm() {
if command -v pnpm >/dev/null 2>&1; then
pnpm_cmd=(pnpm)
return
fi
if command -v corepack >/dev/null 2>&1; then
pnpm_cmd=(corepack pnpm)
return
fi
echo "Missing required command: pnpm (or corepack)" >&2
exit 1
}
run_pnpm() {
"${pnpm_cmd[@]}" "$@"
}
require_node_20() {
local node_major
node_major=$(node -p "process.versions.node.split('.')[0]")
if (( node_major < 20 )); then
echo "Node.js 20+ is required. Found Node.js $(node -v)." >&2
exit 1
fi
}
install_scope=
if [[ $# -ne 1 ]]; then
usage >&2
exit 1
fi
case "$1" in
--global)
install_scope="global"
;;
--local)
install_scope="local"
;;
-h|--help)
usage
exit 0
;;
*)
usage >&2
exit 1
;;
esac
require_command pi
require_command node
require_node_20
resolve_pnpm
case "$install_scope" in
global)
pi install "$ROOT_DIR"
;;
local)
pi install -l "$ROOT_DIR"
;;
esac
echo "Bootstrapping Atlassian runtime dependencies..."
run_pnpm install --frozen-lockfile --dir "${ROOT_DIR}/pi-package/skills/atlassian/scripts"
echo "Bootstrapping web-automation runtime dependencies..."
run_pnpm install --frozen-lockfile --dir "${ROOT_DIR}/pi-package/skills/web-automation/scripts"
run_pnpm --dir "${ROOT_DIR}/pi-package/skills/web-automation/scripts" exec cloakbrowser install
echo "Rebuilding native web-automation dependencies..."
run_pnpm rebuild --dir "${ROOT_DIR}/pi-package/skills/web-automation/scripts" better-sqlite3 esbuild
echo "Installed Pi packages now visible to this scope:"
pi list
echo "Pi package installed (${install_scope}) and runtime dependencies bootstrapped."