Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

jsshrink.sh 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh
  2. PWD=`dirname "$0"`
  3. JS_DIR="$PWD/../program/js"
  4. JAR_DIR='/tmp'
  5. LANG_IN='ECMASCRIPT3'
  6. # latest version requires Java 7, we'll use an older one
  7. #CLOSURE_COMPILER_URL='http://dl.google.com/closure-compiler/compiler-latest.zip'
  8. CLOSURE_COMPILER_URL='http://dl.google.com/closure-compiler/compiler-20131014.zip'
  9. do_shrink() {
  10. rm -f "$2"
  11. # copy the first comment block with license information for LibreJS
  12. grep -q '@lic' $1 && sed -n '/\/\*/,/\*\// { p; /\*\//q; }' $1 > $2
  13. java -jar $JAR_DIR/compiler.jar --compilation_level=SIMPLE_OPTIMIZATIONS --js="$1" --language_in="$3" >> $2
  14. }
  15. if [ ! -d "$JS_DIR" ]; then
  16. echo "Directory $JS_DIR not found."
  17. exit 1
  18. fi
  19. if [ ! -w "$JAR_DIR" ]; then
  20. JAR_DIR=$PWD
  21. fi
  22. if java -version >/dev/null 2>&1; then
  23. :
  24. else
  25. echo "Java not found. Please ensure that the 'java' program is in your PATH."
  26. exit 1
  27. fi
  28. if [ ! -r "$JAR_DIR/compiler.jar" ]; then
  29. if which wget >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then
  30. wget "$CLOSURE_COMPILER_URL" -O "/tmp/$$.zip"
  31. elif which curl >/dev/null 2>&1 && which unzip >/dev/null 2>&1; then
  32. curl "$CLOSURE_COMPILER_URL" -o "/tmp/$$.zip"
  33. else
  34. echo "Please download $CLOSURE_COMPILER_URL and extract compiler.jar to $JAR_DIR/."
  35. exit 1
  36. fi
  37. (cd $JAR_DIR && unzip "/tmp/$$.zip" "compiler.jar")
  38. rm -f "/tmp/$$.zip"
  39. fi
  40. # compress single file from argument
  41. if [ $# -gt 0 ]; then
  42. JS_DIR=`dirname "$1"`
  43. JS_FILE="$1"
  44. if [ $# -gt 1 ]; then
  45. LANG_IN="$2"
  46. fi
  47. echo "Shrinking $JS_FILE"
  48. minfile=`echo $JS_FILE | sed -e 's/\.js$/\.min\.js/'`
  49. do_shrink "$JS_FILE" "$minfile" "$LANG_IN"
  50. exit
  51. fi
  52. DIRS="$PWD/../program/js $PWD/../skins/* $PWD/../plugins/* $PWD/../plugins/*/skins/*"
  53. # default: compress application scripts
  54. for dir in $DIRS; do
  55. for file in $dir/*.js; do
  56. echo "$file" | grep -e '.min.js$' >/dev/null
  57. if [ $? -eq 0 ]; then
  58. continue
  59. fi
  60. if [ ! -f "$file" ]; then
  61. continue
  62. fi
  63. echo "Shrinking $file"
  64. minfile=`echo $file | sed -e 's/\.js$/\.min\.js/'`
  65. do_shrink "$file" "$minfile" "$LANG_IN"
  66. done
  67. done