comparison bin/cssshrink.sh @ 0:4681f974d28b

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:52:31 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4681f974d28b
1 #!/bin/sh
2 PWD=`dirname "$0"`
3 JAR_DIR='/tmp'
4 VERSION='2.4.8'
5 COMPILER_URL="https://github.com/yui/yuicompressor/releases/download/v${VERSION}/yuicompressor-${VERSION}.zip"
6
7 do_shrink() {
8 rm -f "$2"
9 java -jar $JAR_DIR/yuicompressor.jar -v -o "$2" "$1"
10 }
11
12 if [ ! -w "$JAR_DIR" ]; then
13 JAR_DIR=$PWD
14 fi
15
16 if java -version >/dev/null 2>&1; then
17 :
18 else
19 echo "Java not found. Please ensure that the 'java' program is in your PATH."
20 exit 1
21 fi
22
23 if [ ! -r "$JAR_DIR/yuicompressor.jar" ]; then
24 if which wget >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then
25 wget "$COMPILER_URL" -O "/tmp/$$.zip"
26 elif which curl >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then
27 curl "$COMPILER_URL" -o "/tmp/$$.zip"
28 else
29 echo "Please download $COMPILER_URL and extract compiler.jar to $JAR_DIR/."
30 exit 1
31 fi
32 (cd $JAR_DIR && unzip "/tmp/$$.zip" && mv "yuicompressor-${VERSION}.jar" "yuicompressor.jar")
33 rm -f "/tmp/$$.zip"
34 fi
35
36 # compress single file from argument
37 if [ $# -gt 0 ]; then
38 CSS_FILE="$1"
39
40 echo "Shrinking $CSS_FILE"
41 minfile=`echo $CSS_FILE | sed -e 's/\.css$/\.min\.css/'`
42 do_shrink "$CSS_FILE" "$minfile"
43 exit
44 fi
45
46 DIRS="$PWD/../skins/* $PWD/../plugins/* $PWD/../plugins/*/skins/*"
47 # default: compress application scripts
48 for dir in $DIRS; do
49 for file in $dir/*.css; do
50 echo "$file" | grep -e '.min.css$' >/dev/null
51 if [ $? -eq 0 ]; then
52 continue
53 fi
54 if [ ! -f "$file" ]; then
55 continue
56 fi
57
58 echo "Shrinking $file"
59 minfile=`echo $file | sed -e 's/\.css$/\.min\.css/'`
60 do_shrink "$file" "$minfile"
61 done
62 done