Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"composer-runtime-api": "^2.2",
"guzzlehttp/guzzle": "^6.5.5|^7.0.1",
"illuminate/collections": "^10.0|^11.0|^12.0|^13.0",
"laravel/prompts": "^0.3.19",
"laravel/prompts": "^0.3.21",
"symfony/console": "^6.2|^7.0",
"symfony/polyfill-mbstring": "^1.31",
"symfony/process": "^6.0|^7.0"
},
"require-dev": {
Expand Down
42 changes: 42 additions & 0 deletions src/Concerns/InteractsWithHerdOrValet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Statamic\Cli\Concerns;

use Symfony\Component\Process\Exception\ProcessStartFailedException;
use Symfony\Component\Process\Process;

trait InteractsWithHerdOrValet
{
protected function isParkedOnHerdOrValet(string $directory): bool
{
$paths = json_decode($this->runOnValetOrHerd('paths'));

return is_array($paths)
&& (in_array(dirname($directory), $paths) || in_array(dirname($directory).DIRECTORY_SEPARATOR, $paths));
}

protected function generateAppUrl(string $name): string
{
$hostname = mb_strtolower($name).'.'.($this->runOnValetOrHerd('tld') ?: 'test');

return gethostbyname($hostname.'.') !== $hostname.'.' ? 'http://'.$hostname : 'http://localhost';
}

protected function runOnValetOrHerd(string $command): string|false
{
foreach (['herd', 'valet'] as $tool) {
$process = new Process([$tool, $command, '-v']);

try {
$process->run();

if ($process->isSuccessful()) {
return trim($process->getOutput());
}
} catch (ProcessStartFailedException) {
}
}

return false;
}
}
26 changes: 20 additions & 6 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use GuzzleHttp\Client;
use Laravel\Prompts\ConfirmPrompt;
use Laravel\Prompts\Elements\Heading;
use Laravel\Prompts\Elements\Link;
use Laravel\Prompts\Elements\NumberedList;
use Laravel\Prompts\Prompt;
use Laravel\Prompts\SelectPrompt;
use Laravel\Prompts\SuggestPrompt;
Expand All @@ -22,6 +25,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\Process;

use function Laravel\Prompts\callout;
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\intro;
use function Laravel\Prompts\select;
Expand All @@ -30,7 +34,7 @@

class NewCommand extends Command
{
use Concerns\ConfiguresDatabase, Concerns\ConfiguresPrompts, Concerns\RunsCommands;
use Concerns\ConfiguresDatabase, Concerns\ConfiguresPrompts, Concerns\InteractsWithHerdOrValet, Concerns\RunsCommands;

const BASE_REPO = 'statamic/statamic';
const OUTPOST_ENDPOINT = 'https://outpost.statamic.com/v3/starter-kits/';
Expand Down Expand Up @@ -1047,11 +1051,21 @@ protected function enableStatamicPro()
*/
protected function showSuccessMessage()
{
$this->output->writeln(PHP_EOL.' <info>[✔] Statamic was installed successfully!</info>'.PHP_EOL);
$this->output->writeln(' You may now enter your project directory using <comment>cd '.$this->relativePath.'</comment>,'.PHP_EOL);
$this->output->writeln(' The documentation is always available at <info>statamic.dev</info> and you can ');
$this->output->writeLn(' join the community on Discord at <info>statamic.com/discord</info> anytime.'.PHP_EOL);
$this->output->writeLn(' Now go — it\'s time to create something wonderful! 🌟'.PHP_EOL);
$steps = ['cd '.$this->relativePath];

$steps[] = $this->isParkedOnHerdOrValet($this->absolutePath)
? 'Open: '.new Link($this->generateAppUrl($this->name))
: 'composer run dev';

callout('Statamic was installed successfully!', [
'You can start your local development using:',
new NumberedList($steps),
$this->output->getFormatter()->format('<options=bold>New to Statamic?</>')
.' Check out our '.new Link('https://statamic.dev', 'documentation').'.'.PHP_EOL
.$this->output->getFormatter()->format('<options=bold>Need help?</>')
.' Join the community on '.new Link('https://statamic.com/discord', 'Discord').'.',
new Heading('Now go — it\'s time to create something wonderful! 🌟'),
]);

return $this;
}
Expand Down
Loading