#!/bin/bash set -euo pipefail # Find commands and set up environment if command -v bun >/dev/null 2>&1; then BUN_CMD="bun" else BUN_CMD="$HOME/.bun/bin/bun" fi # Set up Go environment if command -v go >/dev/null 2>&1; then GO_CMD="go" GOROOT=$(go env GOROOT) else GO_CMD="/usr/local/go/bin/go" GOROOT="/usr/local/go" fi export GOROOT export PATH="$GOROOT/bin:$PATH" if command -v golangci-lint >/dev/null 2>&1; then GOLINT_CMD="golangci-lint" else GOLINT_CMD="$HOME/go/bin/golangci-lint" fi # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color echo "Running pre-commit checks..." # Frontend checks echo -e "\n${GREEN}Running frontend checks...${NC}" pushd frontend echo -e "\n${GREEN}Running formatter...${NC}" $BUN_CMD format || { echo -e "${RED}Frontend formatting failed!${NC}" exit 1 } echo -e "\n${GREEN}Running linter...${NC}" $BUN_CMD lint || { echo -e "${RED}Frontend linting failed!${NC}" exit 1 } echo -e "\n${GREEN}Running type checker...${NC}" $BUN_CMD check || { echo -e "${RED}Frontend type checking failed!${NC}" exit 1 } echo -e "\n${GREEN}Building frontend...${NC}" $BUN_CMD run build || { echo -e "${RED}Frontend build failed!${NC}" exit 1 } # Backend checks popd echo -e "\n${GREEN}Running backend tests...${NC}" $GO_CMD test -v ./... || { echo -e "${RED}Backend tests failed!${NC}" exit 1 } echo -e "\n${GREEN}Running Go linter...${NC}" $GOLINT_CMD run || { echo -e "${RED}Go linting failed!${NC}" exit 1 } echo -e "\n${GREEN}All checks passed!${NC}"