Skip to content

Commit

Permalink
Add serve command runtime option for preview saving
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 12, 2023
1 parent a3b45ed commit af25590
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/framework/src/Console/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ServeCommand extends ValidatingCommand
protected $signature = 'serve
{--host= : <comment>[default: "localhost"]</comment>}}
{--port= : <comment>[default: 8080]</comment>}
{--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)}
Expand Down Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
18 changes: 18 additions & 0 deletions packages/framework/tests/Unit/ServeCommandOptionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit af25590

Please sign in to comment.