Skip to content

Commit 28968ff

Browse files
[2.x] Install NPM dependencies and build assets (#1119)
* Install NPM dependencies and build assets * Update InstallCommand.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 3241c92 commit 28968ff

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/Console/InstallCommand.php

+28-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Console\Command;
77
use Illuminate\Filesystem\Filesystem;
88
use Illuminate\Support\Str;
9+
use RuntimeException;
910
use Symfony\Component\Process\PhpExecutableFinder;
1011
use Symfony\Component\Process\Process;
1112

@@ -237,9 +238,10 @@ protected function installLivewireStack()
237238
$this->installLivewireTeamStack();
238239
}
239240

241+
$this->runCommands(['npm install', 'npm run build']);
242+
240243
$this->line('');
241244
$this->components->info('Livewire scaffolding installed successfully.');
242-
$this->components->warn('Please execute the [npm install && npm run build] commands to build your assets.');
243245
}
244246

245247
/**
@@ -425,9 +427,10 @@ protected function installInertiaStack()
425427
$this->installInertiaSsrStack();
426428
}
427429

430+
$this->runCommands(['npm install', 'npm run build']);
431+
428432
$this->line('');
429433
$this->components->info('Inertia scaffolding installed successfully.');
430-
$this->components->warn('Please execute the [npm install && npm run build] commands to build your assets.');
431434
}
432435

433436
/**
@@ -714,4 +717,27 @@ protected function phpBinary()
714717
{
715718
return (new PhpExecutableFinder())->find(false) ?: 'php';
716719
}
720+
721+
/**
722+
* Run the given commands.
723+
*
724+
* @param array $commands
725+
* @return void
726+
*/
727+
protected function runCommands($commands)
728+
{
729+
$process = Process::fromShellCommandline(implode(' && ', $commands), null, null, null, null);
730+
731+
if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
732+
try {
733+
$process->setTty(true);
734+
} catch (RuntimeException $e) {
735+
$this->output->writeln(' <bg=yellow;fg=black> WARN </> '.$e->getMessage().PHP_EOL);
736+
}
737+
}
738+
739+
$process->run(function ($type, $line) {
740+
$this->output->write(' '.$line);
741+
});
742+
}
717743
}

0 commit comments

Comments
 (0)