ee647bb991d7a694692c92f89a82ec89c7761f98
[oweals/peertube.git] / scripts / build / client.sh
1 #!/bin/bash
2
3 set -eu
4
5 pre_build_hook () {
6   mkdir "./src/pending_locale" > /dev/null || true
7   mv ./src/locale/angular.*.xlf "./src/pending_locale"
8
9   if [ ! -z ${1+x} ]; then
10     mv "./src/pending_locale/angular.$1.xlf" "./src/locale"
11   fi
12 }
13
14 post_build_hook () {
15   mv ./src/pending_locale/* "./src/locale"
16   rmdir "./src/pending_locale/"
17 }
18
19 # Previous build failed
20 if [ ! -f "client/src/locale/angular.fr-FR.xlf" ]; then
21     git checkout -- client/src/locale/
22     rm -r client/src/pending_locale
23 fi
24
25 cd client
26
27 rm -rf ./dist ./compiled
28
29 pre_build_hook
30
31 defaultLanguage="en-US"
32 npm run ng build -- --output-path "dist/$defaultLanguage/" --deploy-url "/client/$defaultLanguage/" --prod --stats-json
33 mv "./dist/$defaultLanguage/assets" "./dist"
34 mv "./dist/$defaultLanguage/manifest.webmanifest" "./dist/manifest.webmanifest"
35
36 post_build_hook
37
38 # Don't build other languages if --light arg is provided
39 if [ -z ${1+x} ] || [ "$1" != "--light" ]; then
40     if [ ! -z ${1+x} ] && [ "$1" == "--light-fr" ]; then
41         languages=("fr-FR")
42     else
43         # Supported languages
44         languages=(
45             "hu-HU" "th-TH"
46             "fi-FI" "nl-NL" "gd" "el-GR" "es-ES" "oc" "pt-BR" "pt-PT" "sv-SE" "pl-PL" "ru-RU" "zh-Hans-CN" "zh-Hant-TW"
47             "fr-FR" "ja-JP" "eu-ES" "ca-ES" "cs-CZ" "eo" "de-DE" "it-IT"
48         )
49     fi
50
51     for lang in "${languages[@]}"; do
52         # TODO: remove when the project will use runtime translations
53         pre_build_hook "$lang"
54
55         npm run ng build -- --prod --i18n-file "./src/locale/angular.$lang.xlf" --i18n-format xlf --i18n-locale "$lang" \
56             --output-path "dist/$lang/" --deploy-url "/client/$lang/"
57
58         # Do not duplicate assets
59         rm -r "./dist/$lang/assets"
60
61         # TODO: remove when the project will use runtime translations
62         post_build_hook
63     done
64 fi
65
66 cd ../ && npm run build:embed && cd client/
67
68 # Copy runtime locales
69 cp -r "./src/locale" "./dist/locale"