minify.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. #
  3. # minify.sh
  4. #
  5. # Minfies javascript files
  6. #
  7. # @author Christopher Han <xiphux@gmail.com>
  8. # @copyright Copyright (c) 2010 Christopher Han
  9. # @package GitPHP
  10. # @subpackage util
  11. #
  12. JSDIR="js"
  13. JSEXT=".js"
  14. MINEXT=".min.js"
  15. GZEXT=".gz"
  16. CSSDIR="css"
  17. CSSEXT=".css"
  18. MINCSSEXT=".min.css"
  19. rm -fv ${JSDIR}/*${MINEXT}
  20. rm -fv ${CSSDIR}/*${MINCSSEXT}
  21. rm -fv ${JSDIR}/*${GZEXT}
  22. rm -fv ${JSDIR}/ext/*${GZEXT}
  23. rm -fv ${CSSDIR}/*${GZEXT}
  24. rm -fv ${CSSDIR}/ext/*${GZEXT}
  25. if [ "$1" == "clean" ]; then
  26. exit;
  27. fi
  28. for i in ${JSDIR}/*${JSEXT}; do
  29. echo "Minifying ${i}..."
  30. JSMODULE="`basename ${i%$JSEXT}`"
  31. java -classpath lib/rhino/js.jar:lib/closure/compiler.jar org.mozilla.javascript.tools.shell.Main lib/requirejs/r.js -o name=${JSMODULE} out=${JSDIR}/${JSMODULE}${MINEXT}.tmp baseUrl=${JSDIR} paths.jquery="empty:" paths.qtip="empty:" paths.d3="empty:" paths.modernizr="ext/modernizr.custom" optimize="closure" preserveLicenseComments="false"
  32. cat util/jsheader.js ${JSDIR}/${JSMODULE}${MINEXT}.tmp > ${JSDIR}/${JSMODULE}${MINEXT}
  33. rm -f ${JSDIR}/${JSMODULE}${MINEXT}.tmp
  34. done
  35. for i in ${CSSDIR}/*${CSSEXT}; do
  36. echo "Minifying ${i}..."
  37. CSSBASE=${i%$CSSEXT}
  38. java -classpath lib/rhino/js.jar org.mozilla.javascript.tools.shell.Main lib/requirejs/r.js -o cssIn=${i} out=${CSSBASE}${MINCSSEXT} optimizeCss="standard"
  39. done
  40. for i in ${JSDIR}/*${MINEXT}; do
  41. gzip -v -c ${i} > ${i}${GZEXT}
  42. touch ${i} ${i}${GZEXT}
  43. done
  44. for i in ${JSDIR}/ext/jquery*${MINEXT}; do
  45. gzip -v -c ${i} > ${i}${GZEXT}
  46. touch ${i} ${i}${GZEXT}
  47. done
  48. gzip -v -c ${JSDIR}/ext/require.js > ${JSDIR}/ext/require.js${GZEXT}
  49. touch ${JSDIR}/ext/require.js ${JSDIR}/ext/require.js${GZEXT}
  50. for i in ${CSSDIR}/*${MINCSSEXT}; do
  51. gzip -v -c ${i} > ${i}${GZEXT}
  52. touch ${i} ${i}${GZEXT}
  53. done
  54. gzip -v -c ${CSSDIR}/ext/jquery.qtip.min.css > ${CSSDIR}/ext/jquery.qtip.min.css${GZEXT}
  55. touch ${CSSDIR}/ext/jquery.qtip.min.css ${CSSDIR}/ext/jquery.qtip.min.css${GZEXT}