build.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/sh
  2. # Part of Zombie Navigator
  3. # Copyright © 2015 Zombie Navigator Developers
  4. mylog () {
  5. echo "[`date`] $@" >&2
  6. }
  7. dir="`dirname "$0"`"
  8. dir="`cd "$dir";pwd`"
  9. cd "$dir/src"
  10. . ../version_info
  11. # Create .xpi
  12. while [ "$#" -gt 0 ] ; do
  13. case "$1" in
  14. --minify-js)
  15. minify_js=1
  16. ;;
  17. --help)
  18. echo "Usage: $0 [--minify-js]"
  19. exit
  20. ;;
  21. --version)
  22. echo "Will build: '$addon_version'"
  23. exit
  24. ;;
  25. esac
  26. shift
  27. done
  28. mylog "$addon_id version $addon_version build script"
  29. buildsDir="$dir/builds"
  30. buildTmpDir="$dir/.build"
  31. mkdir -p "$buildsDir"
  32. rm -rf "$buildTmpDir"
  33. cd ..
  34. cp -rf src "$buildTmpDir"
  35. cd "$buildTmpDir"
  36. mylog "Optimizing files..."
  37. find . -type f \( -name '*.html' -or -name '*.js' \) -execdir sh -c 'egrep -v "^\s*$|vim:" "$1" > "$1.tmp" && mv -f "$1.tmp" "$1" || rm -f "$1.tmp"' -- {} \;
  38. find . -type f -name '*.css' -execdir sh -c 'egrep -v "^\s*$|vim:" "$1" | tr -d "\t\n" | perl -pe "s/\s*([{:>+,])\s*/\1/g ; s/;}/}/g" > "$1.tmp" && mv -f "$1.tmp" "$1" || rm -f "$1.tmp"' -- {} \;
  39. find . -type f -name '*.json' -execdir sh -c 'egrep -v "^\s*$" "$1" | sed "s/^ *//" | tr -d "\n" > "$1.tmp" && mv -f "$1.tmp" "$1" || rm -f "$1.tmp"' -- {} \;
  40. [ "$minify_js" ] && {
  41. mylog "EXPERIMENTAL: Doing JS minification..."
  42. mylog "This may result in problems!"
  43. find . -type f -name '*.js' -exec sh -c 'echo "Compressing: $1" ; ../bin/estidy < "$1" > "$1.tmp" && mv -f "$1.tmp" "$1" || rm -f "$1.tmp"' -- {} \;
  44. } || {
  45. mylog "Skipping JS minification!"
  46. }
  47. du -a -h --apparent-size --max-depth 1 || du -ahd1
  48. mylog "Building the addon..."
  49. mylog "Please ignore JPM warnings about the 'sember' (if any) (NOT relevant for stable release versions)"
  50. mylog "Because we use '~' for prereleases (for consistence with GNU/Linux conventions)"
  51. ../bin/build || {
  52. mylog "[ERROR] JPM: Failed"
  53. exit 1
  54. }
  55. if which advzip >/dev/null 2>&1 ; then
  56. # AdvanceCOMP available
  57. mylog "Recompressing..."
  58. advzip -z -4 -i 200 ./*.xpi
  59. else
  60. mylog "NOTE: Skipping recompression (AdvanceCOMP needed)..."
  61. fi
  62. mylog "Saving the archive..."
  63. targetDir="$buildsDir/`date +%s`"
  64. [ "$minify_js" ] && targetDir="$targetDir.min-js"
  65. mkdir -p "$targetDir"
  66. mv -b -v ./*.xpi "$targetDir"/ || mv -n -v ./*.xpi "$targetDir"/
  67. cd ..
  68. rm -rf "$buildTmpDir"
  69. mylog "Done? ($addon_id $addon_version)"
  70. # vim: ts=4 noet ai