-
Notifications
You must be signed in to change notification settings - Fork 4
/
pre-commit.bak
executable file
·93 lines (70 loc) · 1.94 KB
/
pre-commit.bak
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
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
verify_exit() {
EXIT_CODE=$?
if [[ "$EXIT_CODE" != 0 ]]; then
printf "\n\033[41mCOMMIT FAILED\033[0m\n"
exit $EXIT_CODE
fi
}
# Go to the project root directory
cd "$(git rev-parse --show-toplevel)"
# CLIENT
STAGED_FILES=($(git diff --cached --name-only --diff-filter=ACM | grep -E 'client/.*\.(ts|tsx)$' | sed -E 's/client\///'))
if [[ "$STAGED_FILES" != "" ]]; then
# AUTOMATED TESTS
echo -e "Running all /client test suites..."
cd client
npx jest
verify_exit
# CLIENT BUILD
npx next build
verify_exit
# ESLINT
ESLINT="node_modules/.bin/eslint"
if [[ ! -x "$ESLINT" ]]; then
printf "\033[41mPlease install ESlint in /client\033[0m\n"
(exit 1) # set exit code
verify_exit
else
ESLINT="node_modules/.bin/eslint"
echo -e "Linting these files in the client directory:\n"
for file in ${STAGED_FILES[@]}; do
echo $file
done
$ESLINT --fix "${STAGED_FILES[@]}"
verify_exit
# Re-add files since they may have been changed
echo 'Readding /client files'
git add "${STAGED_FILES[@]}"
cd ..
fi
fi
# SERVER
STAGED_FILES=($(git diff --cached --name-only --diff-filter=ACM . | grep -E 'server/.*\.(ts|tsx)$' | sed -E 's/server\///'))
if [[ "$STAGED_FILES" != "" ]]; then
# AUTOMATED TESTS
echo -e "Running all /server test suites..."
cd server
npx jest
verify_exit
# ESLINT
ESLINT="node_modules/.bin/eslint"
if [[ ! -x "$ESLINT" ]]; then
printf "\033[41mPlease install ESlint in /server\033[0m\n"
(exit 1) # set exit code
verify_exit
else
ESLINT="node_modules/.bin/eslint"
echo -e "Linting these files in the server directory:\n"
for file in ${STAGED_FILES[@]}; do
echo $file
done
$ESLINT --fix "${STAGED_FILES[@]}"
verify_exit
# Re-add files since they may have been changed
echo 'Readding /server files'
git add "${STAGED_FILES[@]}"
cd ..
fi
fi
printf "\n\033[42mCOMMIT SUCCEEDED\033[0m\n"