Update bower install command

This commit is contained in:
Nicolas Le Goff
2013-08-13 13:01:56 +02:00
parent 15c56fab2f
commit fa1174d6e3
5 changed files with 113 additions and 25 deletions

View File

@@ -28,12 +28,20 @@ class BowerInstall extends Command
$this $this
->setDescription('Installs bower dependencies') ->setDescription('Installs bower dependencies')
->addOption('no-dev', 'd', InputOption::VALUE_NONE, 'Do not install dev dependencies') ->addOption('no-dev', 'd', InputOption::VALUE_NONE, 'Do not install dev dependencies')
->addOption('attempts', 'a', InputOption::VALUE_REQUIRED, 'Number of attempts to install dependencies.', 4); ->addOption(
'prefer-dist',
null,
InputOption::VALUE_NONE,
'If defined forces installation from dist package'
);
} }
protected function doExecute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$grunt = $this->container['driver.grunt'];
$bower = $this->container['driver.bower']; $bower = $this->container['driver.bower'];
$output->writeln("Using <info>".$grunt->getProcessBuilderFactory()->getBinary()."</info> for driver");
$output->writeln("Using <info>".$bower->getProcessBuilderFactory()->getBinary()."</info> for driver"); $output->writeln("Using <info>".$bower->getProcessBuilderFactory()->getBinary()."</info> for driver");
$version = trim($bower->command('-v')); $version = trim($bower->command('-v'));
@@ -44,33 +52,29 @@ class BowerInstall extends Command
)); ));
} }
$attempts = $input->getOption('attempts'); $version = trim($grunt->command('--version'));
if (0 >= $attempts) { if (!version_compare('0.4.0', substr($version, -5), '<=')) {
throw new InvalidArgumentException('Attempts number should be a positive value.'); throw new RuntimeException(sprintf(
'Grunt version >= 0.4.0 is required (version %s provided), please install grunt `http://gruntjs.com/getting-started`', $version
));
} }
$output->write("Cleaning bower cache... "); if ($input->getOption('prefer-dist')) {
$bower->command(array('cache', 'clean')); $output->write("Cleaning bower cache... ");
$output->writeln("<info>OK</info>"); $bower->command(array('cache', 'clean'));
$output->writeln("<info>OK</info>");
$output->write("Removing assets... "); }
$this->container['filesystem']->remove($this->container['root.path'] . '/www/assets');
$output->writeln("<info>OK</info>");
$success = false; $success = false;
$n = 1;
while ($attempts > 0) { try {
try { $output->write("\rInstalling assets...");
$output->write("\rInstalling assets (attempt #$n)..."); $grunt->command('build-assets');
$bower->command($input->getOption('no-dev') ? array('install', '--production') : 'install'); $success = true;
$success = true; $output->writeln("<info>OK</info>");
$output->writeln("<info>OK</info>"); } catch (ExecutionFailureException $e) {
break;
} catch (ExecutionFailureException $e) {
$attempts--;
$n++;
}
} }
if (!$success) { if (!$success) {

View File

@@ -26,7 +26,12 @@ class InstallAll extends Command
->setDescription('Installs all dependencies') ->setDescription('Installs all dependencies')
->addOption('no-dev', 'd', InputOption::VALUE_NONE, 'Do not install dev dependencies') ->addOption('no-dev', 'd', InputOption::VALUE_NONE, 'Do not install dev dependencies')
->addOption('prefer-source', 'p', InputOption::VALUE_NONE, 'Use the --prefer-source composer option') ->addOption('prefer-source', 'p', InputOption::VALUE_NONE, 'Use the --prefer-source composer option')
->addOption('attempts', 'a', InputOption::VALUE_REQUIRED, 'Number of attempts to install bower dependencies.', 4); ->addOption(
'prefer-dist',
null,
InputOption::VALUE_NONE,
'If defined forces installation from bower dist package'
);
} }
protected function doExecute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)

View File

@@ -0,0 +1,42 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\Developer\Utils;
use Alchemy\BinaryDriver\AbstractBinary;
use Alchemy\BinaryDriver\Configuration;
use Alchemy\BinaryDriver\ConfigurationInterface;
use Psr\Log\LoggerInterface;
class GruntDriver extends AbstractBinary
{
public function getName()
{
return 'grunt';
}
/**
* @param array|ConfigurationInterface $conf
* @param LoggerInterface $logger
*
* @return BowerDriver
*/
public static function create($conf = array(), LoggerInterface $logger = null)
{
if (!$conf instanceof ConfigurationInterface) {
$conf = new Configuration($conf);
}
$binaries = $conf->get('grunt.binaries', array('grunt'));
return static::load($binaries, $logger, $conf);
}
}

View File

@@ -12,9 +12,10 @@
namespace Alchemy\Phrasea\Core\CLIProvider; namespace Alchemy\Phrasea\Core\CLIProvider;
use Alchemy\Phrasea\Command\Developer\Utils\BowerDriver; use Alchemy\Phrasea\Command\Developer\Utils\BowerDriver;
use Alchemy\Phrasea\Command\Developer\Utils\UglifyJsDriver;
use Alchemy\Phrasea\Command\Developer\Utils\ComposerDriver; use Alchemy\Phrasea\Command\Developer\Utils\ComposerDriver;
use Alchemy\Phrasea\Command\Developer\Utils\GruntDriver;
use Alchemy\Phrasea\Command\Developer\Utils\RecessDriver; use Alchemy\Phrasea\Command\Developer\Utils\RecessDriver;
use Alchemy\Phrasea\Command\Developer\Utils\UglifyJsDriver;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
use Silex\Application; use Silex\Application;
use Silex\ServiceProviderInterface; use Silex\ServiceProviderInterface;
@@ -85,6 +86,16 @@ class CLIDriversServiceProvider implements ServiceProviderInterface
return UglifyJsDriver::create(array('uglifyjs.binaries' => $uglifyJsBinary), $app['monolog']); return UglifyJsDriver::create(array('uglifyjs.binaries' => $uglifyJsBinary), $app['monolog']);
}); });
$app['driver.grunt'] = $app->share(function (Application $app) {
$gruntBinary = $app['driver.binary-finder']('grunt', 'grunt_binary');
if (null === $gruntBinary) {
throw new RuntimeException('Unable to find grunt executable.');
}
return GruntDriver::create(array('grunt.binaries' => $gruntBinary), $app['monolog']);
});
} }
public function boot(Application $app) public function boot(Application $app)

View File

@@ -0,0 +1,26 @@
<?php
namespace Alchemy\Tests\Phrasea\Command\Developper\Utils;
use Alchemy\Phrasea\Command\Developer\Utils\GruntDriver;
use Symfony\Component\Process\PhpExecutableFinder;
class GruntDriverTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
$driver = GruntDriver::create();
$this->assertInstanceOf('Alchemy\Phrasea\Command\Developer\Utils\GruntDriver', $driver);
$this->assertEquals('grunt', $driver->getName());
}
public function testCreateWithCustomBinary()
{
$finder = new PhpExecutableFinder();
$php = $finder->find();
$driver = GruntDriver::create(array('grunt.binaries' => $php));
$this->assertInstanceOf('Alchemy\Phrasea\Command\Developer\Utils\GruntDriver', $driver);
$this->assertEquals($php, $driver->getProcessBuilderFactory()->getBinary());
}
}