-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev
executable file
·134 lines (119 loc) · 2.83 KB
/
dev
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
#!/usr/bin/env bash
set -euo pipefail
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "${script_dir}/.dev/common"
commands_dir="${script_dir}/.dev/commands/*"
for c in ${commands_dir}; do
if [ ! -f "${c}" ]; then
continue
fi
# shellcheck disable=SC1090
source "${c}"
done
mutagen_enabled=0
function detect_mutagen_support {
command -v mutagen >/dev/null 2>&1 \
&& command -v mutagen-compose >/dev/null 2>&1 \
&& mutagen_enabled=1
}
use_mutagen=${USE_MUTAGEN:-0}
function print_usage {
echo "Usage: ./dev [command] [args]"
}
function show_help {
cat << EOF
The following commands are supported:
./dev create # Create a new project
./dev start # Start the development stack
./dev stop # Stop the development stack
./dev rebuild # Rebuild the images and restart the development stack
./dev clean # Reset the stack (including volumes and images)
./dev execute # Run arbitrary command in a container
./dev mix # Run mix commands in the app container
./dev npm # Run npm commands in the assets container
To get information about a single command use ./dev [command] --help
EOF
}
function maybe_show_command_help {
if [ "${1}" == "--help" ]; then
return
fi
local args=${2:-noop}
if [ "${args}" != "--help" ]; then
return
fi
case ${command} in
"create")
print_help_for_create
;;
"start"|"s")
print_help_for_start
;;
"stop"|"st")
print_help_for_stop
;;
"rebuild"|"rb")
print_help_for_rebuild
;;
"clean"|"cl")
print_help_for_clean
;;
"execute"|"e")
print_help_for_execute
;;
"mix"|"m")
print_help_for_mix
;;
"npm"|"n")
print_help_for_npm
;;
*) echo "No help found for '${command}'"
esac
exit 0
}
function main {
docker_compose="docker compose"
detect_mutagen_support
if [[ "${mutagen_enabled}" == "1" ]] && [[ "${use_mutagen}" == "1" ]]; then
# shellcheck disable=SC2034
docker_compose="mutagen-compose"
fi
local command="${1:-help}"
local args="${*:2}"
maybe_show_command_help "${command}" "${args}"
case ${command} in
"--help")
show_help
;;
"create")
# shellcheck disable=SC2086
run_create ${args}
;;
"start"|"s")
run_start
;;
"stop"|"st")
run_stop
;;
"rebuild"|"rb")
run_rebuild
;;
"clean"|"cl")
run_clean
;;
"execute"|"e")
# shellcheck disable=SC2086
run_execute ${args}
;;
"mix"|"m")
# shellcheck disable=SC2086
run_mix ${args}
;;
"npm"|"n")
# shellcheck disable=SC2086
run_npm ${args}
;;
*) print_usage; echo; show_help
esac
}
main "$@"