forked from aclist/kbin-kes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
executable file
·63 lines (60 loc) · 1.74 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
#!/usr/bin/env bash
COLUMNS=1
version_file="VERSION"
master_file="kes.user.js"
vers=$(< $version_file)
opts=(
"MAJOR (breaking API change)"
"MINOR (feature)"
"PATCH (hotfix)"
"chore (static docs/task/file manipulation)"
)
bump_vers(){
local ma=$(<<< "$vers" sed 's/\([0-9]\+\)\(.\)\([0-9]\+\)\(.\)\([0-9]\+\)/\1/g')
local mi=$(<<< "$vers" sed 's/\([0-9]\+\)\(.\)\([0-9]\+\)\(.\)\([0-9]\+\)/\3/g')
local pa=$(<<< "$vers" sed 's/\([0-9]\+\)\(.\)\([0-9]\+\)\(.\)\([0-9]\+\)/\5/g')
case $1 in
"major")
ma=$((ma+1))
mi=0
pa=0
;;
"minor")
mi=$((mi+1))
pa=0
;;
"patch")
pa=$((pa+1))
;;
esac
local newvers="${ma}.${mi}.${pa}"
echo "$newvers" > $version_file
sed -i "s/\(\/\/ @version *\)\([0-9]\+.*\)/\1$newvers/g" $master_file
echo "HOOK========>Bumping version from $vers to $newvers"
git add $version_file
git add $master_file
}
test_mod(){
local added=$(git diff --cached --name-status | awk '/^A/ {print $2}')
local ct=$(<<< "$added" wc -l)
[[ $ct -gt 1 ]] || [[ $ct -eq 0 ]] && return
if [[ $added =~ user.js ]]; then
local newmod=$(<<< "$added" awk -F. '{print $1}')
local branch=$(git name-rev --name-only HEAD)
local url="// @require https://github.com/aclist/kbin-kes/raw/$branch/mods/$mod"
local func=$(<<< "$mod" awk -F. '{print $1}')
awk -v mod="$url" '!f && /resource/ {print mod;f=1}1' $master_file | sponge $master_file
awk -v entry="$func" 'f{print " " entry ": " entry ",";f=0} /const funcObj/{f=1}1' $master_file | sponge $master_file
fi
}
#test_mod
echo "This commit change is of type:"
select opt in "${opts[@]}"; do
case $opt in
${opts[0]}) bump_vers major ;;
${opts[1]}) bump_vers minor ;;
${opts[2]}) bump_vers patch ;;
${opts[3]}) : ;;
esac
break
done < /dev/tty