Created
May 16, 2013 07:09
-
-
Save LeoDT/5589929 to your computer and use it in GitHub Desktop.
compress some dir's css and js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ai_dir=/opt/www/ai | |
function scandir() { | |
local cur_dir workdir | |
workdir=$1 | |
cd ${workdir} | |
if [ ${workdir} = "/" ] | |
then | |
cur_dir="" | |
else | |
cur_dir=$(pwd) | |
fi | |
for dirlist in $(ls ${cur_dir}) | |
do | |
if test -d ${dirlist} | |
then | |
cd ${dirlist} | |
scandir ${cur_dir}/${dirlist} | |
cd .. | |
else | |
compress_file ${cur_dir}/${dirlist} | |
fi | |
done | |
} | |
function compress_file(){ | |
if grep -q \\.js$ <<< $1 | |
then | |
java -jar ${ai_dir}/tools/closure_compiler.jar --js $1 --js_output_file $1.out --warning_level QUIET | |
mv -f $1.out $1 | |
fi | |
if grep -q \\.css$ <<< $1 | |
then | |
java -jar ${ai_dir}/tools/yuicompressor.jar --type css $1 -o $1.out | |
mv -f $1.out $1 | |
fi | |
} | |
if test -d $1 | |
then | |
scandir $1 | |
elif test -f $1 | |
then | |
echo $1"is not a directory" | |
exit 1 | |
else | |
echo $1"does not exist" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment