Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

126 рядки
3.8KB

  1. #!/usr/bin/env php
  2. <?php
  3. define('LATEST_RELEASE', '^4.0');
  4. define('GITHUB_URL', 'https://github.com/codeigniter4/codeigniter4');
  5. /*
  6. * --------------------------------------------------------------------
  7. * Stability Toggle
  8. * --------------------------------------------------------------------
  9. * Use this script to toggle the CodeIgniter dependency between the
  10. * latest stable release and the most recent development update.
  11. *
  12. * Usage: php builds [release|development]
  13. */
  14. // Determine the requested stability
  15. if (empty($argv[1]) || ! in_array($argv[1], ['release', 'development'], true)) {
  16. echo 'Usage: php builds [release|development]' . PHP_EOL;
  17. exit;
  18. }
  19. $dev = $argv[1] === 'development';
  20. $modified = [];
  21. // Locate each file and update it for the requested stability
  22. $file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json';
  23. if (is_file($file)) {
  24. $contents = file_get_contents($file);
  25. if ((string) $contents !== '') {
  26. $array = json_decode($contents, true);
  27. if (is_array($array)) {
  28. if ($dev) {
  29. $array['minimum-stability'] = 'dev';
  30. $array['prefer-stable'] = true;
  31. $array['repositories'] ??= [];
  32. $found = false;
  33. foreach ($array['repositories'] as $repository) {
  34. if ($repository['url'] === GITHUB_URL) {
  35. $found = true;
  36. break;
  37. }
  38. }
  39. if (! $found) {
  40. $array['repositories'][] = [
  41. 'type' => 'vcs',
  42. 'url' => GITHUB_URL,
  43. ];
  44. }
  45. $array['require']['codeigniter4/codeigniter4'] = 'dev-develop';
  46. unset($array['require']['codeigniter4/framework']);
  47. } else {
  48. unset($array['minimum-stability']);
  49. if (isset($array['repositories'])) {
  50. foreach ($array['repositories'] as $i => $repository) {
  51. if ($repository['url'] === GITHUB_URL) {
  52. unset($array['repositories'][$i]);
  53. break;
  54. }
  55. }
  56. if (empty($array['repositories'])) {
  57. unset($array['repositories']);
  58. }
  59. }
  60. $array['require']['codeigniter4/framework'] = LATEST_RELEASE;
  61. unset($array['require']['codeigniter4/codeigniter4']);
  62. }
  63. file_put_contents($file, json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);
  64. $modified[] = $file;
  65. } else {
  66. echo 'Warning: Unable to decode composer.json! Skipping...' . PHP_EOL;
  67. }
  68. } else {
  69. echo 'Warning: Unable to read composer.json! Skipping...' . PHP_EOL;
  70. }
  71. }
  72. $files = [
  73. __DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php',
  74. __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist',
  75. __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml',
  76. ];
  77. foreach ($files as $file) {
  78. if (is_file($file)) {
  79. $contents = file_get_contents($file);
  80. if ($dev) {
  81. $contents = str_replace('vendor/codeigniter4/framework', 'vendor/codeigniter4/codeigniter4', $contents);
  82. } else {
  83. $contents = str_replace('vendor/codeigniter4/codeigniter4', 'vendor/codeigniter4/framework', $contents);
  84. }
  85. file_put_contents($file, $contents);
  86. $modified[] = $file;
  87. }
  88. }
  89. if ($modified === []) {
  90. echo 'No files modified.' . PHP_EOL;
  91. } else {
  92. echo 'The following files were modified:' . PHP_EOL;
  93. foreach ($modified as $file) {
  94. echo " * {$file}" . PHP_EOL;
  95. }
  96. echo 'Run `composer update` to sync changes with your vendor folder.' . PHP_EOL;
  97. }