diff --git a/.gitignore b/.gitignore index fd46c2e9..6c962a0d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ nbproject composer .ht* /vendor/ -.DS_Store \ No newline at end of file +.DS_Store +.php_cs.cache \ No newline at end of file diff --git a/dev.sh b/dev.sh index e191de74..6c842bd9 100755 --- a/dev.sh +++ b/dev.sh @@ -6,13 +6,16 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" if [ ! -e "data/config.php" ]; then - cp "$DIR/data/config.php.example" "$DIR/data/config.php" + cp "$DIR/data/config.php.example" "$DIR/data/config.php" fi if ! which $PHPBIN 2>/dev/null; then - PHPBIN=php + PHPBIN=php fi +# Installing git hook +$DIR/hooks/install.sh + $PHPBIN composer.phar install -$PHPBIN --server localhost:8000 --docroot "$DIR/web" "$DIR/web/index.php" +$PHPBIN --server localhost:8000 --docroot "$DIR/web" "$DIR/web/index.php" \ No newline at end of file diff --git a/docker.sh b/docker.sh index 72f4572c..0fbf5f86 100755 --- a/docker.sh +++ b/docker.sh @@ -4,14 +4,18 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" if [ ! -e "$DIR/data/config.php" ]; then - cp "$DIR/data/config.php.example" "$DIR/data/config.php" + cp "$DIR/data/config.php.example" "$DIR/data/config.php" fi +# Installing git hook +$DIR/hooks/install.sh + docker run --rm -it --name "dev.lbry.io" \ - -v "$DIR:/usr/src/lbry.io" \ - -w "/usr/src/lbry.io" \ - -p "127.0.0.1:8000:8000" \ - -u "$(id -u):$(id -g)" \ - php:7-alpine \ - php composer.phar install - php --server "0.0.0.0:8000" --docroot "web/" "index.php" + -v "$DIR:/usr/src/lbry.io" \ + -w "/usr/src/lbry.io" \ + -p "127.0.0.1:8000:8000" \ + -u "$(id -u):$(id -g)" \ + php:7-alpine \ + php composer.phar install + + php --server "0.0.0.0:8000" --docroot "web/" "index.php" \ No newline at end of file diff --git a/hooks/install.sh b/hooks/install.sh new file mode 100755 index 00000000..bae03719 --- /dev/null +++ b/hooks/install.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ -e .git/hooks/pre-commit ]; +then + PRE_COMMIT_EXISTS=1 +else + PRE_COMMIT_EXISTS=0 +fi + +cp ./hooks/pre-commit .git/hooks/pre-commit +chmod +x .git/hooks/pre-commit + +if [ "$PRE_COMMIT_EXISTS" = 0 ]; +then + echo "Pre-commit git hook is installed!" +else + echo "Pre-commit git hook is updated!" +fi \ No newline at end of file diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100644 index 00000000..a9b3f5c4 --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,40 @@ +#!/bin/sh + +PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"` +STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php` + +# Determine if a file list is passed +if [ "$#" -eq 1 ] +then + oIFS=$IFS + IFS=' + ' + SFILES="$1" + IFS=$oIFS +fi +SFILES=${SFILES:-$STAGED_FILES_CMD} + +echo "Checking PHP Lint..." +for FILE in $SFILES +do + php -l -d display_errors=0 $PROJECT/$FILE + if [ $? != 0 ] + then + echo "Fix the error before commit." + exit 1 + fi + FILES="$FILES $PROJECT/$FILE" +done + +if [ "$FILES" != "" ] +then + echo "Running php-cs-fixer" + $PROJECT/php-cs-fixer fix $FILES + git add $FILES + if [ $? != 0 ] + then + echo "Error was found" + fi +fi + +exit $? \ No newline at end of file diff --git a/php-cs-fixer b/php-cs-fixer new file mode 100755 index 00000000..e4df4dcf Binary files /dev/null and b/php-cs-fixer differ