Skip to content

Commit

Permalink
[1.x] Install NPM dependencies and build assets (#180)
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 <taylor@laravel.com>
  • Loading branch information
jessarcher and taylorotwell authored Aug 12, 2022
1 parent c61136a commit a6573fd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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 @@ -197,4 +198,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);
});
}
}
4 changes: 3 additions & 1 deletion src/Console/InstallsBladeStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ protected function installBladeStack()
copy(__DIR__.'/../../stubs/default/resources/css/app.css', resource_path('css/app.css'));
copy(__DIR__.'/../../stubs/default/resources/js/app.js', resource_path('js/app.js'));

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

$this->line('');
$this->components->info('Breeze scaffolding installed successfully.');
$this->components->warn('Please execute the [npm install && npm run dev] commands to build your assets.');
}
}
8 changes: 6 additions & 2 deletions src/Console/InstallsInertiaStacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ protected function installInertiaVueStack()
$this->installInertiaVueSsrStack();
}

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

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

/**
Expand Down Expand Up @@ -197,8 +199,10 @@ protected function installInertiaReactStack()
$this->installInertiaReactSsrStack();
}

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

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

/**
Expand Down

0 comments on commit a6573fd

Please sign in to comment.