-
-
Notifications
You must be signed in to change notification settings - Fork 125
/
deploy.sh
executable file
·80 lines (61 loc) · 2.41 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
set -e
# We don't need Netlify builds on master. This seems to be the easiest way to achieve this.
# See https://docs.netlify.com/configure-builds/environment-variables/#read-only-variables for the env vars set by Netlify.
if [ "$NETLIFY" = "true" ] && [ "$BRANCH" = "master" ];
then
rm -rf public
mkdir public
echo 'No Netlify deploy previews on master.' > public/index.html
echo 'Skipping deploy preview for master on Netlify.'
exit
fi
mkdir -p i18n
languages=(de en fr pt es hr nl cs)
echo "Fetching data…"
git clone --depth 1 https://github.com/datenanfragen/data data_tmp
echo "Creating directories…"
for lang in ${languages[@]}
do
mkdir -p "content/$lang/company"
mkdir -p "content/$lang/supervisory-authority"
done
mkdir -p static/templates
mkdir -p static/db
mkdir -p static/db/company-packs
mkdir -p static/db/sva
echo "Copying files…"
cp data_tmp/companies/* static/db
cp data_tmp/supervisory-authorities/* static/db/sva
for lang in ${languages[@]}
do
cp data_tmp/companies/* "content/$lang/company"
cp data_tmp/supervisory-authorities/* "content/$lang/supervisory-authority"
done
cp -r data_tmp/templates/* static/templates
mv data_tmp/schema.json data_tmp/schema-supervisory-authorities.json static
yarn tsm scripts/compile-company-packs.ts
yarn tsm scripts/compile-data-dump.ts
rm -rf data_tmp
cd content || exit
# Unfortunately, Hugo only accepts .md files as posts, so we have to rename our JSONs, see https://stackoverflow.com/a/27285610
echo "Renaming JSON files…"
for lang in ${languages[@]}
do
find "$lang/company" -name '*.json' -exec sh -c 'mv "$0" "${0%.json}.md"' {} \;
find "$lang/supervisory-authority" -name '*.json' -exec sh -c 'mv "$0" "${0%.json}.md"' {} \;
done
cd .. || exit
yarn licenses generate-disclaimer --ignore-optional --ignore-platform > static/NOTICES.txt
echo "Running Webpack and Hugo…"
yarn run build
if [ "$CONTEXT" = "production" ]
then
hugo -e production --minify
else
hugo -e staging --baseURL "$DEPLOY_PRIME_URL" --minify
cp _headers public/_headers
fi
# Finds all generated css files, matches and removes the second last non-dot characters (the md5 hash) and renames the files to the new filename without hash
# This is really not a good fix and I beg hugo to change this!
find "public" -regex '.*/styles/.*\.css' -exec sh -c 'echo $0 | sed "s/\(.*\.min\)\.[^\.]*\(\.[^\.]*\)$/\1\2/" | xargs mv $0 ' {} \;