-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_api_structure.sh
More file actions
128 lines (100 loc) · 2.71 KB
/
create_api_structure.sh
File metadata and controls
128 lines (100 loc) · 2.71 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
#!/bin/bash
function help(){
echo "Usage:
bash create_api_structure.sh [ -n | --api_name ]
[ -p ] --path (optional)
[ -h | --help ]"
exit 1
}
function fill_env() {
cat <<EOT >> $path/.env
IS_DEBUG=False
API_KEY='serdarakyol55@outlook.com'
EOT
}
function fill_readme(){
cat <<EOT >> $path/README.md
# $api_name api created by bash script
EOT
}
function current_folder_create_api(){
virtualenv venv
touch "README.md" "Dockerfile" "requirements.txt" ".env"
fill_env
fill_readme
mkdir $api_name"_api"
cd $api_name"_api"
mkdir "api" "core" "data" "models" "services" "utils" "test"
# create main file
touch "main.py"
# api folder
mkdir "api/routes"
touch "api/routes/router.py" "api/routes/router_"$api_name".py"
# core folder
touch "core/config.py" "core/event_handler.py" "core/messages.py" "core/security.py"
# model folder
touch "models/model_"$api_name".py"
# service folder
touch "services/service_"$api_name".py"
# utils folder
touch "utils/utils.py"
}
function path_create_api(){
# create virtual env
virtualenv $path/venv
touch "$path/.env" "$path/Dockerfile" "$path/README.md" "$path/requirements.txt"
fill_env
fill_readme
mkdir $path$api_name"_api"
cd $path$api_name"_api"
mkdir "api" "core" "data" "models" "services" "utils" "test"
# create main file
touch "main.py"
# api folder
mkdir "api/routes"
touch "api/routes/router.py" "api/routes/router_"$api_name".py"
# core folder
touch "core/config.py" "core/event_handler.py" "core/messages.py" "core/security.py"
# model folder
touch "models/model_"$api_name".py"
# service folder
touch "services/service_"$api_name".py"
# utils folder
touch "utils/utils.py"
}
while getopts ":n:p:" o; do
case "${o}" in
n)
api_name=${OPTARG}
;;
p)
path=${OPTARG}
;;
*)
help
;;
esac
done
shift $((OPTIND-1))
# if lenght of api_name is zero
if [ -z $api_name ]; then
help
else
# if lenght of path is greater than zero
if [ -d "$path" ]; then
path_create_api $path $api_name
else
echo "Directory is NOT exist or specified. Do you want to create the structure in current folder? $(pwd)"
current_path = $(pwd)
select yn in "Yes" "No"; do
case $yn in
Yes )
current_folder_create_api $api_name
break;;
No )
echo "Existing script...";
exit;;
esac
done
fi
fi