forked from yyx990803/HTML5-Clear-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
60 lines (49 loc) · 1.91 KB
/
build.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
#!/bin/bash
BASEDIR=$(dirname $0)
#copy stuff to deploy folder
echo "\033[36m[update]\033[0m copying assets into deploy folder..."
rm -rf $BASEDIR/deploy
mkdir $BASEDIR/deploy
mkdir $BASEDIR/deploy/js
mkdir $BASEDIR/deploy/css
cp $BASEDIR/css/style.css $BASEDIR/deploy/css/style.css
cp -R $BASEDIR/img $BASEDIR/deploy/img
cp $BASEDIR/index.html $BASEDIR/deploy/index.html
cp $BASEDIR/apple-touch-icon-precomposed.png $BASEDIR/deploy/apple-touch-icon-precomposed.png
cp $BASEDIR/offline.appcache $BASEDIR/deploy/offline.appcache
# rewrite index.html
echo "\033[32m[minify]\033[0m rewriting script tag in" $BASEDIR"/deploy/templates/index.html"
#1. remove all current scripts
sed -i.bak '/<script.*\/script>/d' $BASEDIR/deploy/index.html
#2. replace <!-- MIN --> tag with min.js
sed -i.bak 's/<!-- MIN -->/<script src="js\/min.js"><\/script>/' $BASEDIR/deploy/index.html
#3. add appcache manifest
sed -i.bak 's/<html>/<html manifest="offline.appcache">/' $BASEDIR/deploy/index.html
# rewrite appcache version
sed -i.bak 's/# build: */# build: '$(date +%s)'/' $BASEDIR/deploy/offline.appcache
#minify javascript with uglifyjs
echo "\033[32m[minify]\033[0m source:" $BASEDIR"/js/"
echo "\033[32m[minify]\033[0m output:" $BASEDIR"/deploy/js/min.js"
uglifyjs \
$BASEDIR/js/zepto.js \
$BASEDIR/js/main.js \
$BASEDIR/js/client.js \
$BASEDIR/js/db.js \
$BASEDIR/js/touch.js \
$BASEDIR/js/item.js \
$BASEDIR/js/unfold-dummy.js \
$BASEDIR/js/collection.js \
$BASEDIR/js/list-collection.js \
$BASEDIR/js/list-item.js \
$BASEDIR/js/todo-collection.js \
$BASEDIR/js/todo-item.js \
-v -o $BASEDIR/deploy/js/min.js
#remove stuff no longer needed for deploy
echo "\033[33m[cleanup]\033[0m removing stuff no longer needed..."
#1. remove index.html backup
rm $BASEDIR/deploy/index.html.bak
#2. remove appcache backup
rm $BASEDIR/deploy/offline.appcache.bak
#3. remove .DS_Store (if any)
find $BASEDIR/deploy -name .DS_Store -exec rm {} \;
echo "\033[31m[done]\033[0m"