Skip to content

Commit fb28893

Browse files
committed
Create Herd driver install command
1 parent daa4101 commit fb28893

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hyde\RealtimeCompiler\Console\Commands;
6+
7+
use Hyde\Hyde;
8+
use Hyde\Console\Concerns\Command;
9+
use Illuminate\Support\Facades\File;
10+
use Exception;
11+
12+
/**
13+
* @experimental This command is experimental and may be unstable. Report issues at GitHub!
14+
*
15+
* @see https://github.com/hydephp/realtime-compiler/pull/30
16+
*/
17+
class HerdInstallCommand extends Command
18+
{
19+
/** @var string */
20+
protected $signature = 'herd:install {--force : Overwrite any existing file}';
21+
22+
/** @var string */
23+
protected $description = '[Experimental] Install the HydePHP Valet driver for Laravel Herd';
24+
25+
public function safeHandle(): int
26+
{
27+
$driverTargetPath = $this->getDriverTargetPath();
28+
$driverSourcePath = Hyde::vendorPath('resources/stubs/HydeValetDriver.php', 'realtime-compiler');
29+
30+
if (! is_dir(dirname($driverTargetPath))) {
31+
$this->error('Herd Valet drivers directory not found. Is Herd installed?');
32+
33+
return Command::FAILURE;
34+
}
35+
36+
if (file_exists($driverTargetPath) && ! $this->option('force')) {
37+
if (! $this->confirm('The HydePHP Valet driver for Herd already exists. Do you want to overwrite it?', true)) {
38+
$this->info('Installation cancelled.');
39+
40+
return Command::SUCCESS;
41+
}
42+
}
43+
44+
try {
45+
File::copy($driverSourcePath, $driverTargetPath);
46+
$this->info('HydePHP Valet driver for Herd successfully installed!');
47+
$this->line('Driver path: '.$driverTargetPath);
48+
49+
return Command::SUCCESS;
50+
} catch (Exception $exception) {
51+
$this->error('Failed to install the HydePHP Valet driver: '.$exception->getMessage());
52+
53+
return Command::FAILURE;
54+
}
55+
}
56+
57+
private function getDriverTargetPath(): string
58+
{
59+
return match (PHP_OS_FAMILY) {
60+
'Darwin' => $_SERVER['HOME'].'/Library/Application Support/Herd/config/valet/Drivers/HydeValetDriver.php',
61+
'Windows' => $_SERVER['USERPROFILE'].'\.config\herd\config\valet\Drivers\HydeValetDriver.php',
62+
default => throw new Exception('Herd is not yet supported on Linux.'),
63+
};
64+
}
65+
}

src/RealtimeCompilerServiceProvider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
namespace Hyde\RealtimeCompiler;
66

77
use Illuminate\Support\ServiceProvider;
8-
use Hyde\RealtimeCompiler\Http\LiveEditController;
98
use Hyde\RealtimeCompiler\Http\DashboardController;
9+
use Hyde\RealtimeCompiler\Http\LiveEditController;
1010
use Hyde\RealtimeCompiler\Http\VirtualRouteController;
11+
use Hyde\RealtimeCompiler\Console\Commands\HerdInstallCommand;
1112

1213
class RealtimeCompilerServiceProvider extends ServiceProvider
1314
{
1415
public function register(): void
1516
{
1617
$this->app->singleton(RealtimeCompiler::class);
18+
19+
if ($this->app->runningInConsole()) {
20+
$this->commands([
21+
HerdInstallCommand::class,
22+
]);
23+
}
1724
}
1825

1926
public function boot(): void

0 commit comments

Comments
 (0)