From be7ede814ed69f91abe83a7e5358ce47102f74e9 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen.haas@lakedrops.com> Date: Sun, 27 Dec 2020 15:56:30 +0100 Subject: [PATCH] docker/l3d#58 Move project settings out of composer.json --- Config.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Config.php b/Config.php index 954e430..0702785 100644 --- a/Config.php +++ b/Config.php @@ -2,6 +2,8 @@ namespace LakeDrops\Component\Composer; +use Composer\Json\JsonFile; +use Exception; use Symfony\Component\Yaml\Yaml; use Twig\Error\LoaderError; use Twig\Error\RuntimeError; @@ -65,6 +67,7 @@ final class Config { $this->init(); $this->merge($default_values, []); + $this->migrateFomrComposerJson(); } /** @@ -83,6 +86,25 @@ final class Config { } } + /** + * Migrate custom settings from composer.json if required. + */ + private function migrateFomrComposerJson(): void { + $filename = getcwd() . '/composer.json'; + $jsonFile = new JsonFile($filename); + $content = $jsonFile->read(); + if (isset($content['extra'][$this->component])) { + $this->merge([], $content['extra'][$this->component]); + $this->save(); + unset($content['extra'][$this->component]); + try { + $jsonFile->write($content); + } catch (Exception $ex) { + // Let's ignore this, if composer.json is read-only there is a general problem. + } + } + } + /** * @param array $defaultValues * @param array $customValues -- GitLab