Skip to content

Commit

Permalink
CouscousPHP#68 Fixed composer installation by removing the dependency…
Browse files Browse the repository at this point in the history
… to BowerPHP
  • Loading branch information
mnapoli committed Dec 26, 2014
1 parent ecc201d commit ba7f57e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"erusev/parsedown-extra": "~0.2.0",
"phine/phar": "~1.0",
"mnapoli/front-yaml": "~1.0",
"mnapoli/php-di": "~4.4",
"beelab/bowerphp": "1.0.x-dev"
"mnapoli/php-di": "~4.4"
},
"require-dev": {
"phpunit/phpunit": "~4.3"
Expand Down
3 changes: 1 addition & 2 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,4 @@ A good rule of thumb is: **if it works on GitHub.com, it will work with Couscous
If a `bower.json` file is present in the `website/` directory, dependencies will be
installed automatically.

You don't need to have Bower installed on your machine, Couscous internally uses
[BowerPHP](http://bowerphp.org/).
In that case, you need [to have Bower installed](http://bower.io/). If you don't have a `bower.json`, you don't need to install Bower.
10 changes: 6 additions & 4 deletions src/CommandRunner/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ class CommandRunner
*
* @param string $command The command to be executed.
*
* @return mixed
* @return string Output of the command.
*/
public function run($command)
{
exec($command . ' 2>&1', $commandOutput, $returnValue);
exec($command . ' 2>&1', $output, $returnValue);

$output = implode(PHP_EOL, $output);

if ($returnValue !== 0) {
throw new CommandException(implode(PHP_EOL, $commandOutput));
throw new CommandException($output);
}

return $commandOutput;
return $output;
}
}
46 changes: 28 additions & 18 deletions src/Module/Bower/Step/RunBowerInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,61 @@

namespace Couscous\Module\Bower\Step;

use Bowerphp\Command\InstallCommand;
use Couscous\CommandRunner\CommandRunner;
use Couscous\Model\Repository;
use Couscous\Step;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

/**
* Execute the scripts that were set in "after" in the configuration.
* Run Bower install.
*
* @author Matthieu Napoli <matthieu@mnapoli.fr>
*/
class RunBowerInstall implements \Couscous\Step
class RunBowerInstall implements Step
{
/**
* @var Filesystem
*/
private $filesystem;

public function __construct(Filesystem $filesystem)
/**
* @var CommandRunner
*/
private $commandRunner;

public function __construct(Filesystem $filesystem, CommandRunner $commandRunner)
{
$this->filesystem = $filesystem;
$this->commandRunner = $commandRunner;
}

public function __invoke(Repository $repository, OutputInterface $output)
{
if ($repository->regenerate) {
return;
}
if (! $repository->metadata['template.directory']) {
return;
}

if (! $this->filesystem->exists($repository->metadata['template.directory'] . '/bower.json')) {
if ($repository->regenerate || !$this->hasBowerJson($repository)) {
return;
}

$output->writeln('Executing <info>bower install</info>');

$workingDir = getcwd();
chdir($repository->metadata['template.directory']);
$result = $this->commandRunner->run(sprintf(
'cd "%s" && bower install',
$repository->metadata['template.directory']
));

if ($result) {
$output->writeln($result);
}
}

private function hasBowerJson(Repository $repository)
{
if (! $repository->metadata['template.directory']) {
return false;
}

$command = new InstallCommand();
$command->run(new ArrayInput([]), $output);
$filename = $repository->metadata['template.directory'] . '/bower.json';

chdir($workingDir);
return $this->filesystem->exists($filename);
}
}
2 changes: 1 addition & 1 deletion tests/FunctionalTest/CommandRunner/CommandRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function successful_command_execution_should_return_output()

$output = $this->commandRunner->run($command);

$this->assertEquals($expected, $output[0]);
$this->assertEquals($expected, $output);
}

/**
Expand Down
1 change: 1 addition & 0 deletions website/bower.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "couscous",
"dependencies": {
"bootstrap": "~3.2.0",
"fontawesome": "~4.0",
Expand Down
2 changes: 1 addition & 1 deletion website/home.twig
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ php couscous.phar preview</code></pre>
Fenced code blocks
</p>
<p>
Embedded <a href="http://bower.io/">Bower</a>
<a href="http://bower.io/">Bower</a> support
</p>
<p>
Responsive default templates
Expand Down

0 comments on commit ba7f57e

Please sign in to comment.