-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpre-commit-setup.sh
More file actions
executable file
·42 lines (33 loc) · 987 Bytes
/
pre-commit-setup.sh
File metadata and controls
executable file
·42 lines (33 loc) · 987 Bytes
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
#!/bin/bash
# Destination path for the pre-commit hook
hook_destination=".git/hooks/pre-commit"
# Content of the pre-commit hook script
hook_content=$(cat << 'EOF'
#!/bin/bash
# Run frontend Prettier Check
cd frontend
npm run prettier:check
frontend_status=$?
cd ..
# Run backend Prettier Check
cd backend
npm run prettier:check
backend_status=$?
cd ..
# Exit with a non-zero status if either check fails
if [ $frontend_status -ne 0 -o $backend_status -ne 0 ]; then
echo -e "\nPrettier Check failed. Please fix the formatting issues before committing."
exit 1
fi
EOF
)
# Check if the pre-commit hook already exists
if [ -e "$hook_destination" ]; then
echo "A pre-commit hook already exists. Please remove it before running this script."
exit 1
fi
# Create the pre-commit hook script in the hooks directory
echo "$hook_content" > "$hook_destination"
# Make the pre-commit hook script executable
chmod +x "$hook_destination"
echo "Pre-commit hook installed successfully."