Skip to content

Commit

Permalink
meh
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes committed Oct 20, 2024
1 parent c4cb422 commit 423a533
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 80 deletions.
24 changes: 20 additions & 4 deletions src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace SonsOfPHP\Bard\Console\Command;

use SonsOfPHP\Bard\JsonFile;
use SonsOfPHP\Bard\JsonFileInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Helper\ProcessHelper;
Expand All @@ -17,18 +18,33 @@
*/
abstract class AbstractCommand extends Command
{
protected JsonFile $bardConfig;
protected JsonFileInterface $bardConfig;

protected SymfonyStyle $bardStyle;

protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->bardConfig = new JsonFile($input->getOption('working-dir') . '/bard.json');
$config = $input->getOption('config');
$this->initializeBardStyle($input, $output);
$this->initializeBardConfig($input, $output);

Check warning on line 28 in src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php

View check run for this annotation

Codecov / codecov/patch

src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php#L27-L28

Added lines #L27 - L28 were not covered by tests
}

private function initializeBardConfig(InputInterface $input, OutputInterface $output): void

Check warning on line 31 in src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php

View check run for this annotation

Codecov / codecov/patch

src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php#L31

Added line #L31 was not covered by tests
{
$bardJson = $input->getOption('working-dir') . '/bard.json';
$config = $input->getOption('config');

Check warning on line 34 in src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php

View check run for this annotation

Codecov / codecov/patch

src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php#L33-L34

Added lines #L33 - L34 were not covered by tests
if ('bard.json' !== $config) {
$this->bardConfig = new JsonFile($config);
$bardJson = $config;

Check warning on line 36 in src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php

View check run for this annotation

Codecov / codecov/patch

src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php#L36

Added line #L36 was not covered by tests
}

if ($output->isDebug()) {
$this->bardStyle->text(sprintf('Using configuration file "%s"', $bardJson));

Check warning on line 40 in src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php

View check run for this annotation

Codecov / codecov/patch

src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php#L39-L40

Added lines #L39 - L40 were not covered by tests
}

$this->bardConfig = new JsonFile($bardJson);

Check warning on line 43 in src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php

View check run for this annotation

Codecov / codecov/patch

src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php#L43

Added line #L43 was not covered by tests
}

private function initializeBardStyle(InputInterface $input, OutputInterface $output): void

Check warning on line 46 in src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php

View check run for this annotation

Codecov / codecov/patch

src/SonsOfPHP/Bard/src/Console/Command/AbstractCommand.php#L46

Added line #L46 was not covered by tests
{
$this->bardStyle = new SymfonyStyle($input, $output);
}

Expand Down
28 changes: 13 additions & 15 deletions src/SonsOfPHP/Bard/src/Console/Command/MergeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
*/
final class MergeCommand extends AbstractCommand
{
protected JsonFile $bardConfig;

private string $mainComposerFile;

protected function configure(): void
Expand All @@ -46,12 +44,7 @@ protected function configure(): void

protected function initialize(InputInterface $input, OutputInterface $output): void
{
$bardConfigFile = $input->getOption('working-dir') . '/bard.json';
if (!file_exists($bardConfigFile)) {
throw new RuntimeException(sprintf('"%s" file does not exist', $bardConfigFile));
}

$this->bardConfig = new JsonFile($bardConfigFile);
parent::initialize($input, $output);

$this->mainComposerFile = $input->getOption('working-dir') . '/composer.json';
if (!file_exists($this->mainComposerFile)) {
Expand All @@ -67,12 +60,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$rootComposerJsonFile = new JsonFile($input->getOption('working-dir') . '/composer.json');

// Clean out a few of the sections in root composer.json file
$rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSectionOperation('autoload'));
$rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSectionOperation('autoload-dev'));
$rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSectionOperation('require'));
$rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSectionOperation('require-dev'));
$rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSectionOperation('replace'));
$rootComposerJsonFile = $rootComposerJsonFile->with(new ClearSectionOperation('provide'));
$rootComposerJsonFile = $rootComposerJsonFile
->with(new ClearSectionOperation('autoload'))
->with(new ClearSectionOperation('autoload-dev'))
->with(new ClearSectionOperation('require'))
->with(new ClearSectionOperation('require-dev'))
->with(new ClearSectionOperation('replace'))
->with(new ClearSectionOperation('provide'))
;

foreach ($this->bardConfig->getSection('packages') as $pkg) {
$pkgComposerFile = realpath($input->getOption('working-dir') . '/' . $pkg['path'] . '/composer.json');
Expand All @@ -87,7 +82,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
}

$output->writeln($this->getFormatterHelper()->formatSection('bard', sprintf('Merging "%s" into root composer.json', $pkgComposerJsonFile->getSection('name'))));
$this->bardStyle->text(sprintf(
'Merging "%s" into root composer.json',
$pkgComposerJsonFile->getSection('name'),
));

// Update root composer.json
$rootComposerJsonFile = $rootComposerJsonFile
Expand Down
Loading

0 comments on commit 423a533

Please sign in to comment.