-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.sh
279 lines (238 loc) · 6.63 KB
/
app.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
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
278
279
#!/bin/sh
# Memorise callback directory.
pwd=$(pwd)
# Declare paths
path_api=$pwd/api
path_front=$pwd/_front
# Name screen consoles
dev_screenname='NUXTDEV'
prod_screenname='NUXTPROD'
# FUNCTIONS : START
Aliases () {
cd ~
echo "Deleting old ..."
# Delete old aliases if exist
sed -i -e '/app/d' ~/.bashrc >> /dev/null
sed -i -e '/pa/d' ~/.bashrc >> /dev/null
sed -i -e '/tinker/d' ~/.bashrc >> /dev/null
echo "Install new ..."
# Define new aliases
echo -e "alias app='bash app.sh'" >> ~/.bashrc
echo -e "alias pa='php api/artisan'" >> ~/.bashrc
echo -e "alias tinker='php api/artisan tinker'" >> ~/.bashrc
# Back to good dir.
cd $pwd
# Reload bash and aliases.
source ~/.bashrc
echo "Aliases has been installed in your ~./.bashrc file."
}
# FUNCTIONS : END
# UX : START
if [ -z "$1" ]
then
echo "Basic [start | stop | open]"
echo "Usage: app start dev"
echo " app start dev -screen"
echo " "
echo "Updater [update]"
echo "Usage: app update composer"
echo " app update npm"
echo " "
echo "Database [migrate, mig | seed]"
echo " "
#############################
# START ACTION #
#############################
elif [ $1 = "start" ]
then
# START: dev
if [ -z "$2" ]
then
echo "You must specify witch mode: [build | dev]"
elif [ $2 = "dev" ]
then
# START: dev in screen mode.
if [ -z "$3" ]
then
cd $path_front
npm run dev
# START: dev in windows mode.
elif [ $3 = "-screen" ]
then
cd $path_front
screen -A -m -d -S $dev_screenname npm run dev
else
echo "Unknow mode \"$3\"."
echo "Choose one of both: [build | dev]"
fi
# START: prod
elif [ $2 = "prod" ] || [ $2 = "build" ]
then
# START: prod in screen mode.
if [ -z "$3" ]
then
cd $path_front
npm run start
# START: prod in windows mode.
elif [ $3 = "-screen" ]
then
cd $path_front
screen -A -m -d -S $prod_screenname npm run build
else
echo "Unknow mode \"$3\"."
echo "Choose one of both: [prod | dev]"
fi
fi
############################
# STOP ACTION #
############################
elif [ $1 = "stop" ]
then
if [ -z "$2" ]
then
echo "You must specify witch mode: [prod | dev]"
elif [ $2 = "dev" ]
then
screen -X -S $dev_screenname kill
screen -ls
elif [ $2 = "prod" ] | [ $2 = "build" ]
then
screen -X -S $prod_screenname kill
screen -ls
fi
############################
# OPEN ACTION #
############################
# Open a back console (screen)
elif [ $1 = "open" ]
then
if [ $2 = "dev" ]
then
screen -r $dev_screenname
elif [ $2 = "prod" ] | [ $2 = "build" ]
then
screen -r $prod_screenname
fi
##############################
# UPDATE ACTION #
##############################
elif [ $1 = "update" ]
then
# UPDATE ALL
if [ -z "$2" ]
then
echo "All will be updated: composer && npm"
echo " "
echo "Use following commands to update in individual mode:"
echo "app update composer"
echo "app update npm"
echo " "
read -p "Are you sure to update all ? [Y/n]" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
cd $path_api
composer update
cd $path_front
npm update
else
echo " "
echo "Canceled"
fi
# UPDATE COMPOSER
elif [ $2 = "composer" ] || [ $2 = "api" ] || [ $2 = "laravel" ]
then
cd $path_api
composer update
# UPDATE NODEJS
elif [ $2 = "node" ] || [ $2 = "npm" ] || [ $2 = "nuxt" ] || [ $2 = "front" ]
then
cd $path_front
npm update
fi
###############################
# INSTALL ACTION #
###############################
elif [ $1 = "install" ]
then
Aliases
cd $path_api
rm -rf composer.lock
composer install
cd $path_front
rm -rf package-lock.json
npm install
echo " "
echo "################"
echo "# INFORMATIONS #"
echo "################"
echo " "
echo "Command < app > can manage all your app. Start NodeJS, Installation, Update, ..."
echo ""
echo "Example: app start dev <=> cd _front && npm run dev"
echo "Example: app migrate <=> php api/artisan migrate"
echo "Example: app tinker <=> php api/artisan tinker"
echo "Example: app rebase <=> git pull --rebase"
echo ""
echo "Example: pa route:list (replace remote PHP ARTISAN)"
echo "Installation complete."
echo "Don't forget to update your database with an < app migrate --seed > (or not)."
echo ""
echo "All installation done!"
###############################
# MIGRATE ACTION #
###############################
elif [ $1 = "migrate" ] || [ $1 = "mig" ]
then
if [ -z $2 ]
then
php api/artisan migrate
elif [ $2 = "-s" ] || [ $2 = "-seed" ] || [ $2 = "--s" ] || [ $2 = "--seed" ] || [ $2 = "seed" ] || [ $2 = "s" ]
then
php api/artisan migrate --seed
fi
###############################
# REFRESH ACTION #
###############################
elif [ $1 = "rmigrate" ] || [ $1 = "rmig" ]
then
if [ -z $2 ]
then
echo "[:refresh] option will erase all from your database."
read -p "Are you sure to refresh all database ? [Y/n]" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
php api/artisan migrate:refresh
else
echo " "
echo "Canceled"
fi
elif [ $2 = "-s" ] || [ $2 = "-seed" ] || [ $2 = "--s" ] || [ $2 = "--seed" ] || [ $2 = "seed" ] || [ $2 = "s" ]
then
echo "[:refresh --seed] option will erase all from your database."
read -p "Are you sure to refresh all database ? [Y/n]" -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
php api/artisan migrate:refresh --seed
else
echo " "
echo "Canceled"
fi
fi
#############################
# ALIAS ACTION #
#############################
elif [ $1 = "alias" ]
then
Aliases
##############################
# REBASE ACTION #
##############################
elif [ $1 = "rebase" ]
then
git pull --rebase
## END HERE ##
fi
# UX : START