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