autoloaderchecker.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env bash
  2. COMPOSER_COMMAND=$(which "composer")
  3. if [ "$COMPOSER_COMMAND" = '' ]
  4. then
  5. #No global composer found, try local or download it
  6. if [ -e "composer.phar" ]
  7. then
  8. echo "Composer found: checking for update"
  9. else
  10. echo "Composer not found: fetching"
  11. php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  12. php composer-setup.php
  13. php -r "unlink('composer-setup.php');"
  14. fi
  15. COMPOSER_COMMAND="php composer.phar"
  16. else
  17. echo "Global composer found: checking for update"
  18. fi
  19. #Make sure we are on the latest composer
  20. $COMPOSER_COMMAND self-update
  21. REPODIR=`git rev-parse --show-toplevel`
  22. #Redump the main autoloader
  23. echo
  24. echo "Regenerating main autoloader"
  25. $COMPOSER_COMMAND dump-autoload -d $REPODIR
  26. for app in ${REPODIR}/apps/*; do
  27. if [[ -d $app ]]; then
  28. if [[ -e ${app}/composer/composer.json ]]; then
  29. echo
  30. echo "Regenerating autoloader for ${app}"
  31. $COMPOSER_COMMAND dump-autoload -d ${app}/composer
  32. fi
  33. fi
  34. done
  35. files=`git diff --name-only`
  36. composerfile=false
  37. for file in $files
  38. do
  39. if [[ $file == *autoload_classmap* ]]
  40. then
  41. composerfile=true
  42. break
  43. fi
  44. done
  45. echo
  46. if [ $composerfile = true ]
  47. then
  48. echo "The autoloaders are not up to date"
  49. echo "Please run: bash build/autoloaderchecker.sh"
  50. echo "And commit the result"
  51. exit 1
  52. else
  53. echo "Autoloader up to date. Carry on"
  54. exit 0
  55. fi