]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/build/client.sh
Analyze embed too with bundlewatch
[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
40 defaultLanguage="en-US"
41 npm run ng build -- --output-path "dist/$defaultLanguage/" --deploy-url "/client/$defaultLanguage/" --prod --stats-json $additionalParams
42 mv "./dist/$defaultLanguage/assets" "./dist"
43 mv "./dist/$defaultLanguage/manifest.webmanifest" "./dist/manifest.webmanifest"
44
45 post_build_hook
46
47 # Don't build other languages if --light arg is provided
48 if [ -z ${1+x} ] || ([ "$1" != "--light" ] && [ "$1" != "--analyze-bundle" ]); then
49 if [ ! -z ${1+x} ] && [ "$1" == "--light-hu" ]; then
50 languages=(["hu"]="hu-HU")
51 elif [ ! -z ${1+x} ] && [ "$1" == "--light-ar" ]; then
52 languages=(["ar"]="ar")
53 elif [ ! -z ${1+x} ] && [ "$1" == "--light-vi" ]; then
54 languages=(["vi"]="vi-VN")
55 elif [ ! -z ${1+x} ] && [ "$1" == "--light-kab" ]; then
56 languages=(["kab"]="kab")
57 elif [ ! -z ${1+x} ] && [ "$1" == "--light-th" ]; then
58 languages=(["th"]="th-TH")
59 elif [ ! -z ${1+x} ] && [ "$1" == "--light-fi" ]; then
60 languages=(["fi"]="fi-FI")
61 elif [ ! -z ${1+x} ] && [ "$1" == "--light-nl" ]; then
62 languages=(["nl"]="nl-NL")
63 elif [ ! -z ${1+x} ] && [ "$1" == "--light-gd" ]; then
64 languages=(["gd"]="gd")
65 elif [ ! -z ${1+x} ] && [ "$1" == "--light-el" ]; then
66 languages=(["el"]="el-GR")
67 elif [ ! -z ${1+x} ] && [ "$1" == "--light-es" ]; then
68 languages=(["es"]="es-ES")
69 elif [ ! -z ${1+x} ] && [ "$1" == "--light-oc" ]; then
70 languages=(["oc"]="oc")
71 elif [ ! -z ${1+x} ] && [ "$1" == "--light-pt" ]; then
72 languages=(["pt"]="pt-BR")
73 elif [ ! -z ${1+x} ] && [ "$1" == "--light-pt-PT" ]; then
74 languages=(["pt-PT"]="pt-PT")
75 elif [ ! -z ${1+x} ] && [ "$1" == "--light-sv" ]; then
76 languages=(["sv"]="sv-SE")
77 elif [ ! -z ${1+x} ] && [ "$1" == "--light-pl" ]; then
78 languages=(["pl"]="pl-PL")
79 elif [ ! -z ${1+x} ] && [ "$1" == "--light-ru" ]; then
80 languages=(["ru"]="ru-RU")
81 elif [ ! -z ${1+x} ] && [ "$1" == "--light-zh-Hans" ]; then
82 languages=(["zh-Hans"]="zh-Hans-CN")
83 elif [ ! -z ${1+x} ] && [ "$1" == "--light-zh-Hant" ]; then
84 languages=(["zh-Hant"]="zh-Hant-TW")
85 elif [ ! -z ${1+x} ] && [ "$1" == "--light-fr" ]; then
86 languages=(["fr"]="fr-FR")
87 elif [ ! -z ${1+x} ] && [ "$1" == "--light-ja" ]; then
88 languages=(["ja"]="ja-JP")
89 elif [ ! -z ${1+x} ] && [ "$1" == "--light-eu" ]; then
90 languages=(["eu"]="eu-ES")
91 elif [ ! -z ${1+x} ] && [ "$1" == "--light-ca" ]; then
92 languages=(["ca"]="ca-ES")
93 elif [ ! -z ${1+x} ] && [ "$1" == "--light-cs" ]; then
94 languages=(["cs"]="cs-CZ")
95 elif [ ! -z ${1+x} ] && [ "$1" == "--light-eo" ]; then
96 languages=(["eo"]="eo")
97 elif [ ! -z ${1+x} ] && [ "$1" == "--light-de" ]; then
98 languages=(["de"]="de-DE")
99 elif [ ! -z ${1+x} ] && [ "$1" == "--light-it" ]; then
100 languages=(["it"]="it-IT")
101 else
102 # Supported languages
103 languages=(
104 ["ar"]="ar"
105 ["vi"]="vi-VN"
106 ["hu"]="hu-HU"
107 ["th"]="th-TH"
108 ["fi"]="fi-FI"
109 ["nl"]="nl-NL"
110 ["gd"]="gd"
111 ["el"]="el-GR"
112 ["es"]="es-ES"
113 ["oc"]="oc"
114 ["pt"]="pt-BR"
115 ["pt-PT"]="pt-PT"
116 ["sv"]="sv-SE"
117 ["pl"]="pl-PL"
118 ["ru"]="ru-RU"
119 ["zh-Hans"]="zh-Hans-CN"
120 ["zh-Hant"]="zh-Hant-TW"
121 ["fr"]="fr-FR"
122 ["ja"]="ja-JP"
123 ["eu"]="eu-ES"
124 ["ca"]="ca-ES"
125 ["cs"]="cs-CZ"
126 ["eo"]="eo"
127 ["de"]="de-DE"
128 ["it"]="it-IT"
129 ["kab"]="kab"
130 )
131 fi
132
133 for key in "${!languages[@]}"; do
134 lang=${languages[$key]}
135
136 # TODO: remove when the project will use runtime translations
137 pre_build_hook "$lang"
138
139 npm run ng build -- --prod --configuration="$lang" --output-path "dist/build"
140
141 # If --localize is not used
142 mv "dist/build/$key" "dist/$lang"
143 rmdir "dist/build"
144
145 # If --localize is used
146 # if [ ! "$lang" = "$key" ]; then
147 # mv "dist/$key" "dist/$lang"
148 # fi
149
150 # Do not duplicate assets
151 rm -r "./dist/$lang/assets"
152
153 # TODO: remove when the project will use runtime translations
154 post_build_hook
155 done
156 fi
157
158 cd ../ && npm run build:embed && cd client/
159
160 # Copy runtime locales
161 cp -r "./src/locale" "./dist/locale"