-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.sh
executable file
·119 lines (105 loc) · 2.1 KB
/
dev.sh
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
#!/bin/bash
choices=(
"docker"
"pg"
"air"
"test"
"tmux"
)
run_docker() {
source ./.env
docker build -t nero_backend --label nero_backend .
docker run \
-e XATA_HTTP=$XATA_HTTP \
-e XATA_PG=$XATA_PG \
-e XATA_API_KEY=$XATA_API_KEY \
-e JWT_SECRET=$JWT_SECRET \
-e PORT=$PORT \
-e RUNTIME="DOCKER" \
-p 3000:3000 nero_backend:latest
}
run_air() {
if [ -f ".air.toml" ] && command -v air >/dev/null; then
source ./.env
export XATA_HTTP=$XATA_HTTP
export XATA_PG=$XATA_PG
export XATA_API_KEY=$XATA_API_KEY
export JWT_SECRET=$JWT_SECRET
export PORT=$PORT
air -c .air.toml
else
echo "air.toml not found or air not installed"
fi
}
run_pgcli() {
source .env
pgcli "$XATA_PG"
}
run_tests() {
go test -v ./...
}
run_tmux() {
if tmux has-session -t nero >/dev/null; then
tmux attach-session -t nero
return 0
fi
tmux new-session -d -s nero
tmux send-keys -t nero "nvim" C-m
tmux new-window -S -n build
tmux send-keys -t nero "sh ./dev.sh air" C-m
tmux new-window -S -n test
tmux send-keys -t nero "go test ./..." C-m
tmux select-window -t nero:0
}
use_fzf() {
if command -v fzf >/dev/null; then
return 0
else
return 1
fi
}
use_standard() {
usage=" "
for choice in "${choices[@]}"; do
usage="$usage$choice "
done
echo "usage: ./dev.sh [$usage]"
}
choose() {
if use_fzf; then
choice=$(printf '%s\n' "${choices[@]}" | fzf)
handle_choice "$choice"
else
use_standard
fi
}
handle_choice() {
case $1 in
"docker")
run_docker
;;
"pg")
run_pgcli
;;
"air")
run_air
;;
"test")
run_tests
;;
"tmux")
run_tmux
;;
*)
use_standard
;;
esac
}
# ╭──────────────────────────────────────────────────────────╮
# │ Main │
# ╰──────────────────────────────────────────────────────────╯
if [ $# -eq 0 ]; then
choose
else
handle_choice "$1"
fi