BUG Ensure sake works when called from any directory

This commit is contained in:
Damian Mooyman 2017-10-17 13:52:39 +13:00
parent e9e7bd649e
commit 884fdd61b1
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A

44
sake
View File

@ -9,39 +9,29 @@ Executes a SilverStripe command"
exit 1 exit 1
fi fi
# find the silverstripe installation # find the silverstripe installation, looking first at sake
# bin location, but falling back to current directory
sakedir=`dirname $0` sakedir=`dirname $0`
directory="$PWD"
if [ -f "$sakedir/cli-script.php" ]; then if [ -f "$sakedir/cli-script.php" ]; then
# Calling sake from vendor/silverstripe/framework/sake
framework="$sakedir" framework="$sakedir"
base=`dirname $sakedir` base="$sakedir/../../.."
elif [ -f ./cli-script.php ]; then elif [ -f "$sakedir/../silverstripe/framework/cli-script.php" ]; then
framework=. # Calling sake from vendor/bin/sake
base=.. framework="$sakedir/../silverstripe/framework"
else base="$sakedir/../.."
# look up the tree for the first parent folder that has a framework elif [ -f "$directory/vendor/silverstripe/framework/cli-script.php" ]; then
# installation # Vendor framework (from base) if sake installed globally
slashes=${PWD//[^\/]/}
directory="$PWD"
base=.
for (( n=${#slashes}; n>0; --n )) do
if [ -d "$directory/vendor/silverstripe/framework" ]; then
framework="$directory/vendor/silverstripe/framework" framework="$directory/vendor/silverstripe/framework"
base=.
break elif [ -f "$directory/framework/cli-script.php" ]; then
elif [ -d "$directory/framework" ]; then # Legacy directory (from base) if sake installed globally
framework="$directory/framework" framework="$directory/framework"
base=.
break else
fi echo "Can't find cli-script.php in $sakedir"
directory=`dirname $directory`
base="$base."
done
if [ ! -f "$framework/cli-script.php" ]; then
echo "Can't find cli-script.php in $framework"
exit 1 exit 1
fi
fi fi
# Find the PHP binary # Find the PHP binary