4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-11 09:45:52 +00:00
qortal-ui/build.sh
2021-12-25 14:39:47 +01:00

107 lines
2.4 KiB
Bash

#!/usr/bin/env bash
declare -a YARN_PACKAGE_DEPS=("qortal-ui-core" "qortal-ui-plugins" "qortal-ui-crypto")
YARN_LINK_DIR="${HOME}/.config/yarn/link"
SHOW_HELP=0
FORCE_LINK=0
YARN_WATCH=0
RUN_SERVER=0
RUN_ELECTRON=0
while [ -n "$*" ]; do
case $1 in
-h)
# Show help
SHOW_HELP=1
;;
-f)
# Force relink and reinstall dependencies
FORCE_LINK=1
;;
-w)
# Use "yarn watch" instead of "yarn build", to enable hot swapping
YARN_WATCH=1
;;
-s)
# Run server after building
RUN_SERVER=1
;;
-e)
# Run electron after building
RUN_ELECTRON=1
;;
esac
shift
done
if [ "${SHOW_HELP}" -eq 1 ]; then
echo
echo "Usage:"
echo "build.sh [-h] [-f] [-s] [-e]"
echo
echo "-h: show help"
echo "-f: force relink and reinstall dependencies"
echo "-w: use 'yarn watch' instead of 'yarn build', to enable hot swapping"
echo "-s: run UI server after completing the build"
echo "-e: run electron server after completing the build"
echo
exit
fi
echo "Checking dependencies..."
for PACKAGE in "${YARN_PACKAGE_DEPS[@]}"; do
if [ "${FORCE_LINK}" -eq 1 ]; then
echo "Unlinking ${PACKAGE}..."
yarn --cwd "${PACKAGE}" unlink "${PACKAGE}"
yarn --cwd "${PACKAGE}" unlink
fi
if [ ! -d "${YARN_LINK_DIR}/${PACKAGE}" ]; then
echo "Installing and linking ${PACKAGE}..."
yarn --cwd "${PACKAGE}" install
yarn --cwd "${PACKAGE}" link
yarn --cwd qortal-ui link "${PACKAGE}"
else
echo "${PACKAGE} is already linked."
fi
done
WATCH_PID=$(cat "watch.pid" || echo "")
if [ ! -z "${WATCH_PID}" ]; then
echo "Stopping existing watch process..."
kill "${WATCH_PID}"
rm -f "watch.pid"
fi
if [ "${YARN_WATCH}" -eq 1 ]; then
echo "Building qortal-ui in watch mode..."
yarn --cwd qortal-ui run watch &
echo "$!" > "watch.pid";
else
yarn --cwd qortal-ui run build
fi
if [ "${RUN_SERVER}" -eq 1 ]; then
echo "Running UI server..."
trap : INT
yarn --cwd qortal-ui run server
elif [ "${RUN_ELECTRON}" -eq 1 ]; then
echo "Starting electron..."
trap : INT
yarn --cwd qortal-ui run start-electron
fi
WATCH_PID=$(cat "watch.pid" || echo "")
if [ ! -z "${WATCH_PID}" ]; then
echo "Stopping watch process..."
kill "${WATCH_PID}"
rm -f "watch.pid"
fi
# Catch-all to kill any remaining processes
pkill -P $$