2019-05-05 14:08:16 +03:00
|
|
|
#!/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="$@"
|
|
|
|
|
2020-09-22 14:52:16 +03:00
|
|
|
BOLD="\033[1m"
|
|
|
|
UNDERLINED="\033[4m"
|
|
|
|
RESET="\033[0m"
|
|
|
|
LIGHT_CYAN="\033[96m"
|
2021-11-16 22:42:49 +03:00
|
|
|
GREEN="\033[32m"
|
|
|
|
RED="\033[31m"
|
2020-09-22 14:52:16 +03:00
|
|
|
DEFAULT_COLOR="\033[39m"
|
2019-05-05 14:08:16 +03:00
|
|
|
|
2019-05-05 22:46:06 +03:00
|
|
|
BUILD_CMD="stack build"
|
2021-11-16 22:43:55 +03:00
|
|
|
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"
|
2021-11-16 22:42:49 +03:00
|
|
|
HLINT_CMD="stack install hlint --stack-yaml=stack-hlint.yaml && .bin/hlint . $ARGS"
|
|
|
|
ORMOLU_INSTALL_CMD="stack install ormolu --stack-yaml=stack-ormolu.yaml"
|
|
|
|
ORMOLU_BASE_CMD="$ORMOLU_INSTALL_CMD && .bin/ormolu --color always --check-idempotence"
|
|
|
|
ORMOLU_CHECK_CMD="$ORMOLU_BASE_CMD --mode check "'$'"(git ls-files '*.hs' '*.hs-boot')"
|
|
|
|
ORMOLU_FORMAT_CMD="$ORMOLU_BASE_CMD --mode inplace "'$'"(git ls-files '*.hs' '*.hs-boot')"
|
2019-05-05 14:08:16 +03:00
|
|
|
TEST_CMD="$BUILD_CMD --test"
|
2021-11-11 21:37:56 +03:00
|
|
|
EXEC_CMD="stack exec wasp-cli $ARGS"
|
2019-12-17 23:40:05 +03:00
|
|
|
GHCID_CMD="ghcid --command=stack ghci"
|
2019-05-05 14:08:16 +03:00
|
|
|
|
|
|
|
echo_and_eval () {
|
|
|
|
echo -e $"${LIGHT_CYAN}Running:${DEFAULT_COLOR}" $1 "\n"
|
2021-11-16 22:43:55 +03:00
|
|
|
eval $1
|
2019-05-05 14:08:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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."
|
2021-11-11 21:37:56 +03:00
|
|
|
print_usage_cmd "wasp-cli <args>" \
|
2020-09-22 14:52:16 +03:00
|
|
|
"Builds the project once and runs the wasp executable while forwarding arguments."
|
2019-12-17 23:40:05 +03:00
|
|
|
print_usage_cmd "ghcid" \
|
2020-09-22 14:52:16 +03:00
|
|
|
"Runs ghcid, which watches source file changes and reports errors. Does not watch tests."
|
2020-01-28 21:41:14 +03:00
|
|
|
print_usage_cmd "ghcid-test" \
|
2020-09-22 14:52:16 +03:00
|
|
|
"Runs ghcid on both source and tests."
|
2021-11-16 22:42:49 +03:00
|
|
|
print_usage_cmd "code-check" \
|
|
|
|
"Checks code by running it through formatter, linter and static analysis."
|
|
|
|
print_usage_cmd "stan <args>" \
|
|
|
|
"Builds the project and runs static code analysis on it, generating stan.html."
|
|
|
|
print_usage_cmd "hlint <args>" \
|
|
|
|
"Runs linter on the codebase."
|
|
|
|
print_usage_cmd "ormolu:check" \
|
|
|
|
"Runs the code formatter and reports if code is correctly formatted or not."
|
|
|
|
print_usage_cmd "ormolu:format" \
|
|
|
|
"Runs the code formatter and formats the code in place."
|
|
|
|
}
|
|
|
|
|
|
|
|
exitStatusToString () {
|
|
|
|
if (( $1 == 0 )); then echo "${GREEN}OK${RESET}"; else echo "${RED}FAIL${RESET}"; fi
|
2019-05-05 14:08:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case $COMMAND in
|
|
|
|
build)
|
|
|
|
echo_and_eval "$BUILD_CMD"
|
|
|
|
;;
|
2019-12-17 23:40:05 +03:00
|
|
|
ghcid)
|
|
|
|
echo_and_eval "$GHCID_CMD"
|
|
|
|
;;
|
2020-01-28 21:41:14 +03:00
|
|
|
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
|
|
|
|
;;
|
2019-05-05 14:08:16 +03:00
|
|
|
test)
|
|
|
|
echo_and_eval "$TEST_CMD"
|
|
|
|
;;
|
2021-11-16 22:43:55 +03:00
|
|
|
wasp-cli)
|
2019-05-05 14:08:16 +03:00
|
|
|
echo_and_eval "$BUILD_CMD"
|
|
|
|
echo
|
|
|
|
echo_and_eval "$EXEC_CMD"
|
|
|
|
;;
|
2021-11-16 22:43:55 +03:00
|
|
|
stan)
|
|
|
|
echo_and_eval "$STAN_CMD"
|
|
|
|
;;
|
2021-11-16 22:42:49 +03:00
|
|
|
hlint)
|
|
|
|
echo_and_eval "$HLINT_CMD"
|
|
|
|
;;
|
|
|
|
ormolu:check)
|
|
|
|
echo_and_eval "$ORMOLU_CHECK_CMD"
|
|
|
|
;;
|
|
|
|
ormolu:format)
|
|
|
|
echo_and_eval "$ORMOLU_FORMAT_CMD"
|
|
|
|
;;
|
|
|
|
code-check)
|
|
|
|
echo_and_eval "$ORMOLU_CHECK_CMD"
|
|
|
|
ORMOLU_RESULT=$?
|
|
|
|
|
|
|
|
echo_and_eval "$HLINT_CMD"
|
|
|
|
HLINT_RESULT=$?
|
|
|
|
|
|
|
|
echo_and_eval "$STAN_CMD"
|
|
|
|
STAN_RESULT=$?
|
|
|
|
|
|
|
|
TOTAL_RESULT=$(($ORMOLU_RESULT || $HLINT_RESULT || $STAN_RESULT))
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo
|
|
|
|
echo "======================================"
|
|
|
|
echo " SUMMARY"
|
|
|
|
echo "======================================"
|
|
|
|
echo
|
|
|
|
echo -e "Formatter (ormolu): $(exitStatusToString $ORMOLU_RESULT)"
|
|
|
|
echo -e "Linter (hlint): $(exitStatusToString $HLINT_RESULT)"
|
|
|
|
echo -e "Static analysis (stan): $(exitStatusToString $STAN_RESULT)"
|
|
|
|
echo "-----------------------"
|
|
|
|
echo -e "All together: $(exitStatusToString $TOTAL_RESULT)"
|
|
|
|
|
|
|
|
exit $TOTAL_RESULT
|
|
|
|
;;
|
2019-05-05 14:08:16 +03:00
|
|
|
*)
|
|
|
|
print_usage
|
|
|
|
exit 1
|
|
|
|
esac
|