kcg-ai-monitoring/.githooks/pre-commit
htlee a7f3490091 chore: .env.development → .example + pre-commit 모노레포 대응
- .env.development을 git에서 제거, .example로 대체 (서버 정책 준수)
- pre-commit hook을 frontend/ 기준으로 수정 (모노레포 구조)
- custom_pre_commit 플래그 활성화

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 13:52:53 +09:00

63 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
#==============================================================================
# pre-commit hook (모노레포: frontend/ 디렉토리 기준)
# TypeScript 컴파일 + 린트 검증 — 실패 시 커밋 차단
#==============================================================================
# frontend 변경 파일이 있는지 확인
FRONTEND_CHANGED=$(git diff --cached --name-only -- 'frontend/' | head -1)
if [ -z "$FRONTEND_CHANGED" ]; then
echo "pre-commit: frontend 변경 없음, 검증 건너뜀"
exit 0
fi
echo "pre-commit: TypeScript 타입 체크 중..."
# npm 확인
if ! command -v npx &>/dev/null; then
echo "경고: npx가 설치되지 않았습니다. 검증을 건너뜁니다."
exit 0
fi
# node_modules 확인 (모노레포: frontend/ 기준)
if [ ! -d "frontend/node_modules" ]; then
echo "경고: frontend/node_modules가 없습니다. 'cd frontend && npm install' 실행 후 다시 시도하세요."
exit 1
fi
# TypeScript 타입 체크 (frontend/ 디렉토리에서 실행)
(cd frontend && npx tsc --noEmit --pretty 2>&1)
TSC_RESULT=$?
if [ $TSC_RESULT -ne 0 ]; then
echo ""
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ TypeScript 타입 에러! 커밋이 차단되었습니다. ║"
echo "║ 타입 에러를 수정한 후 다시 커밋해주세요. ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
exit 1
fi
echo "pre-commit: 타입 체크 성공"
# ESLint 검증 (설정 파일이 있는 경우만)
if [ -f "frontend/.eslintrc.js" ] || [ -f "frontend/.eslintrc.json" ] || [ -f "frontend/.eslintrc.cjs" ] || [ -f "frontend/eslint.config.js" ] || [ -f "frontend/eslint.config.mjs" ]; then
echo "pre-commit: ESLint 검증 중..."
(cd frontend && npx eslint src/ --ext .ts,.tsx --quiet 2>&1)
LINT_RESULT=$?
if [ $LINT_RESULT -ne 0 ]; then
echo ""
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ ESLint 에러! 커밋이 차단되었습니다. ║"
echo "║ 'cd frontend && npm run lint -- --fix'로 수정하세요. ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
exit 1
fi
echo "pre-commit: ESLint 통과"
fi