Created
February 10, 2020 20:17
-
-
Save bmadigan/88e244d19ede835e42f41040726915c9 to your computer and use it in GitHub Desktop.
Bash Create Laravel Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# l project-name -a -g -d | |
# | |
# Available options: | |
# -a Authentication scaffolding with tests | |
# -g Add Github remote | |
# -d Create a fresh MySQL database | |
# Laravel Zonda | |
function l { | |
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | |
echo "Create Laravel Projects fast." | |
echo "Flags:" | |
echo " - -a Create an auth scaffolding" | |
echo " - -d Create a MySQL database" | |
echo " - -g Add GitHub remote" | |
return | |
fi | |
if [ -z ${1+x} ]; then | |
echo "Required parameter {name} is not set." | |
return | |
fi | |
PROJECT=$1 | |
echo "Creating new Laravel project: $PROJECT..." | |
web | |
~/.composer/vendor/bin/laravel new $PROJECT | |
cd $PROJECT | |
git init | |
git add . | |
git commit -m "Fresh Laravel installation" | |
sed -i '' "s/APP_URL=http\:\/\/localhost/APP_URL=http\:\/\/$PROJECT\.dev/g" .env | |
sed -i '' "s/DB_DATABASE=root/DB_DATABASE=$PROJECT/g" .env | |
sed -i '' "s/DB_USERNAME=root/DB_USERNAME=root/g" .env | |
sed -i '' "s/DB_PASSWORD=/DB_PASSWORD=/g" .env | |
sed 's/<env name="MAIL_DRIVER" value="array"\/>/<env name="MAIL_DRIVER" value="array"\/>, <env name="DB_CONNECTION" value="sqlite"\/>, <env name="DB_DATABASE" value=":memory:"\/>/g' phpunit.xml | tr ',' '\n' > phpunit2.xml | |
rm phpunit.xml | |
mv phpunit2.xml phpunit.xml | |
git add . | |
git commit -m "Updated phpunit to use sqlite database" | |
function authenticationScaffold { | |
php artisan make:auth | |
git add . | |
git commit -m "Authentication scaffolding" | |
composer require dczajkowski/auth-tests | |
php artisan make:auth-tests -as | |
git add . | |
git commit -m "Authentication tests" | |
} | |
function githubAddRemoteAndPush { | |
git remote add origin [email protected]:DCzajkowski/$PROJECT.git | |
git push -u origin master | |
} | |
function createDatabase { | |
mysql -u root -e "CREATE DATABASE $PROJECT;" | |
} | |
if [[ "${@#-a}" = "$@" ]] then else | |
authenticationScaffold | |
fi | |
if [[ "${@#-g}" = "$@" ]] then else | |
githubAddRemoteAndPush | |
fi | |
if [[ "${@#-d}" = "$@" ]] then else | |
createDatabase | |
fi | |
subl . | |
echo -e "\e[36mEverything done! Happy coding 😎" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment