Skip to content

Commit e355832

Browse files
committed
cache basset blocks on production
1 parent 8c72aba commit e355832

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Console/Commands/BassetCache.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,22 @@ public function handle(): void
6767
->flatMap(function (string $file) {
6868
// Map all bassets
6969
$content = File::get($file);
70+
$bassets = collect();
71+
7072
preg_match_all('/(basset|@bassetArchive|@bassetDirectory)\((.+)\)/', $content, $matches);
73+
foreach ($matches[1] as $i => $type) {
74+
$args = $this->parseBassetArguments($matches[2][$i]);
75+
$bassets->push([$type, $args]);
76+
}
7177

72-
$matches[2] = collect($matches[2])
73-
->map(fn ($match) => $this->parseBassetArguments($match));
78+
preg_match_all('/@bassetBlock\((.+?)\)(.*?)@endBassetBlock/si', $content, $matches);
79+
foreach ($matches[1] as $i => $argsString) {
80+
$args = $this->parseBassetArguments($argsString);
81+
array_splice($args, 1, 0, [$matches[2][$i]]);
82+
$bassets->push(['bassetBlock', $args]);
83+
}
7484

75-
return collect($matches[1])->map(fn (string $type, int $i) => [$type, $matches[2][$i]]);
85+
return $bassets;
7686
});
7787

7888
$totalBassets = count($bassets);
@@ -98,6 +108,10 @@ public function handle(): void
98108
$args[1] = false;
99109
}
100110

111+
if ($type === 'bassetBlock') {
112+
$args[2] = false;
113+
}
114+
101115
try {
102116
if (in_array($type, ['basset', 'bassetArchive', 'bassetDirectory', 'bassetBlock'])) {
103117
$result = Basset::{$type}(...$args)->value;

0 commit comments

Comments
 (0)