-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
168 lines (101 loc) · 4.15 KB
/
update.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
exec 3<> /dev/null
function red {
printf "\e[91m$1\e[0m\n"
}
function green {
printf "\e[32m$1\e[0m\n"
}
set -e
set -x
ORIGIN="origin"
LOCALBRANCH="master"
REMOTEBRANCH="master"
trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
echo -n "$var"
}
if [ "$1" = "--travis" ]; then
if [ ! -f package_travis.json ]; then red "package_travis.json does not exist - stop"; exit 1; fi
if [ ! -f package.json ]; then red "package.json does not exist - stop"; exit 1; fi
if [ -f package_prod.json ]; then red "package_prod.json does exist - stop"; exit 1; fi
mv package.json package_prod.json
if [ ! -f package_prod.json ]; then red "package_prod.json does not exist - stop"; exit 1; fi
mv package_travis.json package.json
if [ -f package_travis.json ]; then red "package_travis.json does exist - stop"; exit 1; fi
if [ ! -f package.json ]; then red "package.json does not exist - stop 2"; exit 1; fi
green "package.json -> package_prod.json and package_travis.json -> package.json [done]"
exit 0
fi
if [ "$1" = "--prod" ]; then
if [ ! -f package_prod.json ]; then red "package_prod.json does not exist - stop"; exit 1; fi
if [ ! -f package.json ]; then red "package.json does not exist - stop"; exit 1; fi
if [ -f package_travis.json ]; then red "package_travis.json does exist - stop"; exit 1; fi
mv package.json package_travis.json
if [ ! -f package_travis.json ]; then red "package_travis.json does not exist - stop"; exit 1; fi
mv package_prod.json package.json
if [ -f package_prod.json ]; then red "package_prod.json does exist - stop"; exit 1; fi
if [ ! -f package.json ]; then red "package.json does not exist - stop 2"; exit 1; fi
green "package.json -> package_travis.json and package_prod.json -> package.json [done]"
exit 0
fi
if [ -f package_prod.json ]; then
{ red "package_prod.json exist, before update run\n /bin/bash update.sh --prod"; } 2>&3
exit 1;
fi
make t
if [ "$(git rev-parse --abbrev-ref HEAD)" != $LOCALBRANCH ]; then
{ red "switch first branch to <$LOCALBRANCH>"; } 2>&3
exit 1;
fi
{ green "\ncurrent branch: $LOCALBRANCH"; } 2>&3
DIFF="$(git diff --numstat)"
DIFF="$(trim "$DIFF")"
if [ "$DIFF" != "" ]; then
{ red "\n\n Error: First commit changes ...\n\n"; } 2>&3
exit 2;
fi
DIFF="$(git diff --numstat $LOCALBRANCH $ORIGIN/$REMOTEBRANCH)"
DIFF="$(trim "$DIFF")"
if [ "$DIFF" != "" ] || [ "$1" = "force" ]; then
git push $ORIGIN $REMOTEBRANCH --tags
if [ "$?" != "0" ]; then
{ red "\n\nCan't git push - stop bumping version\n"; } 2>&3
exit 3;
fi
npm version patch
# make umd
# cat comment.txt dist/spvalidation.js > dist/test.js
# mv dist/test.js dist/spvalidation.js
# cat comment.txt dist/spvalidation.min.js > dist/test.js
# mv dist/test.js dist/spvalidation.min.js
(cd docs/react && yarn prod)
node update-badge.js
npx markdown-toc -i README.md
git add README.md
git add docs/public/dist/front.bundle.js
git add docs/public/dist/front.bundle.css
# git add dist
# git add examples.es5.js
git commit --amend --no-edit
git push $ORIGIN $REMOTEBRANCH
if [ "$?" = "0" ]; then
npm publish
if [ "$?" != "0" ]; then
{ red "\n\nCan't npm publish\n try to run 'npm login'\n"; } 2>&3
exit 4;
fi
git push --tags --force
make h
#git push origin master --tags
else
{ red "\n\nCan't git push\n"; } 2>&3
exit 5
fi
else
{ red "\n\n Nothing new to publish, \n run 'make uf' if you're sure that there is still something that should be published\n\n"; } 2>&3
fi