-
Notifications
You must be signed in to change notification settings - Fork 42
/
build-frontend.sh
executable file
·79 lines (67 loc) · 2.07 KB
/
build-frontend.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
#!/usr/bin/env bash
set -euo pipefail
TOPLEVEL="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Verify that we have the configuration
test -e frontend/.env || {
echo "ERROR: Building the frontend requires a config file."
echo " Please create the config file by running config.sh."
exit 1
} >&2
###################
# frontend # (output: frontend/public/)
###################
(cd "$TOPLEVEL/frontend" && npm ci && npm run build --node-options="--max-old-space-size=4096")
#################
# assets.tar.xz #
#################
# we need GNU tar (see below) so we check early
if tar --help | grep GNU >/dev/null; then
echo "found GNU tar as tar"
tar="tar"
elif command -v gtar >/dev/null; then
echo "found GNU tar as gtar"
tar="gtar"
else
echo "did not find GNU tar, please install"
echo " brew install gnu-tar"
exit 1
fi
if ! command -v xz >/dev/null; then
echo "did not find xz, please install"
echo " brew install xz"
exit 1
fi
# We use a local directory, and we don't delete it after the build, so that
# assets can be inspected.
tarball_dir="$TOPLEVEL/web-assets"
rm -rf "$tarball_dir"
echo "using $tarball_dir for tarball directory"
cp -R "$TOPLEVEL/frontend/public/" "$tarball_dir/"
# Bundle into a tight tarball
# On macOS you need to install gtar + xz
# brew install gnu-tar
# brew install xz
cd "$tarball_dir"
# Archive and remove sourcemap files.
find . -name '*.map' | "$tar" cJv \
--files-from=- \
--remove-files \
-f "$TOPLEVEL/sourcemaps.tar.xz"
# shellcheck disable=SC2038 # We have sane filenames, without return characters in them.
find . -type f | xargs -I{} gzip -fn "{}"
# --mtime, --sort, --owner, --group, --numeric-owner and --format are all
# there to get a tarball that's reproducible across different platforms.
# See https://reproducible-builds.org/docs/archives/
"$tar" cJv \
--mtime='2021-05-07 17:00Z' \
--sort=name \
--owner=0 \
--group=0 \
--numeric-owner \
--format=gnu \
--exclude .last_build_id \
-f "$TOPLEVEL/assets.tar.xz" \
.
cd "$TOPLEVEL"
ls -sh "$TOPLEVEL/assets.tar.xz"
sha256sum "$TOPLEVEL/assets.tar.xz"