forked from Tomekmularczyk/react-id-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·113 lines (88 loc) · 2.12 KB
/
release.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
#!/bin/sh
### CONSTANTS
GREEN='\033[0;32m'
RED='\033[91m'
NC='\033[0m' # No Color
### FUNCTIONS
replaceVersionInPackageJSON() {
local NEW_VERSION=$1
local NEW_VERSION_LINE=" \"version\": \"$NEW_VERSION\","
sed -i '' "s/.*\"version\":.*/$NEW_VERSION_LINE/" package.json || exit 1;
}
printCurrentVersion() {
local VERSION=$(sed '3q;d' package.json | xargs) # expected on 3rd line
echo "Current${GREEN} $VERSION ${NC}"
}
readNewVersion() {
local NEW_VERSION
read -p "Type new version: " NEW_VERSION
echo $NEW_VERSION
}
loginToNPM() {
echo "Loging to npm..."
npm login || exit 1;
}
runTests() {
echo 'Running tests...\n'
yarn lint || exit 1;
yarn typecheck || exit 1;
yarn test --silent --noStackTrace --colors >/dev/null || exit 1;
echo '\n'
}
buildPackage() {
echo 'Building library...\n'
rm -rf lib
yarn build || exit 1;
yarn build:declarations || exit 1;
}
bailoutIfRepoIsNotClean() {
git diff-index --quiet HEAD -- \
|| { echo "${RED}You have uncommitted changes, clean up the repo first.${NC}"; exit 1; }
}
confirmNewVersion() {
local NEW_VERSION=$1
local CONFIRMED
echo "Are you sure you want to create version${GREEN} $NEW_VERSION ${NC}?"
read -p "(y/n): " CONFIRMED
if [ $CONFIRMED != "y" ] && [ $CONFIRMED != "Y" ]
then
exit 1;
fi
}
confirmMasterBranch() {
local CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ $CURRENT_BRANCH != "master" ]
then
echo "${RED}First switch to master branch.${NC}"
exit 1;
fi
}
commitAndCreateTag() {
local NEW_VERSION=$1
git add --all
git commit -m "Releasing version $NEW_VERSION"
git tag "v$NEW_VERSION"
}
pushToRemote() {
local CONFIRMED
echo "Do you want to push new commit and tag to remote repo?"
read -p "(y/n): " CONFIRMED
if [ $CONFIRMED = "y" ] || [ $CONFIRMED = "Y" ]
then
git push origin master
git push origin --tags
fi
}
confirmMasterBranch
bailoutIfRepoIsNotClean
clear
runTests
printCurrentVersion
NEW_VERSION=$(readNewVersion)
loginToNPM
confirmNewVersion $NEW_VERSION
buildPackage
replaceVersionInPackageJSON $NEW_VERSION
commitAndCreateTag $NEW_VERSION
npm publish
pushToRemote