-
Notifications
You must be signed in to change notification settings - Fork 3
/
pre-commit
executable file
·79 lines (57 loc) · 1.29 KB
/
pre-commit
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
#!/usr/bin/env bash
# .git/hooks/pre-commit
: << !
#!/usr/bin/env bash
if [ -f "pre-commit" ];then . "pre-commit";fi
!
# eslint exists
eslint="./node_modules/.bin/eslint"
if [[ ! -f $eslint ]]; then
eslint="eslint"
if [[ ! -n $(command -v $eslint) ]]; then
echo -e "\033[31m !eslint \033[0m"
# exit 0
fi
npm i -D -f eslint
eslint="npx eslint"
fi
# files
files=$(git diff --cached --name-only | egrep "(.js|.jsx|.ts|.tsx|.vue)$")
# -deleted
for file in $files; do
if [[ ! -f $file ]]; then
files=$(echo "$files" | egrep -v "^$file$")
fi
done
# has not files to eslint
files=$(echo "$files" | egrep -v "^$")
if [[ -z $files ]]; then
# echo "has not files to eslint"
exit 0
fi
# lint fix
# add again
rs=$($eslint $files --cache=false --cache-file=node_modules/.eslintcache --fix=true --quiet=true -f=codeframe --color=true)
error=$?
git add $files
# echo "$eslint"
# echo "$files"
# echo "$rs"
# # error warning with color
# rs=${rs//error/"\033[31merror\033[0m"}
# rs=${rs//warning/"\033[33mwarning\033[0m"}
# rs=$(echo "$rs" | egrep "error")
# error?
if [[ $error != 0 ]]; then
echo "
请修复问题代码之后再提交
"
echo "$rs"
echo -e "
\033[31m\033[1m
请修复问题代码之后再提交
\033[0m"
exit 1
fi
npm run gulp
git add ./dist/console.js