-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions
77 lines (68 loc) · 1.9 KB
/
functions
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
#!/usr/bin/env bash
set -euf -o pipefail
get() {
local config k k_ v v_
config="$(pwd)/.config"
if ! test -f "$config" ; then
echo "$config does not exist" >&2
return 1
fi
while IFS='=' read -r k v ; do
k_="${k% }"
v_="${v# }"
if [[ "$k_" == "$1" ]] ; then
printf '%s' "$v_"
return 0
fi
done <"$config"
case "$1" in
default-branch) printf 'main' ;;
min-branch-coverage) printf '100' ;;
author-name) printf 'Sanctuary' ;;
contributing-file) printf 'CONTRIBUTING.md' ;;
license-file) printf 'LICENSE' ;;
source-files) printf 'index.js' ;;
readme-source-files) printf 'index.js' ;;
test-files) printf 'test/**/*.js' ;;
heading-level) printf '4' ;;
heading-prefix) printf '#' ;;
comment-prefix) printf '.' ;;
opening-delimiter) # shellcheck disable=SC2016
printf '```javascript' ;;
closing-delimiter) # shellcheck disable=SC2016
printf '```' ;;
module-type) printf 'esm' ;;
version-tag-prefix) printf 'v' ;;
*)
echo "'$1' not defined in $config" >&2
return 1
esac
}
exec_path() {
if [[ "$(basename "$0")" == sanctuary-* ]] ; then
printf '%s' "node_modules/.bin/sanctuary-$1"
else
printf '%s' "bin/$1"
fi
}
run() {
"$(exec_path "$1")" "${@:2}"
}
run_custom_script() {
local IFS=: script scripts
test -x "scripts/$1" || return 0
read -r -a scripts <<<"${CUSTOM_SCRIPTS_RUN-}"
# https://stackoverflow.com/a/7577209/312785
for script in "${scripts[@]+"${scripts[@]}"}" ; do
[[ "$script" == "$1" ]] && return 0
done
scripts+=("$1")
CUSTOM_SCRIPTS_RUN="${scripts[*]}" "scripts/$1" "${@:2}"
exit 0
}
pass() {
echo $'\x1B[0;32m\xE2\x9C\x94\x1B[0m' "$@"
}
fail() {
echo $'\x1B[0;31m\xE2\x9C\x98\x1B[0m' "$@"
}