Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
[MB] Add merge_sections to README + fix for scalar values
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 9, 2018
1 parent 4279740 commit 18cbe07
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
36 changes: 26 additions & 10 deletions packages/MonorepoBuilder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,32 @@ composer require symplify/monorepo-builder --dev

### 1. Merge local `composer.json` to the Root One

Merges following sections to the root `composer.json`, so you can only edit `composer.json` of particular packages and let script to synchronize it.

- 'require'
- 'require-dev'
- 'autoload'
- 'autoload-dev'
- 'repositories'
- 'scripts'
- 'extra'
- ...
Merges configured sections to the root `composer.json`, so you can only edit `composer.json` of particular packages and let script to synchronize it.

```yaml
# monorepo-builder.yml
parameters:
merge_sections:
# default values
- 'require'
- 'require-dev'
- 'autoload'
- 'autoload-dev'
- 'repositories'
```

You can configure it and add `minimum-stablity` for example or remove any of those default values:

```yaml
# monorepo-builder.yml
parameters:
merge_sections:
- 'require'
- 'require-dev'
- 'minimum-stability'
```

To merge just run:

```bash
vendor/bin/monorepo-builder merge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$allComposerJsonFiles[] = $composerPackageFiles + [$this->composerJsonProvider->getRootComposerJsonFileInfo()];
$allComposerJsonFiles = $composerPackageFiles + [$this->composerJsonProvider->getRootComposerJsonFileInfo()];

$conflictingPackageVersions = $this->versionValidator->findConflictingPackageVersionsInFileInfos(
$allComposerJsonFiles
Expand Down
28 changes: 24 additions & 4 deletions packages/MonorepoBuilder/src/Package/PackageComposerJsonMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,33 @@ public function mergeFileInfos(array $composerPackageFileInfos, array $sections)
continue;
}

$merged[$section] = $this->parametersMerger->merge(
$merged[$section] ?? [],
$packageComposerJson[$section]
);
$merged = $this->mergeSection($packageComposerJson, $section, $merged);
}
}

return $merged;
}

/**
* @param mixed[] $packageComposerJson
* @param mixed[] $merged
* @return mixed[]
*/
private function mergeSection(array $packageComposerJson, string $section, array $merged): array
{
// array sections
if (is_array($packageComposerJson[$section])) {
$merged[$section] = $this->parametersMerger->merge(
$merged[$section] ?? [],
$packageComposerJson[$section]
);

return $merged;
}

// key: value sections, like "minimum-stability: dev"
$merged[$section] = $packageComposerJson[$section];

return $merged;
}
}
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ parameters:
- '#Method Symplify\\EasyCodingStandard\\Finder\\SourceFinder::find\(\) should return array<Symfony\\Component\\Finder\\SplFileInfo> but returns array<SplFileInfo>#'
- '#Property Symplify\\EasyCodingStandard\\Yaml\\CheckerServiceParametersShifter::\$serviceKeywords \(array<string>\) does not accept ReflectionProperty#'
- '#Method Symplify\\EasyCodingStandard\\Tests\\Indentation\\IndentationTest::getIndentationTypeFixerFromContainer\(\) should return PhpCsFixer\\Fixer\\Whitespace\\IndentationTypeFixer but returns PhpCsFixer\\Fixer\\FixerInterface\|null#'
- '#Method Symplify\\MonorepoBuilder\\Package\\PackageComposerJsonMerger::mergeFileInfos\(\) should return array<string> but returns array<string, array\|string>#'
- '#Parameter \#1 \$path of function dirname expects string, string\|false given#'
- '#Method Symplify\\PackageBuilder\\Console\\Command\\CommandNaming::getShortClassName\(\) should return string but returns string\|null#'
- '#Method Symplify\\PackageBuilder\\Tests\\Console\\ThrowableRendererTest::getTestErrorOutput\(\) should return string but returns string\|false#'
Expand Down

0 comments on commit 18cbe07

Please sign in to comment.