• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2set -eux
3
4SRCDIR=$(readlink --canonicalize $(dirname $0))
5DSTDIR=$(mktemp --directory --tmpdir $(basename $0).XXXXXXXXXX)
6
7BAZEL=/tmp/bazel
8BAZELISK_RELEASE=v1.17.0
9
10if [[ ${UID} -ne 0 ]]; then
11  if [[ -d deploy ]]; then
12    echo -e '\033[1;31m' "** The ${PWD}/deploy directory exists! Refusing to clobber it! **" '\033[0m'
13    exit 1
14  fi
15  mkdir deploy
16  sudo docker run -i -t --pull always --rm -v ${SRCDIR}/..:/src -v ${PWD}:/dst emscripten/emsdk /src/app/$(basename $0)
17  ls -l deploy
18else
19  wget -O ${BAZEL} https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_RELEASE}/bazelisk-linux-amd64
20  chmod +x ${BAZEL}
21
22  cd ${SRCDIR}
23  # Emscripten doesn't support `-fstack-protector`.
24  AR=emar CC=emcc \
25    ${BAZEL} build --compilation_mode=opt \
26    --copt=-fno-stack-protector \
27    -- :all
28  cp ../bazel-bin/app/_re2.js ${DSTDIR}
29  # Clean up the sundry Bazel output directories.
30  ${BAZEL} clean --expunge
31  cp app.ts index.html _re2.d.ts ${DSTDIR}
32  cp package.json rollup.config.js tsconfig.json ${DSTDIR}
33
34  cd ${DSTDIR}
35  npm install
36  npx tsc
37  npx rollup -c rollup.config.js -d deploy
38  mv deploy/* /dst/deploy
39fi
40
41cd ${SRCDIR}
42rm -rf ${DSTDIR}
43
44exit 0
45