mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-22 22:37:37 +01:00
feat: ✨ Aggiunto comando per la pubblicazione automatica degli assets in sviluppo (watch)
This commit is contained in:
parent
391ef82c1a
commit
a53182276f
56
app/Console/Commands/WatchModulesAssets.php
Normal file
56
app/Console/Commands/WatchModulesAssets.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Spatie\Watcher\Watch;
|
||||
|
||||
class WatchModulesAssets extends Command
|
||||
{
|
||||
protected $signature = 'osm:watch {--D : Watch in development mode (fix paths for use with Vite dev server)}';
|
||||
|
||||
protected $description = 'Watch module(s) assets and automatically publish and fix their paths';
|
||||
|
||||
public function __construct(private Controller $controller)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$modules = $this->controller->getModules()
|
||||
->pluck('extra.osm-modules')
|
||||
->map(fn($item) => reset($item))
|
||||
->pluck('moduleName');
|
||||
|
||||
$dev = $this->option('D');
|
||||
$publishes = collect(ServiceProvider::publishableGroups());
|
||||
|
||||
$paths = [];
|
||||
$callbacks = [];
|
||||
foreach ($modules as $module) {
|
||||
$module_assets = $publishes->filter(fn($item) => Str::startsWith($item[0], $module));
|
||||
$paths[] = $module_assets->keys()->toArray();
|
||||
|
||||
$callbacks[] = fn() => $this->call('osm:publish', [
|
||||
'--module' => $module,
|
||||
'--D' => $dev,
|
||||
'--force' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
$watch = Watch::paths(...Arr::flatten($paths));
|
||||
foreach ($callbacks as $callback) {
|
||||
$watch->onAnyChange(function () use ($callback) {
|
||||
$this->info('Change detected! Publishing assets...');
|
||||
$callback();
|
||||
$this->call('osm:dev-server-fix');
|
||||
});
|
||||
}
|
||||
$watch->start();
|
||||
}
|
||||
}
|
@ -43,6 +43,7 @@
|
||||
"maicol07/laravel-json-api-resource": "dev-master",
|
||||
"nette/utils": "^3",
|
||||
"riverskies/laravel-mobile-detect": "^1",
|
||||
"spatie/file-system-watcher": "^1.0",
|
||||
"tightenco/ziggy": "^1",
|
||||
"wikimedia/composer-merge-plugin": "^2"
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user