Skip to content

Commit 1ba85c6

Browse files
committed
view repo optimizations
1 parent b1efadb commit 1ba85c6

File tree

2 files changed

+66
-74
lines changed

2 files changed

+66
-74
lines changed

php-templates/views.php

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,57 @@
11
<?php
22

3-
function vsCodeFindBladeFiles($path)
4-
{
5-
$paths = [];
3+
$blade = new class {
4+
public function findFiles($path)
5+
{
6+
$paths = [];
67

7-
if (!is_dir($path)) {
8-
return $paths;
9-
}
8+
if (!is_dir($path)) {
9+
return $paths;
10+
}
1011

11-
foreach (
12-
\Symfony\Component\Finder\Finder::create()
12+
$files = \Symfony\Component\Finder\Finder::create()
1313
->files()
1414
->name("*.blade.php")
15-
->in($path)
16-
as $file
17-
) {
18-
$paths[] = [
19-
"path" => str_replace(base_path(DIRECTORY_SEPARATOR), '', $file->getRealPath()),
20-
"isVendor" => str_contains($file->getRealPath(), base_path("vendor")),
21-
"key" => \Illuminate\Support\Str::of($file->getRealPath())
22-
->replace(realpath($path), "")
23-
->replace(".blade.php", "")
24-
->ltrim(DIRECTORY_SEPARATOR)
25-
->replace(DIRECTORY_SEPARATOR, ".")
26-
];
15+
->in($path);
16+
17+
foreach ($files as $file) {
18+
$paths[] = [
19+
"path" => str_replace(base_path(DIRECTORY_SEPARATOR), '', $file->getRealPath()),
20+
"isVendor" => str_contains($file->getRealPath(), base_path("vendor")),
21+
"key" => \Illuminate\Support\Str::of($file->getRealPath())
22+
->replace(realpath($path), "")
23+
->replace(".blade.php", "")
24+
->ltrim(DIRECTORY_SEPARATOR)
25+
->replace(DIRECTORY_SEPARATOR, ".")
26+
];
27+
}
28+
29+
return $paths;
2730
}
31+
};
2832

29-
return $paths;
30-
}
3133
$paths = collect(
3234
app("view")
3335
->getFinder()
3436
->getPaths()
35-
)->flatMap(function ($path) {
36-
return vsCodeFindBladeFiles($path);
37-
});
37+
)->flatMap(fn($path) => $blade->findFiles($path));
3838

3939
$hints = collect(
4040
app("view")
4141
->getFinder()
4242
->getHints()
43-
)->flatMap(function ($paths, $key) {
44-
return collect($paths)->flatMap(function ($path) use ($key) {
45-
return collect(vsCodeFindBladeFiles($path))->map(function ($value) use (
46-
$key
47-
) {
48-
return array_merge($value, ["key" => "{$key}::{$value["key"]}"]);
49-
});
50-
});
51-
});
43+
)->flatMap(
44+
fn($paths, $key) => collect($paths)->flatMap(
45+
fn($path) => collect($blade->findFiles($path))->map(
46+
fn($value) => array_merge($value, ["key" => "{$key}::{$value["key"]}"])
47+
)
48+
)
49+
);
5250

5351
[$local, $vendor] = $paths
5452
->merge($hints)
5553
->values()
56-
->partition(function ($v) {
57-
return !$v["isVendor"];
58-
});
54+
->partition(fn($v) => !$v["isVendor"]);
5955

6056
echo $local
6157
->sortBy("key", SORT_NATURAL)

src/templates/views.ts

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,57 @@
11
// This file was generated from php-templates/views.php, do not edit directly
22
export default `
3-
function vsCodeFindBladeFiles($path)
4-
{
5-
$paths = [];
3+
$blade = new class {
4+
public function findFiles($path)
5+
{
6+
$paths = [];
67
7-
if (!is_dir($path)) {
8-
return $paths;
9-
}
8+
if (!is_dir($path)) {
9+
return $paths;
10+
}
1011
11-
foreach (
12-
\\Symfony\\Component\\Finder\\Finder::create()
12+
$files = \\Symfony\\Component\\Finder\\Finder::create()
1313
->files()
1414
->name("*.blade.php")
15-
->in($path)
16-
as $file
17-
) {
18-
$paths[] = [
19-
"path" => str_replace(base_path(DIRECTORY_SEPARATOR), '', $file->getRealPath()),
20-
"isVendor" => str_contains($file->getRealPath(), base_path("vendor")),
21-
"key" => \\Illuminate\\Support\\Str::of($file->getRealPath())
22-
->replace(realpath($path), "")
23-
->replace(".blade.php", "")
24-
->ltrim(DIRECTORY_SEPARATOR)
25-
->replace(DIRECTORY_SEPARATOR, ".")
26-
];
15+
->in($path);
16+
17+
foreach ($files as $file) {
18+
$paths[] = [
19+
"path" => str_replace(base_path(DIRECTORY_SEPARATOR), '', $file->getRealPath()),
20+
"isVendor" => str_contains($file->getRealPath(), base_path("vendor")),
21+
"key" => \\Illuminate\\Support\\Str::of($file->getRealPath())
22+
->replace(realpath($path), "")
23+
->replace(".blade.php", "")
24+
->ltrim(DIRECTORY_SEPARATOR)
25+
->replace(DIRECTORY_SEPARATOR, ".")
26+
];
27+
}
28+
29+
return $paths;
2730
}
31+
};
2832
29-
return $paths;
30-
}
3133
$paths = collect(
3234
app("view")
3335
->getFinder()
3436
->getPaths()
35-
)->flatMap(function ($path) {
36-
return vsCodeFindBladeFiles($path);
37-
});
37+
)->flatMap(fn($path) => $blade->findFiles($path));
3838
3939
$hints = collect(
4040
app("view")
4141
->getFinder()
4242
->getHints()
43-
)->flatMap(function ($paths, $key) {
44-
return collect($paths)->flatMap(function ($path) use ($key) {
45-
return collect(vsCodeFindBladeFiles($path))->map(function ($value) use (
46-
$key
47-
) {
48-
return array_merge($value, ["key" => "{$key}::{$value["key"]}"]);
49-
});
50-
});
51-
});
43+
)->flatMap(
44+
fn($paths, $key) => collect($paths)->flatMap(
45+
fn($path) => collect($blade->findFiles($path))->map(
46+
fn($value) => array_merge($value, ["key" => "{$key}::{$value["key"]}"])
47+
)
48+
)
49+
);
5250
5351
[$local, $vendor] = $paths
5452
->merge($hints)
5553
->values()
56-
->partition(function ($v) {
57-
return !$v["isVendor"];
58-
});
54+
->partition(fn($v) => !$v["isVendor"]);
5955
6056
echo $local
6157
->sortBy("key", SORT_NATURAL)

0 commit comments

Comments
 (0)