wasp/waspc/run

81 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# This script defines common commands used during building / developing
# and makes it easy to run them.
THIS=$0
COMMAND=${1:-watch}
shift
ARGS="$@"
BOLD="\033[1m"
UNDERLINED="\033[4m"
RESET="\033[0m"
LIGHT_CYAN="\033[96m"
DEFAULT_COLOR="\033[39m"
BUILD_CMD="stack build"
BUILD_ALL_CMD="stack build --bench --no-run-benchmarks --test --no-run-tests"
STAN_CMD="$BUILD_ALL_CMD && stack install stan --stack-yaml=stack-stan.yaml && .bin/stan report $ARGS"
TEST_CMD="$BUILD_CMD --test"
EXEC_CMD="stack exec wasp-cli $ARGS"
GHCID_CMD="ghcid --command=stack ghci"
echo_and_eval () {
echo -e $"${LIGHT_CYAN}Running:${DEFAULT_COLOR}" $1 "\n"
eval $1
}
echo_bold () { echo -e $"${BOLD}${1}${RESET}"; }
print_usage () {
print_usage_cmd () {
echo -e $" ${UNDERLINED}${1}${RESET}"
echo " $2";
}
echo_bold "Usage: ${THIS} <command>"
echo "Commands:"
print_usage_cmd "build" \
"Builds the project."
print_usage_cmd "test" \
"Builds the project and executes tests."
print_usage_cmd "wasp-cli <args>" \
"Builds the project once and runs the wasp executable while forwarding arguments."
print_usage_cmd "stan <args>" \
"Builds the project and runs static code analysis on it, generating stan.html."
print_usage_cmd "ghcid" \
"Runs ghcid, which watches source file changes and reports errors. Does not watch tests."
print_usage_cmd "ghcid-test" \
"Runs ghcid on both source and tests."
}
case $COMMAND in
build)
echo_and_eval "$BUILD_CMD"
;;
ghcid)
echo_and_eval "$GHCID_CMD"
;;
ghcid-test)
# --color always is needed for Tasty to turn on the coloring.
# NOTE: I did not put this into variable because I was not able to put single quotes
# around :main --color always that way and it was not working.
ghcid -T=':main --color always' --command=stack ghci test/TastyDiscoverDriver.hs
;;
test)
echo_and_eval "$TEST_CMD"
;;
wasp-cli)
echo_and_eval "$BUILD_CMD"
echo
echo_and_eval "$EXEC_CMD"
;;
stan)
echo_and_eval "$STAN_CMD"
;;
*)
print_usage
exit 1
esac