Skip to content

Commit

Permalink
Improves output if Herd or Valet are installed. (#335)
Browse files Browse the repository at this point in the history
* Check if the Herd or Valet are available.

* typo

* style: fixes

* style: fixes

* style: fixes

* Update NewCommand.php

* Update NewCommand.php

* Update NewCommand.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
xiCO2k and taylorotwell authored May 3, 2024
1 parent 59ea47d commit ad66a9a
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$output->writeln(" <bg=blue;fg=white> INFO </> Application ready in <options=bold>[{$name}]</>. You can start your local development using:".PHP_EOL);

$output->writeln('<fg=gray>➜</> <options=bold>cd '.$name.'</>');
$output->writeln('<fg=gray>➜</> <options=bold>php artisan serve</>');
$output->writeln('');

if ($this->isParked($directory)) {
$url = $this->generateAppUrl($name);
$output->writeln('<fg=gray>➜</> Open: <options=bold;href='.$url.'>'.$url.'</>');
} else {
$output->writeln('<fg=gray>➜</> <options=bold>php artisan serve</>');
}

$output->writeln('');
$output->writeln(' New to Laravel? Check out our <href=https://bootcamp.laravel.com>bootcamp</> and <href=https://laravel.com/docs/installation#next-steps>documentation</>. <options=bold>Build something amazing!</>');
$output->writeln('');
}
Expand Down Expand Up @@ -756,6 +761,29 @@ protected function canResolveHostname($hostname)
return gethostbyname($hostname.'.') !== $hostname.'.';
}

/**
* Determine if the given directory is parked using Herd or Valet.
*
* @param string $directory
* @return bool
*/
protected function isParked(string $directory)
{
foreach (['herd', 'valet'] as $tool) {
$process = new Process([$tool, 'paths']);

$process->run();

if ($process->isSuccessful()) {
$output = json_decode(trim($process->getOutput()));

return in_array(dirname($directory), $output);
}
}

return false;
}

/**
* Get the version that should be downloaded.
*
Expand Down

0 comments on commit ad66a9a

Please sign in to comment.