setup-hooks.sh 890 B

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. # Function to install a git hook
  3. install_hook() {
  4. local hook_name=$1
  5. # Source and destination paths
  6. local source_hook="tools/git-hooks/${hook_name}"
  7. local dest_hook=".git/hooks/${hook_name}"
  8. # Copy the hook and make it executable
  9. if [[ -e "${source_hook}" ]]; then
  10. cp "${source_hook}" "${dest_hook}" && chmod +x "${dest_hook}"
  11. echo "${hook_name} hook installed successfully."
  12. else
  13. echo "Error: The hook '${source_hook}' does not exist."
  14. exit 1
  15. fi
  16. }
  17. # Select the hook to install based on argument or use default (pre-commit)
  18. hook_to_install=${1:-pre-commit}
  19. # Install the selected hook
  20. install_hook "${hook_to_install}"
  21. # Install ESLint and related dependencies globally if pre-commit is the selected hook
  22. if ! npm list -g eslint --depth=0 >/dev/null 2>&1; then
  23. npm install eslint -g
  24. echo "ESLint and related dependencies installed."
  25. fi