fd9190660023e01cb2e336629c4a493ad2ae64f2
[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             "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"
46             "fr-FR" "ja-JP" "eu-ES" "ca-ES" "cs-CZ" "eo" "de-DE" "it-IT"
47         )
48     fi
49
50     for lang in "${languages[@]}"; do
51         # TODO: remove when the project will use runtime translations
52         pre_build_hook "$lang"
53
54         npm run ng build -- --prod --i18n-file "./src/locale/angular.$lang.xlf" --i18n-format xlf --i18n-locale "$lang" \
55             --output-path "dist/$lang/" --deploy-url "/client/$lang/"
56
57         # Do not duplicate assets
58         rm -r "./dist/$lang/assets"
59
60         # TODO: remove when the project will use runtime translations
61         post_build_hook
62     done
63 fi
64
65 npm run build:embed
66
67 # Copy runtime locales
68 cp -r "./src/locale" "./dist/locale"