Skip to content

Commit

Permalink
various updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes committed Oct 20, 2024
1 parent d04ade9 commit 9e5f718
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 24 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,4 @@
"@php -r \"if(file_exists('./.git')&&file_exists('./build/hooks/pre-commit')){copy('./build/hooks/pre-commit','./.git/hooks/pre-commit');chmod('./.git/hooks/pre-commit',0755);}\""
]
}
}
}
2 changes: 1 addition & 1 deletion src/SonsOfPHP/Bard/src/Console/Command/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->text($bardJsonFile->toJson());

file_put_contents($bardJsonFile->getFilename(), $bardJsonFile->toJson());
$bardJsonFile->save();

$output->writeln(sprintf('File written to "%s"', $filename));

Expand Down
33 changes: 18 additions & 15 deletions src/SonsOfPHP/Bard/src/Console/Command/MergeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,32 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln($this->getFormatterHelper()->formatSection('bard', sprintf('Merging "%s" into root composer.json', $pkgComposerJsonFile->getSection('name'))));

// Update root composer.json
$rootComposerJsonFile = $rootComposerJsonFile->with(new UpdateReplaceSectionOperation($pkgComposerJsonFile));
$rootComposerJsonFile = $rootComposerJsonFile->with(new UpdateRequireSectionOperation($pkgComposerJsonFile));
$rootComposerJsonFile = $rootComposerJsonFile->with(new UpdateRequireDevSectionOperation($pkgComposerJsonFile));
$rootComposerJsonFile = $rootComposerJsonFile->with(new UpdateAutoloadSectionOperation($pkgComposerJsonFile));
$rootComposerJsonFile = $rootComposerJsonFile->with(new UpdateAutoloadDevSectionOperation($pkgComposerJsonFile));
$rootComposerJsonFile = $rootComposerJsonFile->with(new UpdateProvideSectionOperation($pkgComposerJsonFile));
// $rootComposerJsonFile = $rootComposerJsonFile->with(new Conflict($pkgComposerJsonFile));
$rootComposerJsonFile = $rootComposerJsonFile
->with(new UpdateReplaceSectionOperation($pkgComposerJsonFile))
->with(new UpdateRequireSectionOperation($pkgComposerJsonFile))
->with(new UpdateRequireDevSectionOperation($pkgComposerJsonFile))
->with(new UpdateAutoloadSectionOperation($pkgComposerJsonFile))
->with(new UpdateAutoloadDevSectionOperation($pkgComposerJsonFile))
->with(new UpdateProvideSectionOperation($pkgComposerJsonFile))
;

// Update package composer.json
$pkgComposerJsonFile = $pkgComposerJsonFile->with(new CopyBranchAliasValueFromRootToPackageOperation($rootComposerJsonFile));
$pkgComposerJsonFile = $pkgComposerJsonFile->with(new CopySupportSectionFromRootToPackageOperation($rootComposerJsonFile));
$pkgComposerJsonFile = $pkgComposerJsonFile->with(new CopyAuthorsSectionFromRootToPackageOperation($rootComposerJsonFile));
$pkgComposerJsonFile = $pkgComposerJsonFile->with(new CopyFundingSectionFromRootToPackageOperation($rootComposerJsonFile));
$pkgComposerJsonFile = $pkgComposerJsonFile
->with(new CopyBranchAliasValueFromRootToPackageOperation($rootComposerJsonFile))
->with(new CopySupportSectionFromRootToPackageOperation($rootComposerJsonFile))
->with(new CopyAuthorsSectionFromRootToPackageOperation($rootComposerJsonFile))
->with(new CopyFundingSectionFromRootToPackageOperation($rootComposerJsonFile))
;

if (!$isDryRun) {
file_put_contents($pkgComposerJsonFile->getFilename(), $pkgComposerJsonFile->toJson());
$io->text(sprintf('Updated "%s"', $pkgComposerJsonFile->getFilename()));
$pkgComposerJsonFile->save();
$io->text(sprintf('Updated "%s"', $pkgComposerJsonFile->getRealPath()));
}
}

if (!$isDryRun) {
file_put_contents($rootComposerJsonFile->getFilename(), $rootComposerJsonFile->toJson());
$io->text(sprintf('Updated "%s"', $rootComposerJsonFile->getFilename()));
$rootComposerJsonFile->save();
$io->text(sprintf('Updated "%s"', $rootComposerJsonFile->getRealPath()));
}

$io->success('Merge Complete');
Expand Down
9 changes: 9 additions & 0 deletions src/SonsOfPHP/Bard/src/JsonFileInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@
interface JsonFileInterface
{
/**
* Returns the filename such as "composer.json" or "bard.json"
*
* @return string
*/
public function getFilename();

/**
* Returns absolute path to file. Example: "/path/to/bard.json"
*
* @return string|false
*/
public function getRealPath();

/**
* Grabs and returns a section from the JSON file
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function apply(JsonFileInterface $bardConfig): JsonFileInterface
throw new \Exception(sprintf(
'Package already exists at path "%s" in "%s"',
$pkg['path'],
$bardConfig->getFilename(),
$bardConfig->getRealPath(),
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function __construct(private JsonFile $pkgComposerJsonFile) {}

public function apply(JsonFile $rootComposerJsonFile): JsonFile
{
$rootDir = pathinfo($rootComposerJsonFile->getFilename(), \PATHINFO_DIRNAME);
$pkgDir = pathinfo($this->pkgComposerJsonFile->getFilename(), \PATHINFO_DIRNAME);
$rootDir = $rootComposerJsonFile->getPath();
$pkgDir = $this->pkgComposerJsonFile->getPath();
$path = trim(str_replace($rootDir, '', $pkgDir), '/');

$rootAutoloadSection = $rootComposerJsonFile->getSection('autoload-dev');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function __construct(private JsonFile $pkgComposerJsonFile) {}

public function apply(JsonFile $rootComposerJsonFile): JsonFile
{
$rootDir = pathinfo($rootComposerJsonFile->getFilename(), \PATHINFO_DIRNAME);
$pkgDir = pathinfo($this->pkgComposerJsonFile->getFilename(), \PATHINFO_DIRNAME);
$rootDir = $rootComposerJsonFile->getPath();
$pkgDir = $this->pkgComposerJsonFile->getPath();
$path = trim(str_replace($rootDir, '', $pkgDir), '/');

$rootAutoloadSection = $rootComposerJsonFile->getSection('autoload');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile
$rootRequireDev[$package] = $version;
}

foreach ($rootRequireDev as $package => $version) {
if (array_key_exists($package, $rootReplace)) {
unset($rootRequireDev[$package]);
}
}


ksort($rootRequireDev);

return $rootComposerJsonFile->setSection('require-dev', $rootRequireDev);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ public function apply(JsonFile $rootComposerJsonFile): JsonFile
}

foreach ($pkgRequire as $package => $version) {
if (\in_array($package, array_keys($rootReplace))) {
if (array_key_exists($package, $rootReplace)) {
unset($rootRequire[$package]);
continue;
}

$rootRequire[$package] = $version;
}

foreach ($rootRequire as $package => $version) {
if (array_key_exists($package, $rootReplace)) {
unset($rootRequire[$package]);
}
}

ksort($rootRequire);

return $rootComposerJsonFile->setSection('require', $rootRequire);
Expand Down
2 changes: 1 addition & 1 deletion src/SonsOfPHP/Contract/FeatureToggle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp"
}
]
}
}

0 comments on commit 9e5f718

Please sign in to comment.