Skip to content
Extraits de code Groupes Projets
Valider 210724e9 rédigé par JamesRezo's avatar JamesRezo :tada:
Parcourir les fichiers

feat(mode-dev): composer local

parent deb794cb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
<?php
namespace Spip\Composer\Command;
use Composer\Pcre\Preg;
use Composer\Util\Platform;
use Spip\Composer\SpipPaths;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'spip:local',
description: 'Allows running commands in a local context',
aliases: ['local', 'l']
)]
/**
* Inspired by Composer\Command\GlobalCommand
* @since 0.6.0
*/
class LocalCommand extends AbstractSpipCommand
{
protected function configure(): void
{
$this
->setDefinition([
new InputArgument('command-name', InputArgument::REQUIRED, ''),
new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''),
])
->setHelp(
'Use this command as a wrapper to run other Composer commands' .
' within the local context of a ' . SpipPaths::LOCAL_COMPOSER . ' composer file.
');
}
public function run(InputInterface $input, OutputInterface $output): int
{
$rootDir = $this->getRootDir();
$composerFile = $rootDir . '/' . SpipPaths::LOCAL_COMPOSER;
if (!\file_exists($composerFile)) {
$output->writeln('Creating ' . SpipPaths::LOCAL_COMPOSER . ' ...');
\copy($rootDir.'/composer.json', $composerFile);
}
Platform::putEnv('COMPOSER', SpipPaths::LOCAL_COMPOSER);
// extract real command name
$tokens = Preg::split('{\s+}', $input->__toString());
$args = [];
foreach ($tokens as $token) {
if ($token && $token[0] !== '-') {
$args[] = $token;
if (count($args) >= 2) {
break;
}
}
}
// show help for this command if no command was found
if (count($args) < 2) {
return parent::run($input, $output);
}
// create new input without "local" command prefix
$input = new StringInput(Preg::replace('{\bl(?:o(?:c(?:a(?:l)?)?)?)?\b}', '', $input->__toString(), 1));
$this->getApplication()->resetComposer();
return $this->getApplication()->run($input, $output);
}
/**
* @inheritDoc
*/
public function isProxyCommand(): bool
{
return true;
}
}
......@@ -3,6 +3,7 @@
namespace Spip\Composer;
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
use Spip\Composer\Command\LocalCommand;
use Spip\Composer\Command\ModeDevCommand;
/**
......@@ -16,6 +17,7 @@ class CommandProvider implements CommandProviderCapability
public function getCommands()
{
return [
new LocalCommand(),
new ModeDevCommand(),
];
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter