Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Spip\Composer\Command;
use Composer\Config\JsonConfigSource;
use Composer\Factory;
use Composer\Json\JsonFile;
use Spip\Composer\Config\PreferredInstall;
use Spip\Composer\Git\RemoteUrls;
use Spip\Composer\SpipPaths;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'spip:set-ssh-url',
description: 'The install method Composer will prefer to use',
aliases: ['mode-dev']
)]
/**
* Turns remote https urls of source preferred-install packages into ssh urls
* @since 0.6.0
*/
class ModeDevCommand extends AbstractSpipCommand
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$composerFile = Factory::getComposerFile();
$composer = $this->tryComposer();
$output->writeln('Looking into ' . $composerFile);
if (SpipPaths::LOCAL_COMPOSER == $composerFile) {
$tmp = $composer->getConfig()->get('preferred-install');
if (is_string($tmp)) {
$tmp = [$tmp];
}
if(empty(\array_intersect(['spip/*' => 'source'], $tmp))) {
$output->writeln('<warning>Missing preferred-install in '.$composerFile.'</warning>');
if (!$this->getIO()->askConfirmation('<info>Adding default preferred-install ?</info> [<comment>Y,n</comment>]?')) {
$output->writeln('Aborting.');
return AbstractSpipCommand::FAILURE;
}
$output->writeln('<info>Putting default preferred-install in '.$composerFile.'</info>');
$file = new JsonFile($composerFile);
$json = new JsonConfigSource($file);
$json->addConfigSetting('preferred-install', ['spip/*' => 'source']);
$this->resetComposer();
$composer = $this->tryComposer();
}
}
$myPreferredInstall = new PreferredInstall($composer);
$toChange = $myPreferredInstall->getFromConfig();
$changer = new RemoteUrls($this->getIO());
$output->writeln('Looking in git urls ...');
foreach ($toChange as $path) {
$url = '';
$changer->getProcessor()->execute($changer->getRemote($path), $url);
$url = trim($url);
if ($output->isVerbose()) {
$output->write('Checking ' . $url . ' in ' . $path . ' ...');
}
$newUrl = $changer->toSsh($url);
if ($newUrl !== $url) {
$output->write(PHP_EOL.'Converting ' . $url . ' into ' . $newUrl);
$changer->getProcessor()->execute($changer->setRemote($path, $newUrl));
}
if ($output->isVerbose()) {
$output->writeln(' OK');
}
}
$output->writeln(PHP_EOL.'All done.');
return AbstractSpipCommand::SUCCESS;
}
}