-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-commit-hook.sh
executable file
·82 lines (70 loc) · 1.66 KB
/
pre-commit-hook.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# Function to show usage
show_usage() {
echo "Usage: $0 [-t target]"
echo "Options:"
echo " -t Target directory/files to check (changed, api, prisma, all)"
echo "Example: $0 -t api"
exit 1
}
# Default target
target="changed"
# Parse command line arguments
while getopts "t:h" opt; do
case $opt in
t) target="$OPTARG" ;;
h) show_usage ;;
?) show_usage ;;
esac
done
# Function to filter TypeScript/TSX files
filter_ts_files() {
echo "$1" | tr ' ' '\n' | grep -E '\.(ts|tsx)$' | tr '\n' ' '
}
# Get files based on target
case $target in
"changed")
files=$(git ls-files --modified --others --exclude-standard)
;;
"api")
files=$(git ls-files app/api/)
;;
"prisma")
files=$(git ls-files prisma/)
;;
"all")
files=$(git ls-files)
;;
*)
echo "Invalid target: $target"
show_usage
;;
esac
# Filter for TypeScript files
ts_files=$(filter_ts_files "$files")
if [ -z "$ts_files" ]; then
echo "No TypeScript files found in target: $target"
exit 0
fi
echo "🔍 Checking files in target: $target"
echo "Files to check: $ts_files"
# Run TypeScript compilation check
# echo "Running type check..."
# if ! npx tsc --noEmit; then
# echo "❌ TypeScript check failed"
# exit 1
# fi
# Run ESLint on filtered files
echo "Running ESLint..."
if ! npx eslint $ts_files; then
echo "❌ ESLint check failed"
exit 1
fi
# Run test files related to the changes
echo "Running tests..."
if ! npm test -- --findRelatedTests $ts_files; then
echo "❌ Tests failed"
exit 1
fi
echo "✅ All checks passed!"
exit 0