vendors 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * This file is part of the Symfony Standard Edition.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. $rootDir = dirname(__DIR__);
  12. $vendorDir = $rootDir.'/vendor';
  13. array_shift($argv);
  14. if (!isset($argv[0])) {
  15. exit(<<<EOF
  16. Symfony2 vendors script management.
  17. Specify a command to run:
  18. install: install vendors as specified in deps or deps.lock (recommended)
  19. update: update vendors to their latest versions (as specified in deps)
  20. EOF
  21. );
  22. }
  23. if (!in_array($command = array_shift($argv), array('install', 'update'))) {
  24. exit(sprintf("Command \"%s\" does not exist.\n", $command));
  25. }
  26. if (!is_dir($vendorDir)) {
  27. mkdir($vendorDir, 0777, true);
  28. }
  29. // versions
  30. $versions = array();
  31. if ('install' === $command && file_exists($rootDir.'/deps.lock')) {
  32. foreach (file($rootDir.'/deps.lock', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
  33. $parts = array_values(array_filter(explode(' ', $line)));
  34. if (2 !== count($parts)) {
  35. exit(sprintf('The deps version file is not valid (near "%s")', $line));
  36. }
  37. $versions[$parts[0]] = $parts[1];
  38. }
  39. }
  40. $newversions = array();
  41. $deps = parse_ini_file($rootDir.'/deps', true, INI_SCANNER_RAW);
  42. foreach ($deps as $name => $dep) {
  43. // revision
  44. if (isset($versions[$name])) {
  45. $rev = $versions[$name];
  46. } else {
  47. $rev = isset($dep['version']) ? $dep['version'] : 'origin/HEAD';
  48. }
  49. // install dir
  50. $installDir = isset($dep['target']) ? $vendorDir.'/'.$dep['target'] : $vendorDir.'/'.$name;
  51. if (in_array('--reinstall', $argv)) {
  52. if (PHP_OS == 'WINNT') {
  53. system(sprintf('rmdir /S /Q %s', escapeshellarg(realpath($installDir))));
  54. } else {
  55. system(sprintf('rm -rf %s', escapeshellarg($installDir)));
  56. }
  57. }
  58. echo "> Installing/Updating $name\n";
  59. // url
  60. if (!isset($dep['git'])) {
  61. exit(sprintf('The "git" value for the "%s" dependency must be set.', $name));
  62. }
  63. $url = $dep['git'];
  64. if (!is_dir($installDir)) {
  65. system(sprintf('git clone %s %s', escapeshellarg($url), escapeshellarg($installDir)));
  66. }
  67. system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev)));
  68. if ('update' === $command) {
  69. ob_start();
  70. system(sprintf('cd %s && git log -n 1 --format=%%H', escapeshellarg($installDir)));
  71. $newversions[] = trim($name.' '.ob_get_clean());
  72. }
  73. }
  74. // update?
  75. if ('update' === $command) {
  76. file_put_contents($rootDir.'/deps.lock', implode("\n", $newversions));
  77. }
  78. // php on windows can't use the shebang line from system()
  79. $interpreter = PHP_OS == 'WINNT' ? 'php.exe' : '';
  80. // Update the bootstrap files
  81. system(sprintf('%s %s', $interpreter, escapeshellarg($rootDir.'/vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php')));
  82. // Update assets
  83. system(sprintf('%s %s assets:install %s', $interpreter, escapeshellarg($rootDir.'/app/console'), escapeshellarg($rootDir.'/web/')));
  84. // Remove the cache
  85. system(sprintf('%s %s cache:clear --no-warmup', $interpreter, escapeshellarg($rootDir.'/app/console')));