gpm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env php
  2. <?php
  3. define('GRAV_CLI', true);
  4. if (!file_exists(__DIR__ . '/../vendor')){
  5. require_once __DIR__ . '/../system/src/Grav/Common/Composer.php';
  6. }
  7. use Grav\Common\Composer;
  8. use Grav\Common\Config\Setup;
  9. if (!file_exists(__DIR__ . '/../vendor')){
  10. // Before we can even start, we need to run composer first
  11. $composer = Composer::getComposerExecutor();
  12. echo "Preparing to install vendor dependencies...\n\n";
  13. echo system($composer.' --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist -o install');
  14. echo "\n\n";
  15. }
  16. use Symfony\Component\Console\Application;
  17. use Grav\Common\Grav;
  18. $autoload = require_once(__DIR__ . '/../vendor/autoload.php');
  19. if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
  20. exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
  21. }
  22. if (!ini_get('date.timezone')) {
  23. date_default_timezone_set('UTC');
  24. }
  25. if (!file_exists(ROOT_DIR . 'index.php')) {
  26. exit('FATAL: Must be run from ROOT directory of Grav!');
  27. }
  28. if (!function_exists('curl_version')) {
  29. exit('FATAL: GPM requires PHP Curl module to be installed');
  30. }
  31. $climate = new League\CLImate\CLImate;
  32. $climate->arguments->add([
  33. 'environment' => [
  34. 'prefix' => 'e',
  35. 'longPrefix' => 'env',
  36. 'description' => 'Configuration Environment',
  37. 'defaultValue' => 'localhost'
  38. ]
  39. ]);
  40. $climate->arguments->parse();
  41. $environment = $climate->arguments->get('environment');
  42. // Set up environment based on params.
  43. Setup::$environment = $environment;
  44. $grav = Grav::instance(array('loader' => $autoload));
  45. $grav['uri']->init();
  46. $grav['config']->init();
  47. $grav['streams'];
  48. $app = new Application('Grav Package Manager', GRAV_VERSION);
  49. $app->addCommands(array(
  50. new \Grav\Console\Gpm\IndexCommand(),
  51. new \Grav\Console\Gpm\VersionCommand(),
  52. new \Grav\Console\Gpm\InfoCommand(),
  53. new \Grav\Console\Gpm\InstallCommand(),
  54. new \Grav\Console\Gpm\UninstallCommand(),
  55. new \Grav\Console\Gpm\UpdateCommand(),
  56. new \Grav\Console\Gpm\SelfupgradeCommand(),
  57. new \Grav\Console\Gpm\DirectInstallCommand(),
  58. ));
  59. $app->run();