-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnlp.sh
executable file
·338 lines (305 loc) · 8.12 KB
/
nlp.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/bin/bash
TAILWIND=false
JETSTREAM=false
BREEZE=false
MYSQL_TEST=false
POSTGRES=false
POSTGRES_TEST=false
PHPSTORM=false
SUBLIME=false
VSCODE=false
MESSAGE=''
function useTailwind() {
if [[ " ${PARAMETERS[*]} " =~ " -t " ]] || [[ " ${PARAMETERS[*]} " =~ " -tailwind " ]]
then
TAILWIND=true
fi
}
function useBreeze() {
if [[ " ${PARAMETERS[*]} " =~ " -b " ]] || [[ " ${PARAMETERS[*]} " =~ " -breeze " ]]
then
BREEZE=true
fi
}
function useJetstream() {
if [[ " ${PARAMETERS[*]} " =~ " -j " ]] || [[ " ${PARAMETERS[*]} " =~ " -jetstream " ]]
then
JETSTREAM=true
fi
}
function usePostgres() {
if [[ " ${PARAMETERS[*]} " =~ " -db=postgres " ]] || [[ " ${PARAMETERS[*]} " =~ " -database=postgres " ]]
then
POSTGRES=true
fi
}
function useMySQLTest() {
if [[ " ${PARAMETERS[*]} " =~ " -test=mysql " ]]
then
MYSQL_TEST=true
fi
}
function usePostgresTest() {
if [[ " ${PARAMETERS[*]} " =~ " -test=postgres " ]]
then
POSTGRES_TEST=true
fi
}
function parseArguments() {
PARAMETERS=($1 $2 $3 $4 $5 $6)
useTailwind
useBreeze
useJetstream
usePostgres
useMySQLTest
usePostgresTest
}
function validateInstallationOptions() {
if [ "$JETSTREAM" = true ] && [ "$BREEZE" = true ]
then
MESSAGE='You cant install both Jetstream and Breeze.'
fi
if [ "$JETSTREAM" = true ] && [ "$TAILWIND" = true ]
then
TAILWIND=false
fi
if [ "$BREEZE" = true ] && [ "$TAILWIND" = true ]
then
TAILWIND=false
fi
if [ "$MYSQL" = true ] && [ "$POSTGRES_TEST" = true ]
then
MESSAGE='You should use MySQL for testing.'
fi
if [ "$POSTGRES" = true ] && [ "$MYSQL_TEST" = true ]
then
MESSAGE='You should use Postgres for testing.'
fi
}
function showDocs() {
echo 'nlp command to create new Laravel projects.'
echo 'Syntax: nlp <project name> -<option> -<option>'
echo 'Options available:'
echo ''
echo '-breeze or -b to install Laravel Breeze starter kit'
echo '-jetsream or -j to install Laravel Jetstream'
echo '-tailwind or -t to install TailwindCSS'
echo '-database=postgres or -db=postgres to use PostgreSQL'
echo '-test=mysql to setup a testing database with MySQL'
echo '-test=postgres to setup a testing database with PostgreSQL'
echo ''
echo 'Breeze and Jetstream installs tailwind by default.'
echo 'Example: nlp new-project -b -test=mysql'
echo ''
}
function init() {
parseArguments $1 $2 $3 $4 $5 $6
validateInstallationOptions
if [ ! "$MESSAGE" = '' ]
then
echo $MESSAGE
exit
fi
}
function installLaravel() {
echo 'Installing Laravel.'
composer create-project laravel/laravel "$HOME"/code/"$1" > /dev/null 2>&1
echo 'Laravel Installed.'
cd "$HOME"/code/"$1" > /dev/null 2>&1
}
function installDebugbar() {
echo 'Installing Laravel Debugbar.'
composer require barryvdh/laravel-debugbar --dev > /dev/null 2>&1
echo /storage/debugbar >> .gitignore
echo 'Laravel Debugbar Installed.'
}
function installJetstream() {
if [ $JETSTREAM = true ]
then
echo 'Installing Jetstream.'
composer require laravel/jetstream > /dev/null 2>&1
echo 'Jetstream Installed.'
fi
}
function installBreeze() {
if [ $BREEZE = true ]
then
echo 'Installing Breeze.'
composer require laravel/breeze --dev > /dev/null 2>&1
echo 'Breeze Installed.'
fi
}
function installTailwind() {
if [ $TAILWIND = true ]
then
echo 'Installing TailwindCSS.'
npm install -D tailwindcss autoprefixer > /dev/null 2>&1
npx tailwindcss init -p > /dev/null 2>&1
echo -e "@tailwind base;\n@tailwind components;\n@tailwind utilities;" > "$HOME"/code/"$1"/resources/css/app.css
sed -i -e "s/content: \[\]/content: \[\\n\\t'\.\/resources\/\*\*\/\*\.blade\.php',\\n\\t'\.\/resources\/\*\*\/\*\.js',\\n\\t'\.\/resources\/\*\*\/\*\.vue',\\n ]/g" tailwind.config.js > /dev/null 2>&1
rm tailwind.config.js-e > /dev/null 2>&1
wget -q -O ./resources/views/welcome.blade.php https://gist.githubusercontent.com/Tray2/e5be9b2fad7ded2ac45e91f3dc9fb85c/raw/30ea0ba51753f256b02346f501cbb667143e5c66/welcome.blade.php
npm run build > /dev/null 2>&1
echo 'TailwindCSS Installed.'
fi
}
function setupGit() {
echo 'Setting up a Git Repository.'
git init > /dev/null 2>&1
git add . > /dev/null 2>&1
git commit -m "Initial commit" > /dev/null 2>&1
echo 'Git Repository Done.'
}
function createMySQLDatabases() {
if [ $POSTGRES = false ]
then
DATABASE_NAME=${1//[-]/_}
readonly MYSQL=`which mysql`
if [ $MYSQL = 'mysql not found' ]
then
echo "Couldn't find MySQL, make sure that it is installed"
exit
fi
Q1="CREATE DATABASE IF NOT EXISTS $DATABASE_NAME;"
echo 'Creating the database.'
$MYSQL -uroot -e "$Q1" > /dev/null 2>&1
if [ $MYSQL_TEST = true ]
then
DATABASE_NAME_TEST=${1//[-]/_}_test
Q2="CREATE DATABASE IF NOT EXISTS $DATABASE_NAME_TEST;"
$MYSQL -uroot -e "$Q2" > /dev/null 2>&1
fi
echo 'Database(s) Created.'
fi
}
function createPostgreDatabases() {
if [ $POSTGRES = true ]
then
DATABASE_NAME=${1//[-]/_}
readonly PSQL=`which psql`
if [ PSQL = 'psql not found' ]
then
echo "Couldn't find PostgreSQL, make sure that it is installed"
exit
fi
Q1="CREATE DATABASE $DATABASE_NAME;"
echo 'Creating the database.'
$PSQL postgres -c "$Q1" > /dev/null 2>&1
if [ $POSTGRES_TEST = true ]
then
DATABASE_NAME_TEST=${1//[-]/_}_test
Q2="CREATE DATABASE $DATABASE_NAME_TEST;"
$PSQL postgres -c "$Q2" > /dev/null 2>&1
fi
echo 'Database(s) Created.'
fi
}
function enableMySQLForTest() {
if [ $MYSQL_TEST = true ]
then
sed -i -e "s/sqlite/mysql/g" phpunit.xml > /dev/null 2>&1
sed -i -e "s/:memory:/$1/g" phpunit.xml > /dev/null 2>&1
fi
}
function enablePostgreSQLForTest() {
if [ $POSTGRES_TEST = true ]
then
sed -i -e "s/sqlite/pgql/g" phpunit.xml > /dev/null 2>&1
sed -i -e "s/:memory:/$1/g" phpunit.xml > /dev/null 2>&1
fi
}
function updatePhpUnitXML() {
echo 'Updating phpunit.xml.'
sed -i -e "s/\<!-- //g" phpunit.xml > /dev/null 2>&1
sed -i -e "s/\--\>//g" phpunit.xml > /dev/null 2>&1
enableMySQLForTest $DATABASE_NAME_TEST
enablePostgreSQLForTest $DATABASE_NAME_TEST
rm phpunit.xml-e
echo 'phpunit.xml updated.'
}
function updateEnv() {
readonly APP_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${1:0:1})${1:1}"
echo 'Updating the .env file to fit your project.'
if [ $POSTGRES = true ]
then
sed -i -e "s/DB_CONNECTION=mysql/DB_CONNECTION=pgsql/g" .env > /dev/null 2>&1
sed -i -r "s/DB_PORT=3306/DB_PORT=5432/g" .env > /dev/null 2>&1
fi
sed -i -e "s/DB_DATABASE=laravel/DB_DATABASE=$DATABASE_NAME/g" .env > /dev/null 2>&1
sed -i -e "s/APP_NAME=Laravel/APP_NAME=$APP_NAME/g" .env > /dev/null 2>&1
rm .env-e > /dev/null 2>&1
echo '.env updated.'
}
function launchBrowser() {
if [ $JETSTREAM = false ]
then
echo 'Launching Browser.'
open -a "Google Chrome" "http://$1.test"
fi
}
function checkProjectDirectory() {
if [ -d "$HOME/code/$1" ]
then
echo "There is already a project named: $1"
exit
fi
}
function launchPHPStorm() {
PSTORM=`which pstorm`
if [ ! $PSTORM = 'pstorm not found' ]
then
pstorm "$HOME/code/$1"
PHPSTORM=true
fi
}
function launchSublime() {
if [ $PHPSTORM = false ]
then
SUBL=`which subl`
if [ ! $SUBL = 'subl not found' ]
then
subl "$HOME/code/$1"
SUBLIME=true
fi
fi
}
function launchVSCode() {
if [ $PHPSTORM = false ] && [ $SUBL = false ]
then
SUBL=`which code`
if [ ! $CODE = 'code not found' ]
then
code "$HOME/code/$1"
fi
fi
}
function checkComposer() {
COMPOSER=`which composer`
if [ $COMPOSER = 'composer not found' ]
then
echo 'Make sure that you have composer installed, and in the path.'
exit
fi
}
if [ -z "$1" ]
then
showDocs
exit
fi
checkComposer
checkProjectDirectory $1
init $2 $3 $4 $5 $6 $7
installLaravel $1
installDebugbar
installBreeze
installJetstream
installTailwind $1
createMySQLDatabases $1
createPostgreDatabases $1
updateEnv $1
updatePhpUnitXML
setupGit
launchBrowser $1
launchPHPStorm $1
launchSublime $1
launchVSCode $1