-
Notifications
You must be signed in to change notification settings - Fork 30
/
preprocess
executable file
·60 lines (53 loc) · 1.83 KB
/
preprocess
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
if [ $# -eq 0 ]; then # show help
echo "Used to preprocss some file: like compile scss, cleanup html before reload browsers"
exit 1
fi
# this script is runned with CWD = root param passed to http-watcher
notify_changed() {
# ping server, server knows how to reload the file
wget http://127.0.0.1:8000/dev/changed?f=$1 -O -
}
compile_scss() {
sass -t compressed --cache-location /tmp $1 $2
}
compress_html() {
java -jar thirdparty/htmlcompressor.jar \
--type html \
--charset utf8 \
--remove-quotes \
--remove-script-attr \
--remove-link-attr \
--remove-style-attr \
--simple-bool-attr \
--remove-intertag-spaces $1 -o $2
}
# [event file] pairs are passed as command line args
while [ $# -ne 0 ]; do
event=$1; shift # event name
file=$1; shift # file name
extention=${file##*.} # file extension
echo $file $event
case $extention in
scss) # compile scss to css
mkdir -p public/css/
for scss in $(find . -name "[^_]*.scss"); do
name=$(basename $scss) # filename
name="${name%.*}" # remove extension
compile_scss $scss public/css/$name.css
done
;;
tpl) # compress the changed mustache template using htmlcompressor
mkdir -p src/templates
# compress files in templates to src/templates
target=$(echo $file | sed -e 's/templates/src\/templates/')
compress_html $file $target
notify_changed $file
;;
clj)
notify_changed $file
;;
esac
done
# For rssminer
# http-watcher -root ~/workspace/rssminer -ignores "test/,/\.,\.css$,.#,src/templates,target/,public/,android/" -proxy 9090 -command ./preprocess