Skip to content

Commit

Permalink
Adds storage:link command to install script
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed Mar 6, 2024
1 parent 0a44e0a commit 6585240
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function handle(): int
$this->updateAppLayouts();
$this->deleteNpmRelatedFiles();
$this->configureIgnoredFolder();
$this->runStorageLinkCommand();

$this->newLine();
$this->components->info('Importmap Laravel was installed succesfully.');
Expand Down Expand Up @@ -122,6 +123,42 @@ private function configureIgnoredFolder()
File::append(base_path('.gitignore'), "\n/public/js\n");
}

private function runStorageLinkCommand()
{
if ($this->components->confirm('To be able to serve your assets in development, the resource/js folder will be symlinked to your public/js. Would you like to do that now?', true)) {
if ($this->usingSail() && ! env('LARAVEL_SAIL')) {
Process::forever()->run([
'./vendor/bin/sail',
'up',
'-d',
], function ($_type, $output) {
$this->output->write($output);
});

Process::forever()->run([
'./vendor/bin/sail',
'artisan',
'storage:link',
], function ($_type, $output) {
$this->output->write($output);
});
} else {
Process::forever()->run([
$this->phpBinary(),
'artisan',
'storage:link',
], function ($_type, $output) {
$this->output->write($output);
});
}
}
}

private function usingSail(): bool
{
return file_exists(base_path('docker-compose.yml')) && str_contains(file_get_contents(base_path('composer.json')), 'laravel/sail');
}

private function phpBinary()
{
return (new PhpExecutableFinder())->find(false) ?: 'php';
Expand Down

0 comments on commit 6585240

Please sign in to comment.