Skip to content

Commit 72b57ea

Browse files
committed
chore: add just command launcher
1 parent 9218194 commit 72b57ea

2 files changed

Lines changed: 390 additions & 35 deletions

File tree

Justfile

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
set dotenv-load
2+
set dotenv-filename := ".env"
3+
set windows-shell := ["sh", "-cu"]
4+
5+
default:
6+
@just list
7+
8+
list:
9+
@printf "%s\n" \
10+
"run [release] [logs]" \
11+
"clean [build|derived-data|spm|all]..."
12+
13+
run mode="" logs="":
14+
#!/usr/bin/env sh
15+
set -eu
16+
17+
mode="{{ mode }}"
18+
logs="{{ logs }}"
19+
configuration="Debug"
20+
attach_logs=false
21+
22+
if [ "$mode" = "logs" ]; then
23+
attach_logs=true
24+
mode=""
25+
fi
26+
if [ -n "$logs" ]; then
27+
if [ "$logs" != "logs" ]; then
28+
echo "usage: just run [release] [logs]" >&2
29+
exit 1
30+
fi
31+
attach_logs=true
32+
fi
33+
if [ -n "$mode" ]; then
34+
if [ "$mode" != "release" ]; then
35+
echo "usage: just run [release] [logs]" >&2
36+
exit 1
37+
fi
38+
configuration="Release"
39+
fi
40+
41+
if [ "$configuration" = "Release" ]; then
42+
echo "Running Release configuration (mainnet)."
43+
fi
44+
45+
if [ "$attach_logs" = "true" ]; then
46+
BITKIT_CONFIGURATION="$configuration" BITKIT_ATTACH_LOGS=1 ./run.sh
47+
else
48+
BITKIT_CONFIGURATION="$configuration" BITKIT_ATTACH_LOGS=0 ./run.sh
49+
fi
50+
51+
clean *targets:
52+
#!/usr/bin/env sh
53+
set -eu
54+
55+
set -- {{ targets }}
56+
if [ "$#" -eq 0 ]; then
57+
set -- build
58+
fi
59+
60+
clean_build=false
61+
clean_derived_data=false
62+
clean_spm=false
63+
64+
for target in "$@"; do
65+
case "$target" in
66+
build)
67+
clean_build=true
68+
;;
69+
derived-data | derived)
70+
clean_derived_data=true
71+
;;
72+
spm | swiftpm)
73+
clean_spm=true
74+
;;
75+
all)
76+
clean_build=true
77+
clean_derived_data=true
78+
clean_spm=true
79+
;;
80+
*)
81+
echo "usage: just clean [build|derived-data|spm|all]..." >&2
82+
exit 1
83+
;;
84+
esac
85+
done
86+
87+
remove_path() {
88+
path="$1"
89+
90+
case "$path" in
91+
"" | "/" | "$HOME" | "$HOME/")
92+
echo "Refusing to remove unsafe path: $path" >&2
93+
exit 1
94+
;;
95+
esac
96+
97+
if [ -e "$path" ] || [ -L "$path" ]; then
98+
echo "Removing $path"
99+
rm -rf "$path"
100+
fi
101+
}
102+
103+
if [ "$clean_build" = "true" ]; then
104+
remove_path "${BITKIT_DERIVED_DATA_PATH:-build}"
105+
fi
106+
107+
if [ "$clean_derived_data" = "true" ]; then
108+
xcode_derived_data_root="${BITKIT_XCODE_DERIVED_DATA_ROOT:-$HOME/Library/Developer/Xcode/DerivedData}"
109+
for path in "$xcode_derived_data_root"/Bitkit-*; do
110+
remove_path "$path"
111+
done
112+
fi
113+
114+
if [ "$clean_spm" = "true" ]; then
115+
if command -v swift >/dev/null 2>&1; then
116+
if [ -n "${BITKIT_SWIFTPM_CACHE_PATH:-}" ]; then
117+
mkdir -p "$BITKIT_SWIFTPM_CACHE_PATH"
118+
swift package --cache-path "$BITKIT_SWIFTPM_CACHE_PATH" purge-cache
119+
else
120+
swift package purge-cache
121+
fi
122+
fi
123+
124+
remove_path "${BITKIT_DERIVED_DATA_PATH:-build}/SourcePackages"
125+
xcode_derived_data_root="${BITKIT_XCODE_DERIVED_DATA_ROOT:-$HOME/Library/Developer/Xcode/DerivedData}"
126+
for path in "$xcode_derived_data_root"/Bitkit-*/SourcePackages; do
127+
remove_path "$path"
128+
done
129+
remove_path "${BITKIT_SWIFTPM_CACHE_PATH:-$HOME/Library/Caches/org.swift.swiftpm}"
130+
remove_path "$HOME/.swiftpm/cache"
131+
remove_path "$HOME/.swiftpm/repositories"
132+
fi

0 commit comments

Comments
 (0)