1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 16:10:08 +01:00

Add debug instructions to valet status, expand "valet installed" status check

This commit is contained in:
Matt Stauffer
2023-01-11 11:37:47 -05:00
parent 9a04590abf
commit 4c10d906f7
4 changed files with 49 additions and 10 deletions

View File

@@ -6,6 +6,7 @@ class Status
{
public $brewServicesUserOutput;
public $brewServicesSudoOutput;
public $debugInstructions = [];
public function __construct(public Configuration $config, public Brew $brew, public CommandLine $cli, public Filesystem $files)
{
@@ -21,6 +22,7 @@ public function check(): array
$output = collect($this->checks())->map(function (array $check) use (&$isValid) {
if (! $thisIsValid = $check['check']()) {
$this->debugInstructions[] = $check['debug'];
$isValid = false;
}
@@ -30,6 +32,7 @@ public function check(): array
return [
'success' => $isValid,
'output' => $output->all(),
'debug' => $this->debugInstructions(),
];
}
@@ -40,70 +43,87 @@ public function checks(): array
{
return [
[
'description' => 'Is Valet installed?',
'description' => 'Is Valet fully installed?',
'check' => function () {
return is_dir(VALET_HOME_PATH) && file_exists($this->config->path());
return $this->valetInstalled();
},
'debug' => 'Run `composer require laravel/valet` and `valet install`.',
],
[
'description' => 'Is Valet config valid?',
'check' => function () {
try {
$this->config->read();
$config = $this->config->read();
foreach (['tld', 'loopback', 'paths'] as $key) {
if (!array_key_exists($key, $config)) {
$this->debugInstructions[] = 'Your Valet config is missing the "'.$key.'" key. Re-add this manually, or delete your config file and re-install.';
return false;
}
}
return true;
} catch (\JsonException $e) {
return false;
}
},
'debug' => 'Run `valet install` to update your configuration.',
],
[
'description' => 'Is Homebrew installed?',
'check' => function () {
return $this->cli->run('which brew') !== '';
},
'debug' => 'Visit https://brew.sh/ for instructions on installing Homebrew.',
],
[
'description' => 'Is DnsMasq installed?',
'check' => function () {
return $this->brew->installed('dnsmasq');
},
'debug' => 'Run `valet install`.',
],
[
'description' => 'Is Dnsmasq running?',
'check' => function () {
return $this->isBrewServiceRunning('dnsmasq');
},
'debug' => 'Run `valet restart`.',
],
[
'description' => 'Is Nginx installed?',
'check' => function () {
return $this->brew->installed('nginx');
},
'debug' => 'Run `valet install`.',
],
[
'description' => 'Is Nginx running?',
'check' => function () {
return $this->isBrewServiceRunning('nginx');
},
'debug' => 'Run `valet restart`.',
],
[
'description' => 'Is PHP installed?',
'check' => function () {
return $this->brew->hasInstalledPhp();
},
'debug' => 'Run `valet install`.',
],
[
'description' => 'Is PHP running?',
'check' => function () {
return $this->isBrewServiceRunning('php', exactMatch: false);
},
'debug' => 'Run `valet restart`.',
],
[
'description' => 'Is valet.sock present?',
'check' => function () {
return $this->files->exists(VALET_HOME_PATH.'/valet.sock');
},
'debug' => 'Run `valet install`.',
],
];
}
@@ -132,4 +152,19 @@ public function isBrewServiceRunning(string $name, bool $exactMatch = true): boo
return false;
}
public function valetInstalled(): bool
{
return is_dir(VALET_HOME_PATH)
&& file_exists($this->config->path())
&& is_dir(VALET_HOME_PATH.'/Drivers')
&& is_dir(VALET_HOME_PATH.'/Sites')
&& is_dir(VALET_HOME_PATH.'/Log')
&& is_dir(VALET_HOME_PATH.'/Certificates');
}
public function debugInstructions(): string
{
return collect($this->debugInstructions)->unique()->join(PHP_EOL);
}
}

View File

@@ -52,17 +52,16 @@ function (ConsoleCommandEvent $event) {
$app->command('install', function (OutputInterface $output) {
Nginx::stop();
output(PHP_EOL);
Configuration::install();
output(PHP_EOL);
output();
Nginx::install();
output(PHP_EOL);
output();
PhpFpm::install();
output(PHP_EOL);
output();
DnsMasq::install(Configuration::read()['tld']);
output(PHP_EOL);
output();
Nginx::restart();
output(PHP_EOL);
output();
Valet::symlinkToUsersBin();
output(PHP_EOL.'<info>Valet installed successfully!</info>');
@@ -88,6 +87,9 @@ function (ConsoleCommandEvent $event) {
return Command::SUCCESS;
}
info(PHP_EOL.'Debug suggestions:');
info($status['debug']);
return Command::FAILURE;
})->descriptions('Output the status of Valet and its installed services and config.');

View File

@@ -88,7 +88,7 @@ function testing(): bool
/**
* Output the given text to the console.
*/
function output(string $output): void
function output(string $output = ''): void
{
writer()->writeln($output);
}

View File

@@ -35,6 +35,8 @@ public function prepTestConfig()
Configuration::createConfigurationDirectory();
Configuration::createDriversDirectory();
Configuration::createLogDirectory();
Configuration::createCertificatesDirectory();
Configuration::writeBaseConfiguration();
}