Skip to content

Commit

Permalink
[2.x] Install NPM dependencies and build assets (#1119)
Browse files Browse the repository at this point in the history
* Install NPM dependencies and build assets

* Update InstallCommand.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
jessarcher and taylorotwell authored Aug 12, 2022
1 parent 3241c92 commit 28968ff
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use RuntimeException;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -237,9 +238,10 @@ protected function installLivewireStack()
$this->installLivewireTeamStack();
}

$this->runCommands(['npm install', 'npm run build']);

$this->line('');
$this->components->info('Livewire scaffolding installed successfully.');
$this->components->warn('Please execute the [npm install && npm run build] commands to build your assets.');
}

/**
Expand Down Expand Up @@ -425,9 +427,10 @@ protected function installInertiaStack()
$this->installInertiaSsrStack();
}

$this->runCommands(['npm install', 'npm run build']);

$this->line('');
$this->components->info('Inertia scaffolding installed successfully.');
$this->components->warn('Please execute the [npm install && npm run build] commands to build your assets.');
}

/**
Expand Down Expand Up @@ -714,4 +717,27 @@ protected function phpBinary()
{
return (new PhpExecutableFinder())->find(false) ?: 'php';
}

/**
* Run the given commands.
*
* @param array $commands
* @return void
*/
protected function runCommands($commands)
{
$process = Process::fromShellCommandline(implode(' && ', $commands), null, null, null, null);

if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) {
try {
$process->setTty(true);
} catch (RuntimeException $e) {
$this->output->writeln(' <bg=yellow;fg=black> WARN </> '.$e->getMessage().PHP_EOL);
}
}

$process->run(function ($type, $line) {
$this->output->write(' '.$line);
});
}
}

0 comments on commit 28968ff

Please sign in to comment.