diff --git a/build/src/php/VersionUpdater/DependencyProvider.php b/build/src/php/VersionUpdater/DependencyProvider.php new file mode 100644 index 0000000..8bcb253 --- /dev/null +++ b/build/src/php/VersionUpdater/DependencyProvider.php @@ -0,0 +1,25 @@ +set(self::FACADE_PHEL_CONSOLE, function (Container $container) { + return $container->getLocator()->get(ConsoleFacade::class); + }); + } +} diff --git a/build/src/php/VersionUpdater/Facade.php b/build/src/php/VersionUpdater/Facade.php new file mode 100644 index 0000000..e28a9b0 --- /dev/null +++ b/build/src/php/VersionUpdater/Facade.php @@ -0,0 +1,20 @@ +getFactory() + ->createPhelVersionUpdater() + ->update(); + } +} diff --git a/build/src/php/VersionUpdater/Factory.php b/build/src/php/VersionUpdater/Factory.php new file mode 100644 index 0000000..905d245 --- /dev/null +++ b/build/src/php/VersionUpdater/Factory.php @@ -0,0 +1,34 @@ +getPhelConsoleFacade(), + $this->getConfigFileLocation(), + ); + } + + private function getPhelConsoleFacade(): ConsoleFacadeInterface + { + return $this->getProvidedDependency(DependencyProvider::FACADE_PHEL_CONSOLE); + } + + private function getConfigFileLocation(): string + { + return $this->getConfig()->getAppRootDir() . '/../config.toml'; + } +} diff --git a/build/src/php/VersionUpdater/Infrastructure/PhelVersionUpdater.php b/build/src/php/VersionUpdater/Infrastructure/PhelVersionUpdater.php new file mode 100644 index 0000000..c5721b3 --- /dev/null +++ b/build/src/php/VersionUpdater/Infrastructure/PhelVersionUpdater.php @@ -0,0 +1,34 @@ +configFile); + + $phelVersion = $this->consoleFacade->getVersion(); + $updatedContent = preg_replace( + self::REGEX_PHEL_VERSION_FINDER, + 'phel_version = "' . $phelVersion . '"', + $configContent + ); + + if ($updatedContent !== $configContent) { + file_put_contents($this->configFile, $updatedContent); + } + } +} diff --git a/build/tests/php/VersionUpdater/Integration/PhelVersionUpdaterTest.php b/build/tests/php/VersionUpdater/Integration/PhelVersionUpdaterTest.php new file mode 100644 index 0000000..985a101 --- /dev/null +++ b/build/tests/php/VersionUpdater/Integration/PhelVersionUpdaterTest.php @@ -0,0 +1,57 @@ +file = tmpfile(); + fwrite($this->file, 'phel_version = "v.0.9"'); + } + + protected function tearDown(): void + { + fclose($this->file); + } + + public function test_update_phel_version(): void + { + $consoleFacade = $this->createAnonConsoleFacade(); + + $path = stream_get_meta_data($this->file)['uri']; + $phelVersionUpdater = new PhelVersionUpdater($consoleFacade, $path); + $phelVersionUpdater->update(); + + $content = file_get_contents($path); + + $expected = 'phel_version = "v1.0"'; + + self::assertSame($expected, $content); + } + + private function createAnonConsoleFacade(): ConsoleFacadeInterface + { + return new class implements ConsoleFacadeInterface { + + public function getVersion(): string + { + return 'v1.0'; + } + + public function runConsole(): void + { + // ignore + } + }; + } +} diff --git a/build/update-phel-version.php b/build/update-phel-version.php new file mode 100644 index 0000000..39c4c50 --- /dev/null +++ b/build/update-phel-version.php @@ -0,0 +1,14 @@ +updateTomlFile(); diff --git a/composer.json b/composer.json index d903f1d..8653228 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,12 @@ "php build/api-page.php", "php build/api-search.php" ], - "test": "./vendor/bin/phpunit" + "test": "./vendor/bin/phpunit", + "post-install-cmd": [ + "php build/update-phel-version.php" + ], + "post-update-cmd": [ + "php build/update-phel-version.php" + ] } } diff --git a/config.toml b/config.toml index bbff8d2..1aa9504 100644 --- a/config.toml +++ b/config.toml @@ -28,5 +28,5 @@ extra_syntaxes_and_themes = ["syntaxes"] # Put all your custom variables here repo_content_url = "https://github.com/phel-lang/phel-lang.org/blob/master/content/" -phel_version = "0.23.1" +phel_version = "v0.23.1" diff --git a/templates/footer.html b/templates/footer.html index 998528f..a40d962 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -52,7 +52,7 @@

Community