Skip to content

Commit

Permalink
#14: first attempt at requirementss
Browse files Browse the repository at this point in the history
  • Loading branch information
yiendos committed May 15, 2017
1 parent 2c20024 commit 0449d57
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/Joomlatools/Console/Command/Extension/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Install extends AbstractSite
{
protected $extensions = array();

protected $composer = false;

protected function configure()
{
parent::configure();
Expand Down Expand Up @@ -52,14 +54,59 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->extensions = (array) $input->getArgument('extension');

$this->check($input, $output);
$this->install($input, $output);

foreach($input->getArgument('extension') as $extension)
{
//@todo check syntax of composer installs
if(strpos($extension, 'vendor/') !== false){
$this->composer = true;
}
}

if ($this->composer){
$this->composer_install($input, $output);
}else{
$this->install($input, $output);
}
}

public function check(InputInterface $input, OutputInterface $output)
{
if (!file_exists($this->target_dir)) {
throw new \RuntimeException(sprintf('Site not found: %s', $this->site));
}

if ($this->composer)
{
$result = shell_exec('composer -v > /dev/null 2>&1 || { echo "false"; }');

if (trim($result) == 'false' && !file_exists($this->target_dir . 'composer.phar'))
{
$output->writeln('<error>dude you need composer installed</error>');
exit();
}
}
}

public function composer_install(InputInterface $input, OutputInterface $output)
{
chdir($this->target_dir);

$extensions = $input->getArgument('extension');

foreach ($extensions as $extension)
{
//@todo need to double check the syntax for composer require
$result = shell_exec(sprintf('composer require "%s"', $extension));

if ($result == false)
{
$output->writeln('<error>Warning Will Robinson warning');
exit();
}
}

$output->writeln('<info>' . count($extensions) . ' dependencies installed');
}

public function install(InputInterface $input, OutputInterface $output)
Expand Down

0 comments on commit 0449d57

Please sign in to comment.