From cdbae9f39ef4519ab1b2f044298c0b54b6c64833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 15 Jun 2018 16:03:26 +0200 Subject: [PATCH] Refactor frontend stuff to libhack/frontend.sh --- hack/libhack/frontend.sh | 14 ++++++++++++++ hack/tfw.sh | 17 +++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 hack/libhack/frontend.sh diff --git a/hack/libhack/frontend.sh b/hack/libhack/frontend.sh new file mode 100644 index 0000000..64bfee5 --- /dev/null +++ b/hack/libhack/frontend.sh @@ -0,0 +1,14 @@ +# Requires context: +# - FRONTEND_PATH: absolute path of frontend repo +# - CHALLENGE_PATH: absolute path of challenge repo + + +frontend::run() { + local frontend_in_challenge="${CHALLENGE_PATH}/solvable/frontend" + if [[ "$(find "${frontend_in_challenge}" | wc -l)" -gt 2 ]];then + cd "${frontend_in_challenge}" + else + cd "${FRONTEND_PATH}" + fi + yarn start +} diff --git a/hack/tfw.sh b/hack/tfw.sh index 9ebd188..db2fd26 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -18,23 +18,13 @@ FRONTEND_PATH="${TFW_PATH}/${FRONTEND_REPO}" source "${SCRIPT_DIR}/libhack/baseimage.sh" source "${SCRIPT_DIR}/libhack/challenge.sh" +source "${SCRIPT_DIR}/libhack/frontend.sh" -run_frontend() { - FRONTEND_IN_CHALLENGE="${CHALLENGE_PATH}/solvable/frontend" - if [ "$(find "$FRONTEND_IN_CHALLENGE" | wc -l)" -gt 2 ] - then - cd $FRONTEND_IN_CHALLENGE - else - cd $FRONTEND_PATH - fi - yarn start -} - start_challenge_and_frontend() { trap 'exit' INT TERM trap 'kill 0' EXIT - [[ "${RUN_FRONTEND:-1}" == "1" ]] && run_frontend & + [[ "${RUN_FRONTEND:-1}" == "1" ]] && frontend::run & [[ "${BUILD:-1}" == "1" ]] && challenge::build challenge::run $@ wait @@ -55,6 +45,9 @@ case ${1:-} in runcontainer) BUILD=0 RUN_FRONTEND=0 start_challenge_and_frontend ${@:2} ;; + runfrontend) + frontend::run + ;; buildtfw) baseimage::build_if_exists ;;