|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Hyde\Facades; |
|
6
|
|
|
|
|
7
|
|
|
use Hyde\Hyde; |
|
8
|
|
|
use Illuminate\Support\Str; |
|
9
|
|
|
|
|
10
|
|
|
use function sprintf; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* HydeFront is the NPM package that bundles the default precompiled CSS and JavaScript assets for HydePHP. |
|
14
|
|
|
* |
|
15
|
|
|
* This facade makes it easy to access these assets from the HydeFront CDN, automatically getting the correct version. |
|
16
|
|
|
*/ |
|
17
|
|
|
class HydeFront |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var string The HydeFront SemVer tag to load. This constant is set to match the styles used for the installed framework version. */ |
|
20
|
|
|
protected const HYDEFRONT_VERSION = 'v4.0'; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string The HydeFront CDN path pattern used to assemble CDN links. */ |
|
23
|
|
|
protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@%s/dist/%s'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Get the current version of the HydeFront package. |
|
27
|
|
|
* |
|
28
|
|
|
* @return string {@see HYDEFRONT_VERSION} |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function version(): string |
|
31
|
|
|
{ |
|
32
|
|
|
return static::HYDEFRONT_VERSION; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** Get the CDN link for the HydeFront CSS file. This will return the default `app.css` file. */ |
|
36
|
|
|
public static function cdnLink(): string |
|
37
|
|
|
{ |
|
38
|
|
|
return sprintf(static::HYDEFRONT_CDN_URL, static::version(), 'app.css'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** This method is used to inject the project's Tailwind CSS configuration into the Play CDN integration so it can match the styles. */ |
|
42
|
|
|
public static function injectTailwindConfig(): string |
|
43
|
|
|
{ |
|
44
|
|
|
if (! file_exists(Hyde::path('tailwind.config.js'))) { |
|
|
|
|
|
|
45
|
|
|
return ''; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$config = Str::between(file_get_contents(Hyde::path('tailwind.config.js')), '{', '}'); |
|
49
|
|
|
|
|
50
|
|
|
// Remove the plugins array, as it is not used in the frontend build. |
|
51
|
|
|
if (str_contains($config, 'plugins: [')) { |
|
52
|
|
|
$tokens = explode('plugins: [', $config, 2); |
|
53
|
|
|
$tokens[1] = Str::after($tokens[1], ']'); |
|
54
|
|
|
$config = implode('', $tokens); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return preg_replace('/\s+/', ' ', "/* tailwind.config.js */ \n".rtrim($config, ",\n\r")); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|