Created
March 21, 2013 18:54
-
-
Save JoaoVagner/5215647 to your computer and use it in GitHub Desktop.
A quem possa interessar, um compressor e minificador de JS e CSS usando Yui Compressor
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 | |
limpa() { | |
echo -e "\nDeleting existing minified files..." | |
find ../js -name \*.min.js -exec rm {} \; | |
find ../css -name \*.min.css -exec rm {} \; | |
} | |
comprime_js() { | |
echo -e "\nComprimindo e minificando o JavaScript..." | |
jslist=`find ../js -type f -name \*.js` | |
for jsfile in $jslist | |
do | |
echo "Processando: ${jsfile}" | |
java -jar ${YUICOMPRESSOR} -o ${jsfile%.*}.min.js ${jsfile} | |
done | |
} | |
comprime_css() { | |
echo -e "\nComprimindo e minificando o CSS..." | |
csslist=`find ../css -type f -name \*.css` | |
for cssfile in $csslist | |
do | |
echo "Processando: ${cssfile}" | |
java -jar ${YUICOMPRESSOR} -o ${cssfile%.*}.min.css ${cssfile} | |
done | |
} | |
usage() { | |
echo -e "\compressor.sh [-cjdh]" | |
echo " c : Comprime e minifica arquivos CSS" | |
echo " j : Comprime e minifica arquivos Javascript" | |
echo " d : Deleta arquivos comprimidos e minificados" | |
echo " h: Peça ajuda!" | |
} | |
CSS=false | |
JS=false | |
DELETE=false | |
HELP=false | |
while getopts "cjdh" input | |
do | |
case $input in | |
c ) CSS=true;; | |
j ) JS=true;; | |
d ) DELETE=true;; | |
h ) HELP=true;; | |
esac | |
done | |
if ! $JS && ! $CSS && ! $DELETE | |
then | |
usage | |
exit 0 | |
fi | |
if $HELP | |
then | |
usage | |
exit 0 | |
fi | |
if ! [ `find ../yui -type f -name min\*.jar` ] | |
then | |
echo "Yui Compressor não encontrado!" | |
exit 1 | |
else | |
YUICOMPRESSOR=`find ../yui -type f -name min\*.jar` | |
fi | |
if $DELETE | |
then | |
limpa | |
fi | |
if $JS | |
then | |
comprime_js | |
fi | |
if $CSS | |
then | |
comprime_css | |
fi | |
echo -e "\nDone." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ver meu fork ai vei! :D