mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 22:43:19 +00:00
Refactor command line utilities
This commit is contained in:
82
lib/Alchemy/Phrasea/Command/Developer/BowerInstall.php
Normal file
82
lib/Alchemy/Phrasea/Command/Developer/BowerInstall.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?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;
|
||||
|
||||
use Alchemy\Phrasea\Command\Command;
|
||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class BowerInstall extends Command
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('dependencies:bower');
|
||||
|
||||
$this
|
||||
->setDescription('Install 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);
|
||||
}
|
||||
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$bower = $this->container['driver.bower'];
|
||||
$output->writeln("Using <info>".$bower->getProcessBuilderFactory()->getBinary()."</info> for driver");
|
||||
|
||||
$version = trim($bower->command('-v'));
|
||||
|
||||
if (!version_compare('1.0.0-alpha.1', $version, '<=')) {
|
||||
throw new RuntimeException(sprintf(
|
||||
'Bower version 1.0.0-alpha.1 is required (version %s provided), please install bower-canary : `npm install -g bower-canary`', $version
|
||||
));
|
||||
}
|
||||
|
||||
$attempts = $input->getOption('attempts');
|
||||
|
||||
if (0 >= $attempts) {
|
||||
throw new InvalidArgumentException('Attempts number should be a positive value.');
|
||||
}
|
||||
|
||||
$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>");
|
||||
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$success) {
|
||||
throw new RuntimeException('Unable to install bower dependencies');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
62
lib/Alchemy/Phrasea/Command/Developer/ComposerInstall.php
Normal file
62
lib/Alchemy/Phrasea/Command/Developer/ComposerInstall.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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;
|
||||
|
||||
use Alchemy\Phrasea\Command\Command;
|
||||
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ComposerInstall extends Command
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('dependencies:composer');
|
||||
|
||||
$this
|
||||
->setDescription('Install composer 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');
|
||||
}
|
||||
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$composer = $this->container['driver.composer'];
|
||||
|
||||
$output->write("Updating composer... ");
|
||||
$composer->command('self-update');
|
||||
$output->writeln("<info>OK</info>");
|
||||
|
||||
$commands = array('install', '--optimize-autoloader');
|
||||
if ($input->getOption('prefer-source')) {
|
||||
$commands[] = '--prefer-source';
|
||||
}
|
||||
|
||||
try {
|
||||
if ($input->getOption('no-dev')) {
|
||||
$output->write("Installing dependencies <info>without</info> developer packages ");
|
||||
$composer->command(array_merge($commands, array('--no-dev')));
|
||||
$output->writeln("<info>OK</info>");
|
||||
} else {
|
||||
$output->write("Installing dependencies <info>with</info> developer packages ");
|
||||
$composer->command(array_merge($commands, array('--dev')));
|
||||
$output->writeln("<info>OK</info>");
|
||||
}
|
||||
} catch (ExecutionFailureException $e) {
|
||||
throw new RuntimeException('Unable to install bower dependencies', $e->getCode(), $e);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
43
lib/Alchemy/Phrasea/Command/Developer/InstallAll.php
Normal file
43
lib/Alchemy/Phrasea/Command/Developer/InstallAll.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
|
||||
use Alchemy\Phrasea\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class InstallAll extends Command
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('dependencies:all');
|
||||
|
||||
$this
|
||||
->setDescription('Install 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);
|
||||
}
|
||||
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ret = 0;
|
||||
|
||||
$ret += $this->container['console']->get('dependencies:bower')->execute($input, $output);
|
||||
$ret += $this->container['console']->get('dependencies:composer')->execute($input, $output);
|
||||
$ret += $this->container['console']->get('assets:build-javascript')->execute($input, $output);
|
||||
$ret += $this->container['console']->get('assets:compile-less')->execute($input, $output);
|
||||
|
||||
return min($ret, 255);
|
||||
}
|
||||
}
|
@@ -52,6 +52,7 @@ class JavascriptBuilder extends Command
|
||||
)
|
||||
);
|
||||
|
||||
$output->writeln('Building JavaScript assets');
|
||||
foreach ($files as $target => $sources) {
|
||||
$this->buildJavascript($input, $output, $target, $sources);
|
||||
|
||||
@@ -62,7 +63,7 @@ class JavascriptBuilder extends Command
|
||||
|
||||
private function buildJavascript(InputInterface $input, OutputInterface $output, $target, $sources)
|
||||
{
|
||||
$output->writeln("Building <info>".basename($target)."</info>");
|
||||
$output->writeln("\t".basename($target));
|
||||
$this->container['filesystem']->remove($target);
|
||||
|
||||
$process = ProcessBuilder::create(array_merge(array('cat'), $sources))->getProcess();
|
||||
@@ -81,19 +82,11 @@ class JavascriptBuilder extends Command
|
||||
|
||||
private function buildMinifiedJavascript(InputInterface $input, OutputInterface $output, $target, $source)
|
||||
{
|
||||
$output->writeln("Building <info>".basename($target)."</info>");
|
||||
$output->writeln("\t".basename($target));
|
||||
$this->container['filesystem']->remove($target);
|
||||
|
||||
$process = ProcessBuilder::create(array('uglifyjs', $source, '-nc'))->getProcess();
|
||||
if ($input->getOption('verbose')) {
|
||||
$output->writeln("Executing ".$process->getCommandLine()."\n");
|
||||
}
|
||||
$process->run();
|
||||
$output = $this->container['driver.uglifyjs']->command(array($source, '-nc'));
|
||||
|
||||
if (!$process->isSuccessFul()) {
|
||||
throw new RuntimeException(sprintf('Failed to generate %s', $target));
|
||||
}
|
||||
|
||||
file_put_contents($target, $process->getOutput());
|
||||
file_put_contents($target, $output);
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,6 @@
|
||||
namespace Alchemy\Phrasea\Command\Developer;
|
||||
|
||||
use Alchemy\Phrasea\Command\Command;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
@@ -33,34 +32,13 @@ class LessCompiler extends Command
|
||||
*/
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$copies = array(
|
||||
$this->container['root.path'] . '/www/assets/bootstrap/img/glyphicons-halflings-white.png' => $this->container['root.path'] . '/www/skins/build/bootstrap/img/glyphicons-halflings-white.png',
|
||||
$this->container['root.path'] . '/www/assets/bootstrap/img/glyphicons-halflings.png' => $this->container['root.path'] . '/www/skins/build/bootstrap/img/glyphicons-halflings.png',
|
||||
);
|
||||
|
||||
foreach ($copies as $source => $target) {
|
||||
foreach ($this->container['phraseanet.less-assets'] as $source => $target) {
|
||||
$this->container['filesystem']->mkdir(dirname($target));
|
||||
$this->container['filesystem']->copy($source, $target);
|
||||
}
|
||||
|
||||
$files = array(
|
||||
$this->container['root.path'] . '/www/skins/login/less/login.less' => $this->container['root.path'] . '/www/skins/build/login.css',
|
||||
$this->container['root.path'] . '/www/skins/account/account.less' => $this->container['root.path'] . '/www/skins/build/account.css',
|
||||
$this->container['root.path'] . '/www/assets/bootstrap/less/bootstrap.less' => $this->container['root.path'] . '/www/skins/build/bootstrap/css/bootstrap.css',
|
||||
$this->container['root.path'] . '/www/assets/bootstrap/less/responsive.less' => $this->container['root.path'] . '/www/skins/build/bootstrap/css/bootstrap-responsive.css',
|
||||
);
|
||||
|
||||
$output->writeln('Building Assets...');
|
||||
|
||||
try {
|
||||
$this->container['phraseanet.less-builder']->build($files);
|
||||
} catch (RuntimeException $e) {
|
||||
$output->writeln(sprintf('<error>Could not build less files %s</error>', $e->getMessage()));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('<info>Build done !</info>');
|
||||
$output->writeln('Building LESS assets');
|
||||
$this->container['phraseanet.less-builder']->build($this->container['phraseanet.less-mapping'], $output);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
42
lib/Alchemy/Phrasea/Command/Developer/Utils/BowerDriver.php
Normal file
42
lib/Alchemy/Phrasea/Command/Developer/Utils/BowerDriver.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 BowerDriver extends AbstractBinary
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'bower';
|
||||
}
|
||||
|
||||
/**
|
||||
* @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('bower.binaries', array('bower'));
|
||||
|
||||
return static::load($binaries, $logger, $conf);
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?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 ComposerDriver extends AbstractBinary
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'composer';
|
||||
}
|
||||
|
||||
public static function create($conf = array(), LoggerInterface $logger = null)
|
||||
{
|
||||
if (!$conf instanceof ConfigurationInterface) {
|
||||
$conf = new Configuration($conf);
|
||||
}
|
||||
|
||||
$binaries = $conf->get('composer.binaries', array('composer'));
|
||||
|
||||
return static::load($binaries, $logger, $conf);
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?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 UglifyJsDriver extends AbstractBinary
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'uglifyjs';
|
||||
}
|
||||
|
||||
public static function create($conf = array(), LoggerInterface $logger = null)
|
||||
{
|
||||
if (!$conf instanceof ConfigurationInterface) {
|
||||
$conf = new Configuration($conf);
|
||||
}
|
||||
|
||||
$binaries = $conf->get('uglifyjs.binaries', array('uglifyjs'));
|
||||
|
||||
return static::load($binaries, $logger, $conf);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user