mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Update bower install command
This commit is contained in:
@@ -28,12 +28,20 @@ class BowerInstall extends Command
|
||||
$this
|
||||
->setDescription('Installs bower 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)
|
||||
{
|
||||
$grunt = $this->container['driver.grunt'];
|
||||
$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");
|
||||
|
||||
$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) {
|
||||
throw new InvalidArgumentException('Attempts number should be a positive value.');
|
||||
if (!version_compare('0.4.0', substr($version, -5), '<=')) {
|
||||
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... ");
|
||||
$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>");
|
||||
if ($input->getOption('prefer-dist')) {
|
||||
$output->write("Cleaning bower cache... ");
|
||||
$bower->command(array('cache', 'clean'));
|
||||
$output->writeln("<info>OK</info>");
|
||||
}
|
||||
|
||||
$success = false;
|
||||
$n = 1;
|
||||
while ($attempts > 0) {
|
||||
try {
|
||||
$output->write("\rInstalling assets (attempt #$n)...");
|
||||
$bower->command($input->getOption('no-dev') ? array('install', '--production') : 'install');
|
||||
$success = true;
|
||||
$output->writeln("<info>OK</info>");
|
||||
break;
|
||||
} catch (ExecutionFailureException $e) {
|
||||
$attempts--;
|
||||
$n++;
|
||||
}
|
||||
|
||||
try {
|
||||
$output->write("\rInstalling assets...");
|
||||
$grunt->command('build-assets');
|
||||
$success = true;
|
||||
$output->writeln("<info>OK</info>");
|
||||
} catch (ExecutionFailureException $e) {
|
||||
|
||||
}
|
||||
|
||||
if (!$success) {
|
||||
|
@@ -26,7 +26,12 @@ class InstallAll extends Command
|
||||
->setDescription('Installs all 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('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)
|
||||
|
42
lib/Alchemy/Phrasea/Command/Developer/Utils/GruntDriver.php
Normal file
42
lib/Alchemy/Phrasea/Command/Developer/Utils/GruntDriver.php
Normal 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);
|
||||
}
|
||||
}
|
@@ -12,9 +12,10 @@
|
||||
namespace Alchemy\Phrasea\Core\CLIProvider;
|
||||
|
||||
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\GruntDriver;
|
||||
use Alchemy\Phrasea\Command\Developer\Utils\RecessDriver;
|
||||
use Alchemy\Phrasea\Command\Developer\Utils\UglifyJsDriver;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Silex\Application;
|
||||
use Silex\ServiceProviderInterface;
|
||||
@@ -85,6 +86,16 @@ class CLIDriversServiceProvider implements ServiceProviderInterface
|
||||
|
||||
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)
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user