Skip to content

Instantly share code, notes, and snippets.

@LeoDT
Created May 16, 2013 07:09
Show Gist options
  • Save LeoDT/5589929 to your computer and use it in GitHub Desktop.
Save LeoDT/5589929 to your computer and use it in GitHub Desktop.
compress some dir's css and js
#!/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