Skip to content

Instantly share code, notes, and snippets.

@jeremyworboys
Last active August 29, 2015 13:56

Revisions

  1. jeremyworboys revised this gist Feb 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion laravel
    Original file line number Diff line number Diff line change
    @@ -95,7 +95,7 @@ curl -s "https://raw.github.com/thomasbachem/php-short-array-syntax-converter/ma
    # - only one blank line at EOF
    # - convert tabs to four spaces
    echo 'Conforming to personal code style'
    find . -type f -name "*.php" \
    find . -name "*.php" \
    -exec php-cs-fixer -q fix {} \; \
    -exec php convert.php -w {} \; \
    -exec gsed -i 's/[[:space:]]*$//' {} \; \
  2. jeremyworboys created this gist Feb 24, 2014.
    118 changes: 118 additions & 0 deletions laravel
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,118 @@
    #!/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 . -type f -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"