-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
run
executable file
·134 lines (119 loc) · 4.33 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/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"
GREEN="\033[32m"
RED="\033[31m"
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"
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')"
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 "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."
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
}
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"
;;
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
;;
*)
print_usage
exit 1
esac