-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdev
149 lines (120 loc) · 3.4 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
unset DEKICK_PATH
unset PROJECT_ROOT
DEKICKRC_FILE=".dekickrc.yml"
if [ -n "$ZSH_VERSION" ]; then
SHELL=zsh
elif [ -n "$BASH_VERSION" ]; then
SHELL=bash
fi
function realpath() {
local previouspwd=$PWD
cd "$(dirname "$1")" || exit 1
local link
link=$(readlink "$(basename "$1")")
while [ "$link" ]; do
cd "$(dirname "$link")" || exit 1
link=$(readlink "$(basename "$1")")
done
local realpath
realpath="$PWD/$(basename "$1")"
cd "$previouspwd" || exit 1
echo "$realpath"
}
function show_banner() {
if tty > /dev/null 2>&1; then
local dekick_version
dekick_version=$(cat "${DEKICK_PATH}/.version")
echo
echo ' ______ _______ _ _________ _______ _ ';
echo '( __ \ ( ____ \| \ /\\__ ___/( ____ \| \ /\\';
echo '| ( \ )| ( \/| \ / / ) ( | ( \/| \ / /';
echo '| | ) || (__ | (_/ / | | | | | (_/ / ';
echo '| | ) || ( | ( \ \ | | | | | ( \ \ ';
echo '| (__/ )| (____/\| / \ \___) (___| (____/\| / \ \';
echo '(______/ (_______/|_/ \/\_______/(_______/|_/ \/';
echo ' ';
echo "${dekick_version} installed!"
echo
if [ "$PROJECT_ROOT" ]; then
echo "Project path: ${PROJECT_ROOT}"
fi
echo "DeKick path: ${DEKICK_PATH}"
echo
echo "See help by running 'dekick --help'. Happy coding!"
fi
}
function check_dekickrc() {
if [[ ! -t 1 ]]; then
return 0
fi
if [ "${PROJECT_ROOT}" = "${DEKICK_PATH}" ]; then
return 0
fi
if [[ -t 1 ]] && [ ! -f "${PROJECT_ROOT}/${DEKICKRC_FILE}" ]; then
echo -e "\n\033[33mWarning:\033[0m No ${DEKICKRC_FILE} file found in current directory."
echo -ne "\nDo you want to start project creator in the current directory? (Y/n) "
read -r answer
if [ "$answer" = "${answer#[nN]}" ]; then
dekick creator
fi
return 0
fi
}
function check_test_mode() {
if [[ ! -t 1 ]]; then
return 0
fi
if [ "$PROJECT_ROOT" != "$DEKICK_PATH" ]; then
return 0
fi
local dekick_version
dekick_version=$(cat "${DEKICK_PATH}/.version")
echo -e "\n\033[38;5;231;48;5;196m${dekick_version} in test mode installed\033[0m"
echo -ne "\nDo you want to start tests using PyTest? (Y/n) "
read -r answer
if [ "$answer" = "${answer#[nN]}" ]; then
HOST_PLATFORM=$(uname -s)
PYTEST_ARGS=""
if [ "${HOST_PLATFORM}" = "Linux" ]; then
PYTEST_ARGS="-n6"
fi
dekick pytest ${PYTEST_ARGS}
fi
return 0
}
function dekick() {
local PREV_PWD=$PWD
cd "$PROJECT_ROOT" || exit 1
"${DEKICK_PATH}/dekick-docker.sh" "$@"
local EC=$?
cd "$PREV_PWD" || exit 1
return $EC
}
function dck() {
dekick "$@"
}
# Checking if Docker daemon is running and there are proper rights to access it
if ! docker ps >/dev/null 2>&1; then
echo "Docker daemon is not running or you don't have rights to access it."
echo "DeKick will not work properly without Docker!"
fi
if [ -z "$DEKICK_PATH" ]; then
if [ "$SHELL" = "zsh" ]; then
SOURCE=${(%):-%N}
elif [ "$SHELL" = "bash" ]; then
SOURCE=${BASH_SOURCE[0]}
fi
if [ "$SOURCE" = "dev" ]; then
DEKICK_PATH=$(realpath "$(pwd)")
else
DEKICK_PATH=$(realpath "$(dirname "${SOURCE}")")
fi
fi
if [ -z "$PROJECT_ROOT" ]; then
PROJECT_ROOT=$(realpath "$(pwd)")
fi
export DEKICK_PATH PROJECT_ROOT
show_banner
check_dekickrc
check_test_mode