Last change
on this file since 744 was
744,
checked in by duh, 13 years ago
|
setting svn properties
|
-
Property svn:executable set to
*
-
Property svn:keywords set to
Author Date Rev
|
File size:
1.2 KB
|
Line | |
---|
1 | #!/bin/sh |
---|
2 | SOURCE=$1 |
---|
3 | ONLY_IF_MINIFIED_ALREADY_EXISTS=$2 |
---|
4 | DESTINATION=`echo $1|sed 's/\.[A-Za-z]*$/.min\0/g'` |
---|
5 | MD5SUM=`which md5sum` |
---|
6 | MD5_CURRENT= |
---|
7 | MD5_NEW= |
---|
8 | TMP_FILE=~/tmp/minified |
---|
9 | |
---|
10 | # got a parameter? |
---|
11 | if [ ! $1 ]; then |
---|
12 | echo "Usage: "$0" <input file> [only create if a minified already exists]" |
---|
13 | echo "Example: "$0" bla.js 1" |
---|
14 | exit; |
---|
15 | fi |
---|
16 | |
---|
17 | # does the input file exist? |
---|
18 | if [ ! -f $1 ]; then |
---|
19 | echo "Usage: "$0" <input file> [only create if a minified already exists]" |
---|
20 | echo "Example: "$0" bla.js 1" |
---|
21 | echo "error: could not find "$1 |
---|
22 | exit; |
---|
23 | fi |
---|
24 | |
---|
25 | # does the destination exist? |
---|
26 | if [ -f $DESTINATION ]; then |
---|
27 | # yes, create an MD5 sum |
---|
28 | MD5_CURRENT=`$MD5SUM -t $DESTINATION | sed 's/ .*$//g'` |
---|
29 | elif [ $ONLY_IF_MINIFIED_ALREADY_EXISTS ]; then |
---|
30 | # no need to continue |
---|
31 | exit; |
---|
32 | fi |
---|
33 | |
---|
34 | # minify sourcefile |
---|
35 | java -jar ~/apps/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar $SOURCE > $TMP_FILE |
---|
36 | |
---|
37 | # determine the MD5 hash of the generated file |
---|
38 | MD5_NEW=`$MD5SUM -t $TMP_FILE | sed 's/ .*$//g'` |
---|
39 | |
---|
40 | # do the MD5 hashes differ? |
---|
41 | if [ "$MD5_CURRENT" != "$MD5_NEW" ]; then |
---|
42 | cp $TMP_FILE $DESTINATION |
---|
43 | echo ".created minified version of "$SOURCE" ("$MD5_CURRENT" > "$MD5_NEW")" |
---|
44 | fi |
---|
45 | |
---|
46 | # remove temp file |
---|
47 | if [ -f $TMP_FILE ]; then |
---|
48 | rm $TMP_FILE > /dev/null |
---|
49 | fi |
---|
Note: See
TracBrowser
for help on using the repository browser.