-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsdk
More file actions
executable file
·148 lines (139 loc) · 3.83 KB
/
sdk
File metadata and controls
executable file
·148 lines (139 loc) · 3.83 KB
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
147
148
#!/usr/bin/env bash
# function to wrap text in green
function wrap_in_green() {
echo -e "\e[32m$1\e[0m"
}
# function to wrap text in yellow
function wrap_in_yellow() {
echo -e "\e[33m$1\e[0m"
}
# function to print a command/option with its description
function print_command() {
printf " %-35s %s\n" "$(wrap_in_yellow "$1")" "$2"
}
# function to print an example with its description
function print_example() {
printf " %-40s %s\n" "$(wrap_in_yellow "$1")" "$2"
}
# function to display usage
function show_usage() {
wrap_in_green "==================================="
wrap_in_green " Transfer Object (Docker SDK) "
wrap_in_green "==================================="
echo -n "Usage: "
wrap_in_yellow "$0 [-x] [-p] <command> [args]"
echo
echo "Options:"
print_command "-x" "Enable Xdebug (debug, coverage)"
print_command "-p" "Enable Xdebug (profiler)"
echo
echo "Commands:"
print_command "install" "Install development environment"
print_command "build" "Build Docker containers"
print_command "start" "Start Docker containers (honors -x / -p)"
print_command "stop" "Stop Docker containers"
print_command "cli [script]" "Open container shell or execute PHP script"
print_command "composer <cmd>" "Run composer command"
print_command "phpstan" "Run PHPStan"
print_command "phpunit [filter]" "Run PHPUnit tests"
print_command "phpunit-group <g>" "Run PHPUnit tests by group"
print_command "phpcs" "Run PHP CodeSniffer"
print_command "phpcbf" "Run PHP Code Beautifier and Fixer"
print_command "hook-install" "Install CaptainHook"
print_command "hook <cmd>" "Run CaptainHook command"
print_command "to-generate [c]" "Generate transfer objects"
print_command "to-generate-bulk [b]" "Generate bulk transfer objects"
print_command "df-generate" "Generate definitions"
echo
echo "Examples:"
print_example "$0 -x start" "Start containers (Xdebug: debug, coverage)"
print_example "$0 -p start" "Start containers (Xdebug: profiler)"
print_example "$0 composer install" "Run composer install inside container"
}
# vars
DOCKER_CONTAINER_NAME=transfer-object-php
DOCKER_EXEC="docker exec -it ${DOCKER_CONTAINER_NAME}"
# options
XDEBUG_MODE=''
while getopts ":xp" opt; do
case ${opt} in
x )
XDEBUG_MODE="debug,coverage"
;;
p )
XDEBUG_MODE="profile"
;;
\? )
show_usage
exit 1
;;
esac
done
shift $((OPTIND -1))
# arguments
case $1 in
install)
$0 build && $0 start && $0 composer install
;;
build)
USER_ID=$(id -u) GROUP_ID=$(id -g) docker compose build
;;
start)
if [ "$XDEBUG_MODE" == "" ]; then
docker compose up -d --remove-orphans
else
XDEBUG_MODE={$XDEBUG_MODE} docker compose up -d --remove-orphans
fi
;;
stop)
docker compose stop
;;
cli)
if [ -z "$2" ]; then
$DOCKER_EXEC bash
else
$DOCKER_EXEC php "${@:2}"
fi
;;
composer)
$DOCKER_EXEC composer "${@:2}"
;;
phpstan)
$DOCKER_EXEC composer phpstan
;;
phpunit)
if [ -n "$2" ]; then
$DOCKER_EXEC composer phpunit -- --filter "$2"
else
$DOCKER_EXEC composer phpunit
fi
;;
phpunit-group)
$DOCKER_EXEC composer phpunit-group "$2"
;;
phpcs)
$DOCKER_EXEC composer phpcs
;;
phpcbf)
$DOCKER_EXEC composer phpcbf
;;
hook-install)
$DOCKER_EXEC composer captainhook install --only-enabled --run-mode=docker --run-exec="docker exec -i $DOCKER_CONTAINER_NAME"
;;
hook)
$DOCKER_EXEC composer captainhook "${@:2}"
;;
to-generate)
$DOCKER_EXEC composer transfer-generate -- -c "${2:-./config/generator.config.yml}" -v
;;
to-generate-bulk)
$DOCKER_EXEC composer transfer-generate-bulk -- -b "${2:-./var/config/config.list.txt}"
;;
df-generate)
$DOCKER_EXEC composer definition-generate
;;
*)
show_usage
exit 0
;;
esac