client.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #!/bin/bash
  2. set -eu
  3. declare -A languages
  4. pre_build_hook () {
  5. mkdir "./src/pending_locale" > /dev/null || true
  6. mv ./src/locale/angular.*.xlf "./src/pending_locale"
  7. if [ ! -z ${1+x} ]; then
  8. mv "./src/pending_locale/angular.$1.xlf" "./src/locale"
  9. fi
  10. }
  11. post_build_hook () {
  12. mv ./src/pending_locale/* "./src/locale"
  13. rmdir "./src/pending_locale/"
  14. }
  15. # Previous build failed
  16. if [ ! -f "client/src/locale/angular.fr-FR.xlf" ]; then
  17. git checkout -- client/src/locale/
  18. rm -r client/src/pending_locale
  19. fi
  20. cd client
  21. rm -rf ./dist ./compiled
  22. pre_build_hook
  23. additionalParams=""
  24. if [ ! -z ${1+x} ] && [ "$1" == "--analyze-bundle" ]; then
  25. additionalParams="--namedChunks=true --outputHashing=none"
  26. export ANALYZE_BUNDLE=true
  27. fi
  28. defaultLanguage="en-US"
  29. npm run ng build -- --output-path "dist/$defaultLanguage/" --deploy-url "/client/$defaultLanguage/" --prod --stats-json $additionalParams
  30. mv "./dist/$defaultLanguage/assets" "./dist"
  31. mv "./dist/$defaultLanguage/manifest.webmanifest" "./dist/manifest.webmanifest"
  32. post_build_hook
  33. # Don't build other languages if --light arg is provided
  34. if [ -z ${1+x} ] || ([ "$1" != "--light" ] && [ "$1" != "--analyze-bundle" ]); then
  35. if [ ! -z ${1+x} ] && [ "$1" == "--light-hu" ]; then
  36. languages=(["hu"]="hu-HU")
  37. elif [ ! -z ${1+x} ] && [ "$1" == "--light-ar" ]; then
  38. languages=(["ar"]="ar")
  39. elif [ ! -z ${1+x} ] && [ "$1" == "--light-vi" ]; then
  40. languages=(["vi"]="vi-VN")
  41. elif [ ! -z ${1+x} ] && [ "$1" == "--light-kab" ]; then
  42. languages=(["kab"]="kab")
  43. elif [ ! -z ${1+x} ] && [ "$1" == "--light-th" ]; then
  44. languages=(["th"]="th-TH")
  45. elif [ ! -z ${1+x} ] && [ "$1" == "--light-fi" ]; then
  46. languages=(["fi"]="fi-FI")
  47. elif [ ! -z ${1+x} ] && [ "$1" == "--light-nl" ]; then
  48. languages=(["nl"]="nl-NL")
  49. elif [ ! -z ${1+x} ] && [ "$1" == "--light-gd" ]; then
  50. languages=(["gd"]="gd")
  51. elif [ ! -z ${1+x} ] && [ "$1" == "--light-el" ]; then
  52. languages=(["el"]="el-GR")
  53. elif [ ! -z ${1+x} ] && [ "$1" == "--light-es" ]; then
  54. languages=(["es"]="es-ES")
  55. elif [ ! -z ${1+x} ] && [ "$1" == "--light-oc" ]; then
  56. languages=(["oc"]="oc")
  57. elif [ ! -z ${1+x} ] && [ "$1" == "--light-pt" ]; then
  58. languages=(["pt"]="pt-BR")
  59. elif [ ! -z ${1+x} ] && [ "$1" == "--light-pt-PT" ]; then
  60. languages=(["pt-PT"]="pt-PT")
  61. elif [ ! -z ${1+x} ] && [ "$1" == "--light-sv" ]; then
  62. languages=(["sv"]="sv-SE")
  63. elif [ ! -z ${1+x} ] && [ "$1" == "--light-pl" ]; then
  64. languages=(["pl"]="pl-PL")
  65. elif [ ! -z ${1+x} ] && [ "$1" == "--light-ru" ]; then
  66. languages=(["ru"]="ru-RU")
  67. elif [ ! -z ${1+x} ] && [ "$1" == "--light-zh-Hans" ]; then
  68. languages=(["zh-Hans"]="zh-Hans-CN")
  69. elif [ ! -z ${1+x} ] && [ "$1" == "--light-zh-Hant" ]; then
  70. languages=(["zh-Hant"]="zh-Hant-TW")
  71. elif [ ! -z ${1+x} ] && [ "$1" == "--light-fr" ]; then
  72. languages=(["fr"]="fr-FR")
  73. elif [ ! -z ${1+x} ] && [ "$1" == "--light-ja" ]; then
  74. languages=(["ja"]="ja-JP")
  75. elif [ ! -z ${1+x} ] && [ "$1" == "--light-eu" ]; then
  76. languages=(["eu"]="eu-ES")
  77. elif [ ! -z ${1+x} ] && [ "$1" == "--light-ca" ]; then
  78. languages=(["ca"]="ca-ES")
  79. elif [ ! -z ${1+x} ] && [ "$1" == "--light-cs" ]; then
  80. languages=(["cs"]="cs-CZ")
  81. elif [ ! -z ${1+x} ] && [ "$1" == "--light-eo" ]; then
  82. languages=(["eo"]="eo")
  83. elif [ ! -z ${1+x} ] && [ "$1" == "--light-de" ]; then
  84. languages=(["de"]="de-DE")
  85. elif [ ! -z ${1+x} ] && [ "$1" == "--light-it" ]; then
  86. languages=(["it"]="it-IT")
  87. else
  88. # Supported languages
  89. languages=(
  90. ["ar"]="ar"
  91. ["vi"]="vi-VN"
  92. ["hu"]="hu-HU"
  93. ["th"]="th-TH"
  94. ["fi"]="fi-FI"
  95. ["nl"]="nl-NL"
  96. ["gd"]="gd"
  97. ["el"]="el-GR"
  98. ["es"]="es-ES"
  99. ["oc"]="oc"
  100. ["pt"]="pt-BR"
  101. ["pt-PT"]="pt-PT"
  102. ["sv"]="sv-SE"
  103. ["pl"]="pl-PL"
  104. ["ru"]="ru-RU"
  105. ["zh-Hans"]="zh-Hans-CN"
  106. ["zh-Hant"]="zh-Hant-TW"
  107. ["fr"]="fr-FR"
  108. ["ja"]="ja-JP"
  109. ["eu"]="eu-ES"
  110. ["ca"]="ca-ES"
  111. ["cs"]="cs-CZ"
  112. ["eo"]="eo"
  113. ["de"]="de-DE"
  114. ["it"]="it-IT"
  115. ["kab"]="kab"
  116. )
  117. fi
  118. for key in "${!languages[@]}"; do
  119. lang=${languages[$key]}
  120. # TODO: remove when the project will use runtime translations
  121. pre_build_hook "$lang"
  122. npm run ng build -- --prod --configuration="$lang" --output-path "dist/build"
  123. # If --localize is not used
  124. mv "dist/build/$key" "dist/$lang"
  125. rmdir "dist/build"
  126. # If --localize is used
  127. # if [ ! "$lang" = "$key" ]; then
  128. # mv "dist/$key" "dist/$lang"
  129. # fi
  130. # Do not duplicate assets
  131. rm -r "./dist/$lang/assets"
  132. # TODO: remove when the project will use runtime translations
  133. post_build_hook
  134. done
  135. fi
  136. cd ../ && npm run build:embed && cd client/
  137. # Copy runtime locales
  138. cp -r "./src/locale" "./dist/locale"