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