try to rebuild assets when installing/ updating plugin

This commit is contained in:
Boy132 2025-08-04 11:13:24 +02:00
parent 02d18f28e3
commit a741be7226
2 changed files with 27 additions and 1 deletions

View File

@ -15,6 +15,7 @@ use Illuminate\Http\UploadedFile;
use Illuminate\Support\Composer; use Illuminate\Support\Composer;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Spatie\TemporaryDirectory\TemporaryDirectory; use Spatie\TemporaryDirectory\TemporaryDirectory;
use ZipArchive; use ZipArchive;
@ -161,6 +162,27 @@ class PluginService
} }
} }
public function buildAssets(): bool
{
try {
$result = Process::run('yarn install');
if ($result->failed()) {
throw new Exception('Could not install dependencies: ' . $result->errorOutput());
}
$result = Process::run('yarn build');
if ($result->failed()) {
throw new Exception('Could not build assets: ' . $result->errorOutput());
}
return true;
} catch (Exception $exception) {
report($exception);
}
return false;
}
public function installPlugin(Plugin $plugin): void public function installPlugin(Plugin $plugin): void
{ {
try { try {
@ -168,6 +190,8 @@ class PluginService
$this->runPluginMigrations($plugin); $this->runPluginMigrations($plugin);
$this->buildAssets();
$this->enablePlugin($plugin); $this->enablePlugin($plugin);
} catch (Exception $exception) { } catch (Exception $exception) {
report($exception); report($exception);
@ -185,6 +209,8 @@ class PluginService
$this->runPluginMigrations($plugin); $this->runPluginMigrations($plugin);
$this->buildAssets();
cache()->forget("plugins.$plugin->id.update"); cache()->forget("plugins.$plugin->id.update");
} catch (Exception $exception) { } catch (Exception $exception) {
report($exception); report($exception);

View File

@ -1,7 +1,7 @@
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import tailwindcss from '@tailwindcss/vite'; import tailwindcss from '@tailwindcss/vite';
import laravel, { refreshPaths } from 'laravel-vite-plugin'; import laravel, { refreshPaths } from 'laravel-vite-plugin';
import { globSync } from "glob"; import { globSync } from 'glob';
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [