-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils
executable file
·146 lines (116 loc) · 2.87 KB
/
utils
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
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
#-------------------#
#----- Helpers -----#
#-------------------#
usage() {
echo "$0 [COMMAND] [ARGS]"
echo " Commands:"
echo " - start/up: boots up the Docker stack"
echo " - stop/down: shuts down the Docker stack"
echo " - dc: alias to docker-compose"
echo " - cmd: runs an arbitrary command in the workspace container"
echo " - cmdr: same as 'cmd', but running as the root user"
echo " - shell: opens a shell into the workspace container, same as 'cmd bash'"
echo " - shellr: same as 'shell', but running as the root user"
echo " - tinker: opens the PHP REPL (PsySH)"
echo " - migrate: runs database migrations"
echo " - seed: runs database seeding"
echo " - artisan: runs a command with artisan"
echo " - yarn: runs a command with yarn"
echo " - composer: runs a command with composer"
echo " - test: runs the PHPUnit tests"
echo " - coverage: runs the PHPUnit tests, with code coverage"
echo " - stan: run PHPStan/Larastan static analysis on the project"
echo " - watch: runs 'yarn run watch' to aid in JS development"
}
fn_exists() {
type $1 2>/dev/null | grep -q 'is a function'
}
COMMAND=$1
shift
ARGUMENTS=${@}
#--------------------#
#----- Commands -----#
#--------------------#
dc() {
docker-compose "${@}"
}
start() {
dc up -d
}
up() {
start
}
stop() {
dc down
}
down() {
stop
}
cmd() {
dc exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" --user laravel workspace "${@}"
}
cmdr() {
dc exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" workspace "${@}"
}
shell() {
cmd bash
}
shellr() {
cmdr bash
}
artisan() {
cmd php artisan "${@}"
}
tinker() {
artisan tinker
}
migrate() {
artisan migrate
}
seed() {
artisan db:seed "${@}"
}
yarn() {
cmd bash -l -c "yarn ${*}"
}
watch() {
cmd bash -l -c "yarn run watch"
}
composer() {
cmd bash -l -c "composer ${*}"
}
test() {
cmd vendor/bin/phpunit "${@}"
}
coverage() {
cmd vendor/bin/phpunit --coverage-html=coverage "${@}"
}
stan() {
artisan code:analyse --level=max --paths="app,domain"
}
gethostip() {
cmd /sbin/ip route | awk '/default/ { print $3 }'
}
migratesafe() {
c=0
while ! `dc exec db sh -c 'export MYSQL_PWD=$MYSQL_ROOT_PASSWORD; exec mysql -uroot -e"quit"' >/dev/null 2>&1` >/dev/null 2>&1
do
echo "MySQL is not ready, waiting $(expr 30 - $c) more seconds..."
((c++)) && ((c==30)) && { echo "Timed out."; exit 1; }
sleep 1
done
migrate
}
#---------------------#
#----- Execution -----#
#---------------------#
fn_exists $COMMAND
if [ $? -eq 0 ]; then
# cd into the script's current directory so docker-compose reference the right dir
cd "${0%/*}"
# Execute
$COMMAND $ARGUMENTS
else
usage
fi