forked from aclist/kbin-kes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·83 lines (82 loc) · 2.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
80
81
82
83
#!/usr/bin/env bash
npm_flag="--no-git-tag-version"
COLUMNS=1
version_file="VERSION"
master_file="kes.user.js"
funcs_file="helpers/funcs.js"
manifest="helpers/manifest.json"
vers=$(< $version_file)
branch=$(git name-rev --name-only HEAD)
opts=(
"MAJOR (breaking API change)"
"MINOR (feature)"
"PATCH (hotfix)"
"chore (static docs/task/file manipulation)"
)
bump_npm(){
case "$1" in
"prerelease")
npm version "$1" --preid=rc "$npm_flag"
;;
"beta")
npm version "$1" --preid=beta "$npm_flag"
;;
*)
npm version "$1" "$npm_flag"
;;
esac
}
bump_vers(){
[[ $1 == chore ]] && return
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')
if [[ $branch == "main" ]]; then
bump_npm "$1"
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}"
elif [[ $branch =~ ^release/ ]]; then
local inc=$(<<< "$vers" awk -F"." '{print $4}')
local pref=$(<<< "$vers" awk -F"-" '{print $1}')
newvers="${pref}-rc.$((inc+1))"
bump_npm prerelease
else
local inc=$(<<< "$vers" awk -F"." '{print $4}')
local pref=$(<<< "$vers" awk -F"-" '{print $1}')
newvers="${pref}-beta.$((inc+1))"
fi
echo "$newvers" > $version_file
./build/scripts/gen_manifest.sh
./build/scripts/gen_kes.sh
./build/scripts/concat_funcs build
echo
echo "HOOK========>Bumping version from $vers to $newvers"
echo
git add $manifest
git add $version_file
git add $master_file
git add "$funcs_file"
}
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