-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchange-version.sh
executable file
·113 lines (107 loc) · 2.94 KB
/
change-version.sh
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
# Need debug ? set -e -x
# Test for jq
if ! [[ "$(command -v jq)" ]]; then
echo -e "\e[31mWARNING:\e[39m jq is not installed";
echo -e "\e[34mCOMMAND:\e[39m sudo apt install jq";
exit 1;
fi
# Test for npm
if ! [[ "$(command -v npm)" ]]; then
echo -e "\e[31mWARNING:\e[39m npm is not installed";
echo -e "\e[34mCOMMAND:\e[39m sudo apt install npm";
exit 1;
fi
# Print usage
usage() {
echo ""
echo "Without arguments, this script will be run interactively and will change the"
echo "version patch number."
echo "Options $0"
echo " -h, --help: display this help"
echo " -d, --display: display current versions and exit"
echo " -a, --auto: disable the interactive mode"
echo " -v, --version [patch|minor|major|userinput]: change the semver version"
echo " -pv, --package-version: output only the package.json version"
echo ""
echo "Example: $0 -d"
echo "Example: $0 -a -v major"
echo "Example: $0 -a -v 3.2.1"
echo ""
}
VERSION=$(jq -r .version app/package.json)
summary() {
if [ "$1" != "" ]; then
echo ${1^^}
fi
echo " package.json: $VERSION"
ORIVERSION=$VERSION
}
VERSIONCHANGE=
INTERACTIVE=1
SHOW=0
PACKAGEVERSION=0
while [ "$1" != "" ]; do
case $1 in
-v | --version ) shift
VERSIONCHANGE=${1^^}
;;
-a | --auto ) INTERACTIVE=0
;;
-d | --display ) SHOW=1
;;
-pv | --package-version ) PACKAGEVERSION=1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
change-versions() {
change-version-package
}
change-version-package() {
if [ -z $VERSIONCHANGE ]; then
VERSIONCHANGE='PATCH'
fi
echo "Changing version in app/package.json"
case "$VERSIONCHANGE" in
PATCH)
cd app/; npm version --no-git-tag-version --allow-same-version patch; cd ..
;;
MINOR)
cd app/; npm version --no-git-tag-version --allow-same-version minor; cd ..
;;
MAJOR)
cd app/; npm version --no-git-tag-version --allow-same-version major; cd ..
;;
*)
cd app/; npm version --no-git-tag-version --allow-same-version $VERSIONCHANGE; cd ..
;;
esac
VERSION=$(jq -r .version app/package.json)
echo "Version in package.json is now $VERSION"
}
################################################################################
if [ $SHOW == "1" ]; then
summary "Versions summary"
exit 0
fi
if [ $PACKAGEVERSION == "1" ]; then
echo -n $VERSION
exit 0
fi
summary "Initial versions"
if [ $INTERACTIVE == "1" ]; then
read -r -p "Continue? [Y/n]" response
response=${response,,} # tolower
if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
change-versions
fi
else
change-versions
fi
summary "Final versions"