This repository has been archived by the owner on May 8, 2021. It is now read-only.
generated from alpas/starter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
alpas
executable file
·171 lines (148 loc) · 4.37 KB
/
alpas
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env bash
APP_NAME="short_urls_service"
cecholn() {
RED="\033[0;31m"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
NC='\033[0m' # No Color
printf "${!1}${2} ${NC}\n"
}
cecho() {
RED="\033[0;31m"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
NC='\033[0m' # No Color
printf "${!1}${2} ${NC}"
}
install() {
cecholn "BLUE" "Building $APP_NAME..."
if ./gradlew "$@" installdist; then
cecholn "GREEN" "🙌 Done!"
else
cecholn "RED" "😿 Failed!"
fi
}
build() {
cecholn "BLUE" "Building $APP_NAME..."
if ./gradlew build -q >/dev/null 2>&1; then
cecholn "GREEN" "🙌 Done!"
else
cecholn "RED" "😿 Failed!"
fi
}
buildJar() {
cecholn "BLUE" "Building $APP_NAME jar..."
if ./gradlew shadowJar >/dev/null 2>&1; then
cecholn "GREEN" "🙌 Done!"
else
cecholn "RED" "😿 Failed!"
fi
}
runApp() {
MY_PATH=$(dirname "$0")
MY_PATH=$( (cd "$MY_PATH" && pwd))
APP_PATH="${MY_PATH}"
export alpas_run_mode="console"
export alpas_root_dir="$APP_PATH"
./gradlew run -q --args="$*" #>/dev/null 2>&1
unset alpas_run_mode
unset alpas_root_dir
}
checkJava() {
java=$(command -v java)
cecholn "BLUE" " Making sure the correct version of Java is installed..."
if [[ "$java" ]]; then
_java=java
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
_java="$JAVA_HOME/bin/java"
else
cecholn "RED" " Java not found. Make sure to install the proper version: https://alpas.dev/docs/installation"
exit 1
fi
if [[ "$_java" ]]; then
full_version=$("$_java" -version 2>&1 | head -1 | cut -d'"' -f2)
version=$("$_java" -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
if [[ "$version" -gt "8" ]]; then
cecholn "GREEN" " Found supported Java version $full_version! 👍"
else
cecholn "RED" " Unsupported Java version $full_version. Make sure to install the proper version: https://alpas.dev/docs/installation"
exit 1
fi
fi
}
if [[ $# -eq 1 ]]; then
case "$1" in
init)
cecholn "RED" " Oops! I need your app name."
printf " Please provide app's full name. The command should be something like:"
cecholn "GREEN" " ./alpas init com.example.blog"
;;
watch)
shift;
./gradlew run -t --quiet "$@"
;;
build)
build
;;
run)
shift;
./gradlew run --quiet "$@"
;;
serve)
shift;
./gradlew run --quiet "$@"
;;
help)
runApp --help
;;
list)
runApp --help
;;
jar)
buildJar
;;
*)
runApp "$@"
;;
esac
elif [[ $1 == *"init"* ]]; then
if [ -f ./.env ]; then
cecho "RED" " Oops!"
echo "Looks like your app is already crafted."
else
cecholn "BLUE" " Crafting your app...\n"
# todo: check that the proper versions of Gradle is installed
checkJava
gradle wrapper >/dev/null 2>&1
chmod +x ./gradlew
./gradlew >/dev/null 2>&1
cecholn "BLUE" " Copying .env file..."
cp ./.env.example ./.env
# todo: replace perl with bash
perl -p -i -e 's/com.egorsmkv.short_urls_service/'"$2"'/g' `grep -Ril --exclude-dir=node_modules --exclude-dir=.gradle --exclude-dir=.idea com.egorsmkv.short_urls_service .`
app_name="${2##*.}"
perl -p -i -e 's/short_urls_service/'"${app_name}"'/g' `grep -Ril --exclude-dir=node_modules --exclude-dir=.gradle --exclude-dir=.idea short_urls_service .`
cecholn "BLUE" " Generating your app key..."
app_key=$(env LC_CTYPE=C tr -dc "A-Za-z0-9_$%^&*()-+=" </dev/urandom | head -c 32 | base64)
perl -p -i -e 's/__APP_KEY__/'"base64:${app_key}"'/g' `grep -l __APP_KEY__ .env`
cecholn "BLUE" " Building your app..."
cecholn "BLUE" " This will take a few seconds."
rm -rf ./build
rm -rf ./out
gradle build --quiet >/dev/null 2>&1
build --quiet >/dev/null 2>&1
cecholn "BLUE" " Linking src/main/resources/web folder..."
./alpas link:web --quiet
cecholn "BLUE" " Linking src/main/resources/templates folder..."
./alpas link:templates --quiet
printf "\n"
cecholn "GREEN" " ✓ Your app is crafted!\n"
cecholn "BLUE" " Run ./alpas serve to serve your app."
cecholn "BLUE" " Run ./alpas help to see all the available Alpas commands.\n"
cecholn "YELLOW" " Don't forget to checkout the docs: https://alpas.dev/docs"
fi
else
runApp "$@"
fi