1
0
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:
Maicol Battistini 2022-02-14 18:15:55 +01:00
parent 391ef82c1a
commit a53182276f
No known key found for this signature in database
GPG Key ID: 4FDB0F87CDB1D34A
2 changed files with 57 additions and 0 deletions

View 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();
}
}

View File

@ -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"
},