package.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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,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. echo "+ Copy dependencies..."
  38. targets=(
  39. angular/angular.js
  40. angular/angular-csp.css
  41. angular-aria/angular-aria.min.js
  42. angular-animate/angular-animate.min.js
  43. angular-sanitize/angular-sanitize.min.js
  44. angular-route/angular-route.min.js
  45. babel-es6-polyfill/browser-polyfill.min.js
  46. msgpack-lite/dist/msgpack.min.js
  47. tweetnacl/nacl-fast.min.js
  48. file-saver/FileSaver.min.js
  49. js-sha256/build/sha256.min.js
  50. @saltyrtc/chunked-dc/dist/chunked-dc.es5.js
  51. @saltyrtc/client/dist/saltyrtc-client.es5.js
  52. @saltyrtc/task-webrtc/dist/saltyrtc-task-webrtc.es5.js
  53. @saltyrtc/task-relayed-data/dist/saltyrtc-task-relayed-data.es5.js
  54. webrtc-adapter/out/adapter_no_edge.js
  55. webrtc-adapter/out/adapter.js
  56. qrcode-generator/qrcode.js
  57. qrcode-generator/qrcode_UTF8.js
  58. angular-qrcode/angular-qrcode.js
  59. angularjs-scroll-glue/src/scrollglue.js
  60. angular-material/angular-material.min.js
  61. angular-material/angular-material.min.css
  62. croppie/croppie.min.js
  63. croppie/croppie.css
  64. autolinker/dist/Autolinker.min.js
  65. angular-ui-router/release/angular-ui-router.min.js
  66. messageformat/messageformat.min.js
  67. angular-translate/dist/angular-translate.min.js
  68. angular-translate/dist/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js
  69. angular-translate/dist/angular-translate-interpolation-messageformat/angular-translate-interpolation-messageformat.min.js
  70. sdp/sdp.js
  71. )
  72. for target in "${targets[@]}"; do
  73. if [[ "$OSTYPE" == "darwin"* ]]; then
  74. ditto "node_modules/$target" "$DIR/node_modules/$target"
  75. else
  76. install -D "node_modules/$target" "$DIR/node_modules/$target"
  77. fi
  78. done
  79. echo "+ Update version number..."
  80. # Note: The `-i.bak` notation is requires so that the sed command works both on Linux
  81. # and on macOS: https://stackoverflow.com/q/5694228/284318
  82. 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
  83. 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
  84. echo "+ Update permissions..."
  85. find $DIR/ -type f -exec chmod 644 {} \;
  86. find $DIR/ -type d -exec chmod 755 {} \;
  87. echo "+ Put everything in an archive..."
  88. cd release
  89. tar cfz "../dist/threema-web-$VERSION.tar.gz" $(basename "$DIR")
  90. cd ..
  91. echo -e "\nDone."