package.sh 4.0 KB

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