1
0

local-install.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env bash
  2. # Build the current branch and link it as the global `codegraph` for
  3. # hands-on testing. Replaces any existing global install for as long
  4. # as the symlink is in place.
  5. #
  6. # Usage:
  7. # ./scripts/local-install.sh # build + link
  8. # ./scripts/local-install.sh --undo # unlink + restore the published version
  9. set -euo pipefail
  10. cd "$(dirname "$0")/.."
  11. PKG=$(node -p "require('./package.json').name")
  12. VERSION=$(node -p "require('./package.json').version")
  13. BRANCH=$(git rev-parse --abbrev-ref HEAD)
  14. if [ "${1:-}" = "--undo" ]; then
  15. echo "→ unlinking ${PKG}"
  16. npm unlink -g "${PKG}" >/dev/null 2>&1 || true
  17. echo "→ reinstalling published ${PKG}"
  18. npm install -g "${PKG}"
  19. echo "done: global codegraph -> $(command -v codegraph)"
  20. exit 0
  21. fi
  22. echo "→ building ${PKG} ${VERSION} (${BRANCH})"
  23. npm run build
  24. echo "→ linking globally"
  25. npm link
  26. LINKED=$(command -v codegraph || echo "(not on PATH)")
  27. echo
  28. echo "✓ global codegraph now points to this branch"
  29. echo " binary: ${LINKED}"
  30. echo " branch: ${BRANCH}"
  31. echo " version: ${VERSION}"
  32. echo
  33. echo "To restore the published version:"
  34. echo " ./scripts/local-install.sh --undo"