31 lines
1.2 KiB
PHP
31 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use Illuminate\Http\Request;
|
|
use RuntimeException;
|
|
|
|
final class EzAssets
|
|
{
|
|
public static function scripts(Request $request): array
|
|
{
|
|
$origin = 'http://hn.loc/__hn_vite';
|
|
$marker = storage_path('framework/ez-vite.hot');
|
|
if (in_array($request->getHost(), ['127.0.0.1', 'localhost', '::1', 'hn.loc'], true)
|
|
&& is_file($marker) && trim(file_get_contents($marker)) === $origin) {
|
|
$socket = @fsockopen('127.0.0.1', 5184, $error, $message, 0.1);
|
|
if ($socket) {
|
|
fclose($socket);
|
|
return ['scripts' => ['/__hn_vite/@vite/client', '/__hn_vite/main.js'], 'styles' => []];
|
|
}
|
|
}
|
|
$manifest = base_path('theme/EZ/assets/.vite/manifest.json');
|
|
if (!is_file($manifest)) {
|
|
throw new RuntimeException('EZ assets missing: run npm ci && npm run build:hn in frontends/.');
|
|
}
|
|
$entries = json_decode(file_get_contents($manifest), true, flags: JSON_THROW_ON_ERROR);
|
|
$entry = $entries['index.html'];
|
|
return ['scripts' => ['/theme/EZ/assets/'.$entry['file']], 'styles' => array_map(fn ($file) => '/theme/EZ/assets/'.$file, $entry['css'] ?? [])];
|
|
}
|
|
}
|