Skip to content

Commit

Permalink
add additional check for tty support
Browse files Browse the repository at this point in the history
  • Loading branch information
slavarazum committed Mar 21, 2024
1 parent f8d9e7b commit 3c72988
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/Console/Commands/BroadcastingInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Str;
use Qruto\Wave\WaveServiceProvider;
use Symfony\Component\Process\Process as SymfonyProcess;

use function file_get_contents;
use function Laravel\Prompts\confirm;
Expand All @@ -27,9 +29,11 @@ public function handle(): int
$relativeBroadcastingRoutesStub = 'laravel/framework/src/Illuminate/Foundation/Console/stubs/broadcasting-routes.stub';

if (file_exists(__DIR__.'/../../../../'.$relativeBroadcastingRoutesStub)) {
File::copy(__DIR__.'/../../../stubs/broadcasting-routes.stub', $broadcastingRoutesPath);
File::copy(__DIR__.'/../../../stubs/broadcasting-routes.stub',
$broadcastingRoutesPath);
} else {
File::copy(__DIR__.'/../../../vendor/'.$relativeBroadcastingRoutesStub, $broadcastingRoutesPath);
File::copy(__DIR__.'/../../../vendor/'.$relativeBroadcastingRoutesStub,
$broadcastingRoutesPath);
}
}

Expand Down Expand Up @@ -68,7 +72,8 @@ public function handle(): int
/** {@inheritdoc} */
protected function installNodeDependencies()
{
if (! confirm('Would you like to install and build the Node dependencies required for broadcasting?', default: true)) {
if (! confirm('Would you like to install and build the Node dependencies required for broadcasting?',
default: true)) {
return;
}

Expand All @@ -94,12 +99,13 @@ protected function installNodeDependencies()
$command = Process::command(implode(' && ', $commands))
->path(base_path());

if (! windows_os()) {
if (! windows_os() || SymfonyProcess::isTtySupported()) {
$command->tty(true);
}

if ($command->run()->failed()) {
$this->components->warn("Node dependency installation failed. Please run the following commands manually: \n\n".implode(' && ', $commands));
$this->components->warn("Node dependency installation failed. Please run the following commands manually: \n\n".implode(' && ',
$commands));
} else {
$this->components->info('Node dependencies installed successfully.');
}
Expand All @@ -121,18 +127,21 @@ protected function updateBroadcastingDriver(): void

File::put(
$env,
Str::of(File::get($env))->replaceMatches('/(BROADCAST_(?:DRIVER|CONNECTION))=\w*/', fn (array $matches) => $matches[1].'=redis')->value()
Str::of(File::get($env))->replaceMatches('/(BROADCAST_(?:DRIVER|CONNECTION))=\w*/',
fn (array $matches) => $matches[1].'=redis')->value()
);
}

protected function publishConfiguration(): void
{
if (! confirm('Would you like to publish the Wave configuration file?', default: false, hint: 'This will allow you to configure the SSE connection.')) {
if (! confirm('Would you like to publish the Wave configuration file?',
default: false,
hint: 'This will allow you to configure the SSE connection.')) {
return;
}

$this->callSilently('vendor:publish', [
'--provider' => \Qruto\Wave\WaveServiceProvider::class,
'--provider' => WaveServiceProvider::class,
'--tag' => 'wave-config',
]);
}
Expand Down

0 comments on commit 3c72988

Please sign in to comment.