-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev-tools.sh
executable file
·293 lines (256 loc) · 6.57 KB
/
dev-tools.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/bin/bash
# This script will build a production release of dandelion
buildDandelion()
{
# Directory Variables
TMP_DIR="/tmp"
GIT_DIR="dandelion"
FULL_DIR="$TMP_DIR/$GIT_DIR"
DELIVERY_DIR="$2"
# Git Variables
GIT_REPO="https://github.com/onesimus-systems/dandelion"
GIT_BRANCH=$1
GIT_BRANCH_FILENAME=${GIT_BRANCH#tags/}
echo "Cleaning up"
cd $TMP_DIR
rm -rf $GIT_DIR
echo "Cloning git repo"
git clone $GIT_REPO $FULL_DIR
cd $FULL_DIR
echo "Checking out $GIT_BRANCH"
git checkout $GIT_BRANCH
if [ $? -ne 0 ]; then
echo "Error checking out branch $GIT_BRANCH"
exit 1
fi
echo "Installing Composer"
composer install --no-dev
if [ $? -ne 0 ]; then
exit 1
fi
echo "Optimizing Autoloader"
composer dump-autoload --optimize --no-dev
if [ $? -ne 0 ]; then
exit 1
fi
echo "Installing Node Modules"
npm install
if [ $? -ne 0 ]; then
exit 1
fi
echo "Running Gulp"
$TMP_DIR/dandelion/node_modules/.bin/gulp
if [ $? -ne 0 ]; then
exit 1
fi
echo "Removing dev directories"
DEV_ITEMS=(
'.git'
'node_modules'
'vagrant'
'public/source'
'public/build/js/maps'
'public/assets/themes/modern/less'
'public/assets/themes/modern/maps'
'public/assets/themes/legacy/less'
'public/assets/themes/legacy/maps'
'composer.*'
'package.json'
'gulpfile.js'
'dev-tools.sh'
'Vagrantfile'
'server.php'
)
for DIR in "${DEV_ITEMS[@]}"; do
echo "Deleting $FULL_DIR/$DIR"
rm -rf $FULL_DIR/$DIR
done
echo "Creating tarball"
cd $TMP_DIR
tar czf $DELIVERY_DIR/dandelion-$GIT_BRANCH_FILENAME.tar.gz $GIT_DIR/
echo "Cleaning up"
cd $TMP_DIR
rm -rf $GIT_DIR
echo "Finished"
}
buildCommand ()
{
BRANCH="master"
MV_PATH="$HOME/Desktop"
case $2 in
help)
echo "Usage: build -b -t -v -p"
echo "-b Branch to checkout"
echo "-t Tag to checkout"
echo "-v Version to checkout"
echo " Defaults to master branch"
echo "-p Path to save gzipped tarball"
echo " Defaults to desktop"
exit 0
esac
args=`getopt v:t:b:p: $*`
if test $? -ne 0; then
echo 'Usage: build -t tag'
exit 1
fi
set -- $args
for i; do
case "$i" in
-b)
shift
BRANCH="$1"
shift
;;
-t)
shift
BRANCH="tags/$1"
shift
;;
-v)
shift
BRANCH="tags/v$1"
shift
;;
-p)
shift
MV_PATH="$1"
shift
esac
done
buildDandelion $BRANCH $MV_PATH
}
bumpverCommand ()
{
# Setup options
COMMIT=false
DRY_RUN=false
# Setup version variables
NEW_VERSION=""
CURRENT_VERSION=""
MAJOR=""
MINOR=""
PATCH=""
BUMP=$2
# Setup regexes
VER_REGEX="^[[:blank:]]*const VERSION = '\([[:digit:]]\.[[:digit:]]\.[[:digit:]]\)"
VER_SED_REGEX="\(VERSION[[:blank:]]=[[:blank:]]'\)[[:digit:]]\.[[:digit:]]\.[[:digit:]]"
VER_JSON_SED_REGEX="\(\"version\": \"\)[[:digit:]]\.[[:digit:]]\.[[:digit:]]"
# Setup file pathnams
APPFILE="./app/Dandelion/Application.php"
COMPOSERFILE="./composer.json"
NPMFILE="./package.json"
# Parse arguments
args=`getopt cd $*`
if test $? -ne 0; then
echo 'Usage: bumpver [major|minor|patch] -c -d'
exit 1
fi
set -- $args
for i; do
case "$i" in
-c)
shift
COMMIT=true
shift
;;
-d)
shift
DRY_RUN=true
shift
esac
done
# Get current version from application file
CURRENT_VERSION=$(grep "$VER_REGEX" $APPFILE)
CURRENT_VERSION=$(expr "$CURRENT_VERSION" : "$VER_REGEX")
# Explode to array
IFS='.' read -a CURRENT <<< "$CURRENT_VERSION"
MAJOR=${CURRENT[0]}
MINOR=${CURRENT[1]}
PATCH=${CURRENT[2]}
# Bump version as requested
case $BUMP in
major)
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR+1))
PATCH=0
;;
patch)
PATCH=$((PATCH+1))
;;
help)
echo "Usage: bumpver [major|minor|patch] -c -d"
echo "-c Commit and tag in git"
echo "-d Dry run, displays changed files, will not commit"
exit 0
;;
*)
echo "Which version number should be bumped?"
exit 1
esac
# Compose new version number
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "Old Version: $CURRENT_VERSION"
echo "New Version: $NEW_VERSION"
echo ''
# Edit main application file
if [ "$DRY_RUN" = true ]; then
sed "s/$VER_SED_REGEX/\1$NEW_VERSION/" $APPFILE
else
cat $APPFILE > $APPFILE.bak
sed "s/$VER_SED_REGEX/\1$NEW_VERSION/" $APPFILE.bak > $APPFILE
rm $APPFILE.bak
fi
# Edit composer file
if [ "$DRY_RUN" = true ]; then
sed "s/$VER_JSON_SED_REGEX/\1$NEW_VERSION/" $COMPOSERFILE
else
cat $COMPOSERFILE > $COMPOSERFILE.bak
sed "s/$VER_JSON_SED_REGEX/\1$NEW_VERSION/" $COMPOSERFILE.bak > $COMPOSERFILE
rm $COMPOSERFILE.bak
fi
# Edit package.json
if [ "$DRY_RUN" = true ]; then
sed "s/$VER_JSON_SED_REGEX/\1$NEW_VERSION/" $NPMFILE
else
cat $NPMFILE > $NPMFILE.bak
sed "s/$VER_JSON_SED_REGEX/\1$NEW_VERSION/" $NPMFILE.bak > $NPMFILE
rm $NPMFILE.bak
fi
# Commit changes and tag commit
if [ "$COMMIT" = true -a "$DRY_RUN" = false ]; then
echo "Commiting"
git commit -am "Bumped $BUMP version"
git tag v$NEW_VERSION
fi
}
printHelp ()
{
echo "Dev tools script for Dandelion"
echo "Copyright 2015 - Onesimus Systems"
echo "MIT"
echo ''
echo "Available commands:"
echo " build: Generate a release tarball"
echo " bumpver: Bump the version"
echo ''
echo "Type: '[command] help' to get help for a specific command"
}
### Main Script ###
case $1 in
build)
buildCommand $@
;;
bumpver)
bumpverCommand $@
;;
help)
printHelp
;;
*)
echo "Invalid command"
exit 1
esac