diff --git a/bin/grav b/bin/grav index 2b754f153..2d412dd36 100755 --- a/bin/grav +++ b/bin/grav @@ -9,7 +9,7 @@ if (version_compare($ver = PHP_VERSION, $req = '5.4.0', '<')) { if (!file_exists(__DIR__ . '/../vendor')){ // Before we can even start, we need to run composer first echo "Preparing to install vendor dependencies...\n\n"; - echo system('php bin/composer.phar --working-dir="'.__DIR__.'/../" --no-interaction install'); + echo system('php bin/composer.phar --working-dir="'.__DIR__.'/../" --no-interaction --no-dev --prefer-dist install'); echo "\n\n"; } @@ -28,6 +28,7 @@ if (!file_exists(ROOT_DIR . 'index.php')) { $app = new Application('Grav CLI Application', '0.1.0'); $app->addCommands(array( new Grav\Console\Cli\InstallCommand(), + new Grav\Console\Cli\ComposerCommand(), new Grav\Console\Cli\SandboxCommand(), new Grav\Console\Cli\CleanCommand(), new Grav\Console\Cli\ClearCacheCommand(), diff --git a/system/src/Grav/Console/Cli/ComposerCommand.php b/system/src/Grav/Console/Cli/ComposerCommand.php new file mode 100644 index 000000000..3a28718ac --- /dev/null +++ b/system/src/Grav/Console/Cli/ComposerCommand.php @@ -0,0 +1,80 @@ +setName("composer") + ->addOption( + 'install', + 'i', + InputOption::VALUE_NONE, + 'install the dependencies' + ) + ->addOption( + 'update', + 'u', + InputOption::VALUE_NONE, + 'update the dependencies' + ) + ->setDescription("Updates the composer vendordependencies needed by Grav.") + ->setHelp('The composer command updates the composer vendordependencies needed by Grav'); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $action = 'update'; + + if ($input->getOption('install')) { + $action = 'install'; + } + + // Updates composer first + $output->writeln("\nInstalling vendor dependencies"); + $output->writeln($this->composerUpdate(GRAV_ROOT, $action)); + } + +} diff --git a/system/src/Grav/Console/Cli/InstallCommand.php b/system/src/Grav/Console/Cli/InstallCommand.php index b316e5701..8aead008f 100644 --- a/system/src/Grav/Console/Cli/InstallCommand.php +++ b/system/src/Grav/Console/Cli/InstallCommand.php @@ -1,6 +1,7 @@ getOption('symlink')) { // Updates composer first $output->writeln("\nInstalling vendor dependencies"); - $output->writeln(system('php bin/composer.phar --working-dir="'.$this->destination.'" --no-interaction --no-dev --prefer-dist -o install')); + $output->writeln($this->composerUpdate(GRAV_ROOT, 'install')); $this->gitclone($output); } else { diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 42c65d495..a2e80b6e8 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -83,6 +83,11 @@ trait ConsoleTrait } } + public function composerUpdate($path, $action = 'install') + { + return system('php bin/composer.phar --working-dir="'.$path.'" --no-interaction --no-dev --prefer-dist -o '. $action); + } + /** * @param array $all * diff --git a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php index 29eb77d58..5ed68ced2 100644 --- a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php +++ b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php @@ -154,7 +154,7 @@ class SelfupgradeCommand extends Command } $this->output->writeln("\nInstalling vendor dependencies"); - $this->output->writeln(system('php bin/composer.phar --working-dir="'.GRAV_ROOT.'" --no-interaction --no-dev --prefer-dist -o install')); + $this->output->writeln($this->composerUpdate(GRAV_ROOT, 'update')); // clear cache after successful upgrade $this->clearCache('all');