forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnowpak.sh
More file actions
executable file
·94 lines (78 loc) · 1.92 KB
/
Copy pathsnowpak.sh
File metadata and controls
executable file
·94 lines (78 loc) · 1.92 KB
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
#!/bin/bash
# Bash script to minify snowplow.js
# Depends on YUICompressor 2.4.2 and sed
#
# Copyright 2012-2013 Snowplow Analytics Ltd
# License: http://www.opensource.org/licenses/bsd-license.php Simplified BSD
# Constants which should apply on any box
DEPENDENCIES_FILE='dependencies.txt'
FULL_OUTPUTFILE="snowplow.js"
MIN_OUTPUTFILE="sp.js"
YUIC_JARPATH="build/yuicompressor-2.4.2.jar"
usage() {
echo "Usage: ${0} [options]"
echo ""
echo "Specific options:"
echo " -y PATH path to YUICompressor 2.4.2 *"
echo " -c combine only (no minification or removing debug)"
echo ""
echo "* or set env variable YUI_COMPRESSOR_PATH instead"
echo ""
echo "Common options:"
echo " -h Show this message"
exit 1
}
parse_args() {
while getopts “cy:” opt; do
case $opt in
c)
COMBINE_ONLY=true
;;
y)
YUI_COMPRESSOR_PATH=$OPTARG
;;
\?)
usage
exit 1
;;
h)
usage
exit
;;
esac
done
}
validate_options() {
if [ ! $YUI_COMPRESSOR_PATH ]; then
echo "Path to YUICompressor 2.4.2 not provided"
usage
exit 1
fi
YUI_COMPRESSOR_PATH=$YUI_COMPRESSOR_PATH'/'$YUIC_JARPATH
if [ ! -f ${YUI_COMPRESSOR_PATH} ];then
echo "Cannot find YUICompressor 2.4.2 jarfile at ${YUI_COMPRESSOR_PATH}"
usage
fi
}
combine_files() {
while read F; do cat $F; done <$DEPENDENCIES_FILE
}
filter_out_debug() {
sed '/<DEBUG>/,/<\/DEBUG>/d'
}
yui_compress() {
java -jar ${YUI_COMPRESSOR_PATH} --type js --line-break 1000
}
compress() {
sed 's/eval/replacedEvilString/' | yui_compress | sed 's/replacedEvilString/eval/'
}
parse_args "$@"
validate_options
if [ $COMBINE_ONLY ]; then
echo "Combining source files only..."
combine_files > $FULL_OUTPUTFILE
else
echo "Running minification..."
combine_files | filter_out_debug | compress > $MIN_OUTPUTFILE
fi
exit 0