Repository navigation
Expand file tree
/
Copy pathingbling.sh
More file actions
executable file
·277 lines (226 loc) · 6.89 KB
/
Copy pathingbling.sh
File metadata and controls
executable file
·277 lines (226 loc) · 6.89 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/env bash
command="$1"
repo="https://github.com/ThomasSquall/Ingbling.git"
dir=$(pwd)/
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
function check-is-installed {
command="$1"
"$command" --version 2>&1 >/dev/null
IS_AVAILABLE=$?
if [[ 0 -ne "IS_AVAILABLE" ]]; then
echo "$command is not installed. Please install it before running again."
exit 1
fi;
}
function check-dependencies {
check-is-installed git
check-is-installed composer
}
function install-repo {
name="$1"
git clone "$repo" "$dir$name"
cd "$name"
rm -rf .git
rm -f ingbling.sh
}
function install-dependencies {
composer install
composer update
}
function create-config {
file="ingbling.json"
echo "{" > "$file"
echo " \"name\": \"$1\"," >> "$file"
echo " \"version\": \"$2\"," >> "$file"
echo " \"settings\": {" >> "$file"
echo " \"basedir\": \"$3\"," >> "$file"
echo " \"url\": \"$4\"," >> "$file"
echo " \"errors\": false" >> "$file"
echo " }," >> "$file"
echo " \"db\": {" >> "$file"
echo " \"host\": \"$5\"," >> "$file"
echo " \"port\": $6," >> "$file"
echo " \"name\": \"$7\"," >> "$file"
echo " \"user\": \"$8\"," >> "$file"
echo " \"password\": \"$9\"" >> "$file"
echo " }" >> "$file"
echo "}" >> "$file"
mv .htaccess-sample .htaccess
sed -i "s@ingbling@$1@" .htaccess
rm -f .htaccess-sample
}
function basedir-config {
basedir="$1"
if [[ "app" != "$basedir" && "app/" != "$basedir" ]]; then
mkdir "$basedir"
mv app/* "$basedir"/
rm -rf app/
fi;
}
function init {
check-dependencies
echo "Welcome to Ingbling project generator!"
read -p "Project name: " name
while [[ "" = "$name" ]]; do
echo "You cannot leave the project name empty"
read -p "Project name: " name
done;
read -p "Project version (1.0.0): " version
if [[ "" = "$version" ]]; then
version="1.0.0"
fi;
read -p "Development directory (app): " basedir
if [[ "" = "$basedir" ]]; then
basedir="app"
fi;
read -p "URL of your app (http://localhost/$name): " url
if [[ "" = "$url" ]]; then
url="http://localhost/$name"
fi;
read -p "Database host (localhost): " db_host
if [[ "" = "$db_host" ]]; then
db_host="localhost"
fi;
read -p "Database port (27017): " db_port
if [[ "" = "$db_port" ]]; then
db_port="27017"
fi;
read -p "Database name ($name): " db_name
if [[ "" = "$db_name" ]]; then
db_name="$name"
fi;
read -p "Database user: " db_user
read -p "Database password: " db_password
while [[ "" != "$db_user" && "" = "$db_password" ]]; do
echo "Your password cannot be empty while a user has been defined"
read -p "Database password: " db_password
done;
echo
echo "Name: $name"
echo "Version: $version"
echo "Development directory: $basedir"
echo "URL of the app: $url"
echo "Database host: $db_host"
echo "Database port: $db_port"
echo "Database name: $db_name"
echo "Database user: $db_user"
echo "Database password: $db_password"
echo
read -p "Is this configuration ok? " -n 1 -r
echo
if [[ ^[Yy]$ =~ "$REPLY" || "" = "$REPLY" ]]; then
install-repo "$name"
install-dependencies
create-config "$name" "$version" "$basedir" "$url" "$db_host" "$db_port" "$db_name" "$db_user" "$db_password"
basedir-config "$basedir"
echo
echo -e "${GREEN}Congratulations! Your project has been successfully created!${NC}"
echo
else
read -p "You choose to abort, wanna start over? " restart
if [[ "" = "$restart" || "y" = "$restart" || "Y" = "$restart" || "yes" = "$restart" || "Yes" = "$restart" ]]; then
ingbling init
fi;
fi;
exit 1
}
function generate-controller {
read -p "Controller name? (Home) " name
if [[ "" = "$name" ]]; then
name="Home"
fi
name="$(tr '[:upper:]' '[:lower:]' <<< ${name})"
ucName="$(tr '[:lower:]' '[:upper:]' <<< ${name:0:1})${name:1}"
cName="$ucName""Controller"
controller="<?php"
controller="$controller"$'\n'
controller="$controller"$'\n/**'
controller="$controller"$'\n * Class '"$cName."
if [[ "home" = "$name" ]]; then
controller="$controller"$'\n * @PHPEasyAPI\Server'
else
controller="$controller"$'\n * @PHPEasyAPI\Server("'"$name"'")'
fi
controller="$controller"$'\n */'
controller="$controller"$'\nclass '"$cName"' extends Ingbling\MVC\ControllerBase'
controller="$controller"$'\n{'
controller="$controller"$'\n /**'
controller="$controller"$'\n * Initialize here your controller.'
controller="$controller"$'\n */'
controller="$controller"$'\n public function init() { $this->Title = "'"$ucName"'"; }'
controller="$controller"$'\n'
controller="$controller"$'\n /**'
controller="$controller"$'\n * Renders the main page of the controller.'
controller="$controller"$'\n'" * @PHPEasyAPI\Enrichment\Endpoint"'(method = "GET", url = "")'
controller="$controller"$'\n */'
controller="$controller"$'\n public function getIndex() { $this->render(); }'
controller="$controller"$'\n}'
echo "$controller" > "$1/controllers/$cName.php"
echo -e "${GREEN}Controller $cName created successfully!${NC}"
exit 1
}
function generate-collection {
echo "collections"
}
function generate {
if [[ ! -f ingbling.json ]]; then
echo
echo -e "${RED}Not an Ingbling project!${NC}"
echo "Please use 'ingbling init' to start one."
echo
exit 1
fi
basedir=`cat ingbling.json|grep basedir|awk '{$1=$1};1'`
if [[ "" = "$basedir" ]]; then
basedir="app"
else
basedir="${basedir//\"basedir\": \"}"
basedir="${basedir//\",}"
basedir="${basedir///}"
fi;
echo "Choose what you want to generate:"
echo "[0]: Controller"
echo "[1]: Collection"
read -p "Enter the corresponding number: " -n 1 -r
echo
case "$REPLY" in
0)
generate-controller "$basedir"
;;
1)
generate-collection
;;
esac
}
function guide {
echo
echo "List of commands:"
echo
echo " init | i: Creates a new Ingbling project"
echo " gen | g: Starts an interactive component generator"
echo
echo "--version | -v Shows the Ingbling script version"
echo "--help | -h Shows the guide"
echo
exit 1
}
case "$command" in
init|i)
init
;;
gen|g)
generate
;;
--help|-h)
guide
;;
--version|-v)
echo "Ingbling: app builder, version 1.0.0"
;;
*)
echo "No command found! Run 'ingbling --help' for more info."
exit 1
;;
esac