package.sh 4.0 KB

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