템플릿
1
0
template-react-ts/.githooks/pre-commit
Team Workflow Bot 9cc8f6b66a chore: React TypeScript 프로젝트 템플릿 초기 구성
- CLAUDE.md: React/TypeScript/Vite 프로젝트 가이드
- .claude/settings.json: npm/Node.js 빌드 도구 권한 설정
- .claude/rules/: TypeScript/React 코드 스타일, 네이밍, 테스트 규칙
- .githooks/pre-commit: TypeScript 타입체크 + ESLint 검증
- .npmrc: Nexus npm 프록시 레지스트리
- .prettierrc: 코드 포맷팅 설정
- .node-version: Node.js 버전 고정
2026-02-14 08:20:40 +09:00

55 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
#==============================================================================
# pre-commit hook (React TypeScript)
# TypeScript 컴파일 + 린트 검증 — 실패 시 커밋 차단
#==============================================================================
echo "pre-commit: TypeScript 타입 체크 중..."
# npm 확인
if ! command -v npx &>/dev/null; then
echo "경고: npx가 설치되지 않았습니다. 검증을 건너뜁니다."
exit 0
fi
# node_modules 확인
if [ ! -d "node_modules" ]; then
echo "경고: node_modules가 없습니다. 'npm install' 실행 후 다시 시도하세요."
exit 1
fi
# TypeScript 타입 체크
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 ".eslintrc.js" ] || [ -f ".eslintrc.json" ] || [ -f ".eslintrc.cjs" ] || [ -f "eslint.config.js" ] || [ -f "eslint.config.mjs" ]; then
echo "pre-commit: ESLint 검증 중..."
npx eslint src/ --ext .ts,.tsx --quiet 2>&1
LINT_RESULT=$?
if [ $LINT_RESULT -ne 0 ]; then
echo ""
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ ESLint 에러! 커밋이 차단되었습니다. ║"
echo "║ 'npm run lint -- --fix'로 자동 수정을 시도해보세요. ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
exit 1
fi
echo "pre-commit: ESLint 통과"
fi