Skip to content

Instantly share code, notes, and snippets.

@PEKTOP
Last active November 14, 2015 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PEKTOP/06e923e382c16795a941 to your computer and use it in GitHub Desktop.
Save PEKTOP/06e923e382c16795a941 to your computer and use it in GitHub Desktop.
Build automation for Laravel and Lumen
#!/bin/bash
echo "[BUILD] start"
CURRENT_DIR="$( cd "$( dirname "$0" )" && pwd )"
echo "[BUILD] current directory is $CURRENT_DIR"
if ! command -v php >/dev/null; then
echo "[BUILD] php is required"
echo "[BUILD] finish"
exit 1
fi
if command -v composer >/dev/null; then
echo "[BUILD] using composer that installed globally"
COMPOSER="composer"
else
if [ ! -f "$CURRENT_DIR/composer.phar" ]; then
echo "[BUILD] download composer.phar"
curl -sS https://getcomposer.org/installer | php -- --install-dir=$CURRENT_DIR --filename=composer.phar
else
echo "[BUILD] update an existing composer.phar"
php $CURRENT_DIR/composer.phar self-update
fi
COMPOSER="php $CURRENT_DIR/composer.phar"
fi
if [ "$1" = "dev" ]; then
if [ -f "$CURRENT_DIR/.env.dev" ]; then
echo "[BUILD] (dev) create .env"
cp $CURRENT_DIR/.env.dev $CURRENT_DIR/.env
else
echo "[FAIL] no such file .env.dev"
exit 1
fi
if [ ! -d "$CURRENT_DIR/vendor" ]; then
echo "[BUILD] (dev) composer install"
eval "$COMPOSER install --prefer-dist"
else
echo "[BUILD] (dev) composer update"
eval "$COMPOSER update --prefer-dist"
fi
if [ "$2" = "idehelper" ]; then
echo "[BUILD] (dev) run artisan command for IDE helper"
php artisan clear-compiled
php artisan ide-helper:generate
php artisan optimize
fi
else
if [ -f "$CURRENT_DIR/.env.production" ]; then
echo "[BUILD] (production) create .env"
cp $CURRENT_DIR/.env.production $CURRENT_DIR/.env
else
echo "[FAIL] no such file .env.prod"
exit 1
fi
if [ ! -d "$CURRENT_DIR/vendor" ]; then
echo "[BUILD] (production) composer install"
eval "$COMPOSER install --prefer-dist --no-dev"
else
echo "[BUILD] (production) composer update"
eval "$COMPOSER update --prefer-dist --no-dev"
fi
fi
echo "[BUILD] finish"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment