Skip to content

Instantly share code, notes, and snippets.

@jeremyworboys
Last active August 29, 2015 13:56
Show Gist options
  • Save jeremyworboys/9199783 to your computer and use it in GitHub Desktop.
Save jeremyworboys/9199783 to your computer and use it in GitHub Desktop.
Personal Laravel project bootstrapper
#!/bin/bash
# Get project name
if [[ $1 == "" ]]
then
echo -n "Enter project name (or domain): "
read -e PROJECT_NAME
if [[ $PROJECT_NAME == "" ]]
then
echo "You must enter a name for the project"
exit 1
fi
else
PROJECT_NAME=$1
fi
SAFE_NAME=`echo $PROJECT_NAME | gsed -e 's/[^a-z0-9]/_/gi' -e 's/__*/_/g'`
# Create database?
echo -n "Create a database for $PROJECT_NAME? (Y/n) "
read -e CREATE_DATABASE
CREATE_DATABASE=${CREATE_DATABASE:-y}
if [[ $CREATE_DATABASE == "y" ]]
then
echo -n "Database name? ($PROJECT_NAME) "
read -e DATABASE_NAME
DATABASE_NAME=${DATABASE_NAME:-$PROJECT_NAME}
fi
# Install generators?
echo -n "Add Way/Generators to $PROJECT_NAME? (Y/n) "
read -e INSTALL_GENERATORS
INSTALL_GENERATORS=${INSTALL_GENERATORS:-y}
# Install clockwork?
echo -n "Add Itsgoingd/Clockwork to $PROJECT_NAME? (Y/n) "
read -e INSTALL_CLOCKWORK
INSTALL_CLOCKWORK=${INSTALL_CLOCKWORK:-y}
# ------------------------------------------------------------------------------
# Pull in Laravel boilerplate
composer create-project laravel/laravel www --prefer-dist --no-scripts --no-progress --no-install
cd www
# Clean up
rm CONTRIBUTING.md
rm readme.md
# Clean up composer.json
gsed -i "s/\"name\": .*/\"name\": \"${PROJECT_NAME}\",/" composer.json
gsed -i '/description/d' composer.json
gsed -i '/keywords/d' composer.json
gsed -i '/license/d' composer.json
# Tweak Laravel config
gsed -i "s/'timezone' => .*/'timezone' => 'Australia\/Sydney',/" app/config/app.php
# Create database and update Laravel config
if [[ $CREATE_DATABASE == "y" ]]
then
# @TODO: Allow creating user and defining/entering password
mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS \`$DATABASE_NAME\`;"
gsed -i "s/'database' => .*/'database' => '${DATABASE_NAME}',/" app/config/database.php
gsed -i "s/'password' => .*/'password' => 'root',/" app/config/database.php
fi
# Install Jeffrey Way's generator tool
if [[ $INSTALL_GENERATORS == 'y' ]]
then
composer require "way/generators dev-master" --dev --no-update
gsed -i "108a\\\t\\t'Way\\\\Generators\\\\GeneratorsServiceProvider'," app/config/app.php
fi
# Install Miroslav Rigler's clockwork component
if [[ $INSTALL_CLOCKWORK == 'y' ]]
then
composer require "itsgoingd/clockwork dev-master" --dev --no-update
gsed -i "108a\\\t\\t'Clockwork\\\\Support\\\\Laravel\\\\ClockworkServiceProvider'," app/config/app.php
gsed -i "176a\\\t\\t'Clockwork' => 'Clockwork\\\\Support\\\\Laravel\\\\Facade'," app/config/app.php
gsed -i "3a\\\n\\t/**\\n\\t * Constructor.\\n\\t *\\n\\t * @return void\\n\\t */\\n\\tpublic function __construct()\\n\\t{\\n\\t\\t\$this->beforeFilter(function() {\\n\\t\\t\\tEvent::fire('clockwork.controller.start');\\n\\t\\t});\\n\\n\\t\\t\$this->afterFilter(function() {\\n\\t\\t\\tEvent::fire('clockwork.controller.end');\\n\\t\\t});\\n\\t}" app/controllers/BaseController.php
fi
# Get array syntax converter
curl -s "https://raw.github.com/thomasbachem/php-short-array-syntax-converter/master/convert.php" -o convert.php
# Get all files to meet personal coding style:
# - PSR-2
# - Short array syntax
# - no trailing spaces
# - blank line at EOF
# - only one blank line at EOF
# - convert tabs to four spaces
echo 'Conforming to personal code style'
find . -name "*.php" \
-exec php-cs-fixer -q fix {} \; \
-exec php convert.php -w {} \; \
-exec gsed -i 's/[[:space:]]*$//' {} \; \
-exec gsed -i '' {} \; \
-exec gsed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' {} \; \
-exec gsed -i 's/\t/ /g' {} \;
# Clean up
rm convert.php
# Install dependencies
composer update --prefer-dist
php artisan key:generate
# Create git repo
gsed -i "1i/app/storage" .gitignore
gsed -i "/composer.lock/d" .gitignore
git init
git add .
git commit -am "Initial commit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment