compress.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #/bin/sh
  2. # Requires Closure Compiler Application
  3. # https://developers.google.com/closure/compiler/docs/gettingstarted_app
  4. # --compilation_level ADVANCED_OPTIMIZATIONS
  5. SCRIPTS=("turn" "turn.html4" "zoom" "scissor")
  6. SCRIPTS_LEN=${#SCRIPTS[@]}
  7. SCRIPTS_COMMENT="/* turn.js 4.1.0 | Copyright (c) 2012 Emmanuel Garcia | turnjs.com | turnjs.com/license.txt */"
  8. echo -e "${SCRIPTS_COMMENT}\n" > comment.js
  9. if [ ! -f /tmp/compiler.jar ];
  10. then
  11. echo "Downloading Google Closure Compiler..."
  12. curl --silent -L http://closure-compiler.googlecode.com/files/compiler-latest.zip > /tmp/compiler-latest.zip
  13. unzip -o /tmp/compiler-latest.zip -d /tmp
  14. rm /tmp/compiler-latest.zip
  15. chmod +x /tmp/compiler.jar
  16. fi
  17. echo "Making Minimized files..."
  18. for (( i=0; i<${SCRIPTS_LEN}; i++ ));
  19. do
  20. java -jar "/tmp/compiler.jar" --js ${SCRIPTS[$i]}.js > ${SCRIPTS[$i]}.closure.js
  21. cat comment.js ${SCRIPTS[$i]}.closure.js > ${SCRIPTS[$i]}.min.js
  22. rm ${SCRIPTS[$i]}.closure.js
  23. m=$(ls -la ${SCRIPTS[$i]}.min.js | awk '{ print $5}')
  24. gzip -nfc --best ${SCRIPTS[$i]}.min.js > ${SCRIPTS[$i]}.min.js.gz
  25. g=$(ls -la ${SCRIPTS[$i]}.min.js.gz | awk '{ print $5}')
  26. echo " ${SCRIPTS[$i]}.js: $m bytes minified, $g bytes gzipped"
  27. rm ${SCRIPTS[$i]}.min.js.gz
  28. if [ "--test" == "$1" ]; then
  29. rm ${SCRIPTS[$i]}.min.js
  30. fi
  31. done
  32. rm comment.js