if [ "$1" == "--help" ] ; then echo 'Usage: pack [css|js|file]' echo echo 'css - pack all .css files' echo 'js - pack all .js files' echo 'file - pack file in WWW_PATH' echo echo 'pack wihout arguments will pack all .css and .js files in WWW_PATH' echo 'WWW_PATH = '$WWW_PATH echo exit; fi ERRORS_LIST="" processYuiCompressorRepponce () { local response=${1:-''} local file=${2:-'unknown file'} local isError=$(echo $response | grep '[ERROR]') if [ "$isError" != "" ] ; then cecho "FAILED\n" $CL_RED ERRORS_LIST=$(echo "$ERRORS_LIST\n$file") else cecho "DONE\n" $CL_GREEN fi } # CSS fileName="" if [ "$1" == "css" ] ; then css=true; js=false; else if [ "$1" == "js" ] ; then css=false; js=true; else if [ "$1" == "" ] ; then css=true; js=true; else fileName="$1" fi fi fi CURRENT_DIR=`pwd` cd $WWW_PATH if [ "$css" == true ] ; then list=$(find ./css -name '*.css' -type f | grep -Fv '.pack.' | grep -Fv '.merge.') for f in $(echo -e $list); do ext=$(echo $f | sed 's/.*\.//') o=$(echo $f | sed "s/\.$ext$/\.pack\.$ext/") cecho "$f -> $o - " response=$(java -jar $BASE_PATH/site/bin/yuicompressor.jar $f -o $o 2>&1) processYuiCompressorRepponce "$response" "$f" done; fi if [ "$js" == true ] ; then list=$(find ./js -name '*.js' -type f | grep -Fv '.pack.' | grep -Fv '.merge.' | grep -Fv './js/ckeditor/') list="$list\n./js/ckeditor/ckeditor.js" for f in $(echo -e $list); do ext=$(echo $f | sed 's/.*\.//') o=$(echo $f | sed "s/\.$ext$/\.pack\.$ext/") cecho "$f -> $o - " response=$(java -jar $BASE_PATH/site/bin/yuicompressor.jar $f -o $o 2>&1) processYuiCompressorRepponce "$response" "$f" done; fi if [ "$fileName" != "" ] ; then ext=$(echo $fileName | sed 's/.*\.//') o=$(echo $fileName | sed "s/$ext$/pack\.$ext/") cecho "$fileName -> $o - " response=$(java -jar $BASE_PATH/site/bin/yuicompressor.jar $fileName -o $o 2>&1) processYuiCompressorRepponce "$response" "$fileName" fi cd $CURRENT_DIR if [ "$ERRORS_LIST" != "" ] ; then cecho "Next files are not packed:$ERRORS_LIST\n" $CL_RED else cecho "All files packed successfuly\n" $CL_GREEN fi exit 0