Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

jsshrink.sh 2.0KB

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