From af25590a73f8343e5f2e4b17c4b739d136ef996c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 12 Nov 2023 10:09:37 +0100 Subject: [PATCH] Add serve command runtime option for preview saving --- .../src/Console/Commands/ServeCommand.php | 2 ++ .../Foundation/Internal/LoadConfiguration.php | 1 + .../tests/Unit/ServeCommandOptionsUnitTest.php | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/packages/framework/src/Console/Commands/ServeCommand.php b/packages/framework/src/Console/Commands/ServeCommand.php index 166ea34e4ac..adcea1806cd 100644 --- a/packages/framework/src/Console/Commands/ServeCommand.php +++ b/packages/framework/src/Console/Commands/ServeCommand.php @@ -28,6 +28,7 @@ class ServeCommand extends ValidatingCommand protected $signature = 'serve {--host= : [default: "localhost"]}} {--port= : [default: 8080]} + {--save-preview= : Should the served page be saved to disk? (Overrides config setting)} {--dashboard= : Enable the realtime compiler dashboard. (Overrides config setting)} {--pretty-urls= : Enable pretty URLs. (Overrides config setting)} {--play-cdn= : Enable the Tailwind Play CDN. (Overrides config setting)} @@ -76,6 +77,7 @@ protected function getEnvironmentVariables(): array { return Arr::whereNotNull([ 'HYDE_SERVER_REQUEST_OUTPUT' => ! $this->option('no-ansi'), + 'HYDE_SERVER_SAVE_PREVIEW' => $this->parseEnvironmentOption('save-preview'), 'HYDE_SERVER_DASHBOARD' => $this->parseEnvironmentOption('dashboard'), 'HYDE_PRETTY_URLS' => $this->parseEnvironmentOption('pretty-urls'), 'HYDE_PLAY_CDN' => $this->parseEnvironmentOption('play-cdn'), diff --git a/packages/framework/src/Foundation/Internal/LoadConfiguration.php b/packages/framework/src/Foundation/Internal/LoadConfiguration.php index 5fa364ee040..10bf1418286 100644 --- a/packages/framework/src/Foundation/Internal/LoadConfiguration.php +++ b/packages/framework/src/Foundation/Internal/LoadConfiguration.php @@ -87,6 +87,7 @@ private function loadRuntimeConfiguration(Application $app, Repository $reposito $this->mergeCommandLineArguments($repository, '--no-api', 'hyde.api_calls', false); } + $this->mergeRealtimeCompilerEnvironment($repository, 'HYDE_SERVER_SAVE_PREVIEW', 'hyde.server.save_preview'); $this->mergeRealtimeCompilerEnvironment($repository, 'HYDE_SERVER_DASHBOARD', 'hyde.server.dashboard.enabled'); $this->mergeRealtimeCompilerEnvironment($repository, 'HYDE_PRETTY_URLS', 'hyde.pretty_urls'); $this->mergeRealtimeCompilerEnvironment($repository, 'HYDE_PLAY_CDN', 'hyde.use_play_cdn'); diff --git a/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php b/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php index 605d24ecc81..935d9793198 100644 --- a/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php +++ b/packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php @@ -80,6 +80,24 @@ public function test_getEnvironmentVariables_withNoAnsiOption() ], $this->getMock(['no-ansi' => true])->getEnvironmentVariables()); } + public function testSavePreviewOptionPropagatesToEnvironmentVariables() + { + $command = $this->getMock(['save-preview' => 'false']); + $this->assertSame('disabled', $command->getEnvironmentVariables()['HYDE_SERVER_SAVE_PREVIEW']); + + $command = $this->getMock(['save-preview' => 'true']); + $this->assertSame('enabled', $command->getEnvironmentVariables()['HYDE_SERVER_SAVE_PREVIEW']); + + $command = $this->getMock(['save-preview' => '']); + $this->assertSame('enabled', $command->getEnvironmentVariables()['HYDE_SERVER_SAVE_PREVIEW']); + + $command = $this->getMock(['save-preview' => null]); + $this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_SERVER_SAVE_PREVIEW'])); + + $command = $this->getMock(); + $this->assertFalse(isset($command->getEnvironmentVariables()['HYDE_SERVER_SAVE_PREVIEW'])); + } + public function testDashboardOptionPropagatesToEnvironmentVariables() { $command = $this->getMock(['dashboard' => 'false']);