-
Notifications
You must be signed in to change notification settings - Fork 508
/
Copy pathpost-commands.sh
executable file
·116 lines (104 loc) · 2.88 KB
/
post-commands.sh
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
#!/bin/bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
WORKSPACE_DIR="$( cd "$SCRIPT_DIR/.." &> /dev/null && pwd )"
VISIBLE_FOLDER_SERVER="${VISIBLE_FOLDER_SERVER}"
VISIBLE_FOLDER_CLIENT="${VISIBLE_FOLDER_CLIENT}"
VISIBLE_FOLDER_PROJECT="${VISIBLE_FOLDER_PROJECT}"
VISIBLE_FOLDER_VERSION="${VISIBLE_FOLDER_VERSION}"
# Set up SERVER_DIR & CLIENT_DIR
if [ -z "$VISIBLE_FOLDER_VERSION" ]; then
SERVER_DIR="${WORKSPACE_DIR}/${VISIBLE_FOLDER_PROJECT}/server"
CLIENT_DIR="${WORKSPACE_DIR}/${VISIBLE_FOLDER_PROJECT}/client/${VISIBLE_FOLDER_CLIENT}"
else
SERVER_DIR="${WORKSPACE_DIR}/${VISIBLE_FOLDER_PROJECT}/${VISIBLE_FOLDER_VERSION}/server"
CLIENT_DIR="${WORKSPACE_DIR}/${VISIBLE_FOLDER_PROJECT}/${VISIBLE_FOLDER_VERSION}/client/${VISIBLE_FOLDER_CLIENT}"
fi
# Backend setup functions
setup_backend() {
case "$VISIBLE_FOLDER_SERVER" in
node)
cd "$SERVER_DIR/node" && npm install
;;
java)
cd "$SERVER_DIR" && cd java && mvn clean install
;;
dotnet)
cd "$SERVER_DIR/dotnet" && dotnet restore
;;
php)
cd "$SERVER_DIR" && cd php && composer install
;;
python)
cd "$SERVER_DIR" && cd python && python -m venv .venv && pip install -r requirements.txt
;;
ruby)
cd "$SERVER_DIR" && cd ruby && bundle install
;;
*)
echo "Unknown server: $VISIBLE_FOLDER_SERVER"
exit 1
;;
esac
}
# Frontend setup functions
setup_frontend() {
cd "$CLIENT_DIR" && npm install
}
# Backend start functions
start_backend() {
case "$VISIBLE_FOLDER_SERVER" in
node)
cd "$SERVER_DIR/node" && npm start
;;
java)
cd "$SERVER_DIR/java" && mvn spring-boot:run
;;
dotnet)
cd "$SERVER_DIR/dotnet" && dotnet run
;;
php)
cd "$SERVER_DIR/php" && composer start
;;
python)
cd "$SERVER_DIR" && cd python && flask --app server run --port 8080
;;
ruby)
cd "$SERVER_DIR" && cd ruby && bundle exec ruby server.rb
;;
*)
echo "Unknown server: $VISIBLE_FOLDER_SERVER"
exit 1
;;
esac
}
# Frontend start functions
start_frontend() {
cd "$CLIENT_DIR" && npm run start --no-analytics
}
# Post-create commands
post_create() {
echo "Running post-create commands..."
setup_backend
setup_frontend
}
# Post-attach commands
post_attach() {
echo "Running post-attach commands..."
start_backend &
start_frontend
}
# Main execution
case "$1" in
post-create)
post_create
;;
post-attach)
post_attach
;;
*)
echo "Usage: $0 {post-create|post-attach}"
exit 1
;;
esac
exit 0