package.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. echo -e " _____ _ _ _ _ _ "
  4. echo -e "|_ _| |_ ___ ___ ___ _____ ___| | | |___| |_ "
  5. echo -e " | | | | _| -_| -_| | .'| | | | -_| . | \e[32m_\e[0m "
  6. echo -e " |_| |_|_|_| |___|___|_|_|_|__,|_____|___|___|\e[32m|_|\e[0m\n"
  7. echo -e "Creating release distribution for Threema Web\n"
  8. # Test whether we're in the root dir
  9. if [ ! -f "package.json" ]; then
  10. echo "Error: package.json not found."
  11. echo "Please run this script from the root directory of this repository."
  12. exit 1
  13. fi
  14. # Clean up release directory
  15. if [ -e "release" ]; then
  16. while true; do
  17. read -r -p "Release directory exists. Delete it? (y/n) " input
  18. case $input in
  19. y|Y ) echo -e "\n+ Delete release directory..."; rm -r release; break;;
  20. n|N ) echo "Aborting."; exit 1;;
  21. * ) echo "Invalid input.";;
  22. esac
  23. done
  24. fi
  25. VERSION=$(grep "\"version\"" package.json | sed 's/[[:blank:]]*\"version\": \"\([^\"]*\).*/\1/')
  26. DIR="release/threema-web-$VERSION"
  27. echo "+ Create release directory..."
  28. mkdir -p $DIR/{dist,partials,directives,components,node_modules,partials/messenger.receiver,troubleshoot}
  29. echo "+ Copy code..."
  30. cp -R index.html $DIR/
  31. cp -R dist/app.js $DIR/dist/
  32. cp -R public/* $DIR/
  33. cp -R troubleshoot/* $DIR/troubleshoot/
  34. cp -R src/partials/*.html $DIR/partials/
  35. cp -R src/partials/messenger.receiver/*.html $DIR/partials/messenger.receiver/
  36. cp -R src/directives/*.html $DIR/directives/
  37. cp -R src/components/*.html $DIR/components/ 2>/dev/null || :
  38. echo "+ Copy dependencies..."
  39. targets=(
  40. angular/angular.js
  41. angular/angular-csp.css
  42. angular-aria/angular-aria.min.js
  43. angular-animate/angular-animate.min.js
  44. angular-sanitize/angular-sanitize.min.js
  45. angular-route/angular-route.min.js
  46. msgpack-lite/dist/msgpack.min.js
  47. tweetnacl/nacl-fast.min.js
  48. @saltyrtc/chunked-dc/dist/chunked-dc.es5.js
  49. @saltyrtc/client/dist/saltyrtc-client.es5.js
  50. @saltyrtc/task-webrtc/dist/saltyrtc-task-webrtc.es5.js
  51. @saltyrtc/task-relayed-data/dist/saltyrtc-task-relayed-data.es5.js
  52. webrtc-adapter/out/adapter_no_edge.js
  53. webrtc-adapter/out/adapter.js
  54. qrcode-generator/qrcode.js
  55. qrcode-generator/qrcode_UTF8.js
  56. angular-qrcode/angular-qrcode.js
  57. angularjs-scroll-glue/src/scrollglue.js
  58. angular-material/angular-material.min.js
  59. angular-material/angular-material.min.css
  60. croppie/croppie.min.js
  61. croppie/croppie.css
  62. autolinker/dist/Autolinker.min.js
  63. @uirouter/angularjs/release/angular-ui-router.min.js
  64. messageformat/messageformat.min.js
  65. angular-translate/dist/angular-translate.min.js
  66. angular-translate/dist/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js
  67. angular-translate/dist/angular-translate-interpolation-messageformat/angular-translate-interpolation-messageformat.min.js
  68. sdp/sdp.js
  69. )
  70. for target in "${targets[@]}"; do
  71. if [[ "$OSTYPE" == "darwin"* ]]; then
  72. ditto "node_modules/$target" "$DIR/node_modules/$target"
  73. else
  74. install -D "node_modules/$target" "$DIR/node_modules/$target"
  75. fi
  76. done
  77. echo "+ Update version number..."
  78. # Note: The `-i.bak` notation is requires so that the sed command works both on Linux
  79. # and on macOS: https://stackoverflow.com/q/5694228/284318
  80. sed -i.bak -e "s/\[\[VERSION\]\]/${VERSION}/g" $DIR/index.html $DIR/troubleshoot/index.html $DIR/dist/app.js $DIR/manifest.webmanifest $DIR/browserconfig.xml $DIR/version.txt
  81. rm $DIR/index.html.bak $DIR/troubleshoot/index.html.bak $DIR/dist/app.js.bak $DIR/manifest.webmanifest.bak $DIR/browserconfig.xml.bak $DIR/version.txt.bak
  82. echo "+ Update permissions..."
  83. find $DIR/ -type f -exec chmod 644 {} \;
  84. find $DIR/ -type d -exec chmod 755 {} \;
  85. echo "+ Put everything in an archive..."
  86. cd release
  87. tar cfz "../dist/threema-web-$VERSION.tar.gz" $(basename "$DIR")
  88. cd ..
  89. echo -e "\nDone."