lila/ui/build

66 lines
1.5 KiB
Bash
Executable File

#!/bin/bash -ea
target=${1-dev}
mode=${2-build} # build | upgrade | css | js
echo "building ui modules with target=$target and mode=$mode"
echo "node: $(node --version)"
echo "yarn: $(yarn --version)"
cd "$(git rev-parse --show-toplevel)"
mkdir -p public/compiled
ts_apps1="common chess"
ts_apps2="ceval game tree chat nvui"
apps="site chat cli challenge notify learn insight editor puzzle round analyse lobby tournament tournamentSchedule tournamentCalendar simul dasher speech palantir serviceWorker"
if [ $mode == "upgrade" ]; then
yarn upgrade --non-interactive
else
yarn install --non-interactive
fi
build_ts() {
echo "build_ts" "$@"
set -ev
cd ui/$1
yarn run compile
}
build() {
echo "build" "$@"
set -ev
if [[ $1 == "css" ]]; then
cd ui
gulp "css-$target"
else
cd ui/$1
gulp $target
fi
}
if [ $mode != "upgrade" ] && [ $mode != "js" ]; then
apps="css $apps"
fi
if [ $mode == "css" ]; then
(build css)
else
if type -p parallel; then # parallel execution!
if [ -z "$P_OPTS" -a ! -e ~/.parallel/config ]; then
P_OPTS="-j+4 --halt 2"
[ "$TRAVIS" = "true" ] || P_OPTS+=" --bar"
fi
set -x
parallel --gnu $P_OPTS build_ts ::: $ts_apps1
parallel --gnu $P_OPTS build_ts ::: $ts_apps2
parallel --gnu $P_OPTS build ::: $apps
else # sequential execution
echo "For faster builds, install GNU parallel."
for app in $ts_apps1 $ts_apps2; do (build_ts $app); done
for app in $apps; do (build $app); done
fi
fi