Skip to content

Commit 0e6682b

Browse files
Add some stuff
1 parent 23d37e7 commit 0e6682b

38 files changed

+335
-188
lines changed

src/Actions/ConnectReferencesAction.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class ConnectReferencesAction
1414
{
1515
public function __construct(
1616
protected TypeScriptTransformerConfig $config,
17-
public TypeScriptTransformerLog $log,
1817
) {
1918
}
2019

@@ -28,32 +27,31 @@ public function execute(TransformedCollection $collection): ReferenceMap
2827
}
2928
}
3029

31-
$visitor = Visitor::create()->before(function (TypeReference $typeReference, array $metadata) use ($referenceMap, &$references) {
30+
$visitor = Visitor::create()->before(function (TypeReference $typeReference, array &$metadata) use ($referenceMap) {
3231
$reference = $typeReference->reference;
3332

3433
if (! $referenceMap->has($reference)) {
3534
/** @var Transformed $transformed */
3635
$transformed = $metadata['transformed'];
3736

38-
$this->log->warning("Tried replacing reference to `{$reference->humanFriendlyName()}` in `{$transformed->reference->humanFriendlyName()}` but it was not found in the transformed types");
37+
TypeScriptTransformerLog::resolve()->warning("Tried replacing reference to `{$reference->humanFriendlyName()}` in `{$transformed->reference->humanFriendlyName()}` but it was not found in the transformed types");
3938

4039
return;
4140
}
4241

43-
$references[] = $reference;
42+
$metadata['references'][] = $reference;
4443
$typeReference->connect($referenceMap->get($reference));
4544
}, [TypeReference::class]);
4645

4746
foreach ($collection as $transformed) {
48-
$references = [];
49-
5047
$metadata = [
5148
'transformed' => $transformed,
49+
'references' => [],
5250
];
5351

5452
$visitor->execute($transformed->typeScriptNode, $metadata);
5553

56-
$transformed->references = $references;
54+
$transformed->references = $metadata['references'];
5755
}
5856

5957
return $referenceMap;

src/Actions/FormatFilesAction.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ class FormatFilesAction
1010
{
1111
public function __construct(
1212
public TypeScriptTransformerConfig $config,
13-
public TypeScriptTransformerLog $log,
1413
) {
1514
}
1615

1716
/**
18-
* @param array<WrittenFile> $writtenFiles
17+
* @param array<WrittenFile> $writtenFiles
1918
*/
2019
public function execute(array $writtenFiles): void
2120
{
2221
if ($this->config->formatter === null) {
2322
return;
2423
}
2524

26-
foreach ($writtenFiles as $writtenFile) {
27-
$this->config->formatter->format($writtenFile->path);
28-
}
25+
$this->config->formatter->format(
26+
array_map(fn (WrittenFile $writtenFile) => $writtenFile->path, $writtenFiles)
27+
);
2928
}
3029
}

src/Actions/ProvideTypesAction.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class ProvideTypesAction
1111
{
1212
public function __construct(
1313
protected TypeScriptTransformerConfig $config,
14-
public TypeScriptTransformerLog $log,
1514
) {
1615
}
1716

@@ -24,7 +23,6 @@ public function execute(TransformedCollection $collection): void
2423

2524
$defaultTypeProvider->provide(
2625
$this->config,
27-
$this->log,
2826
$collection
2927
);
3028
}

src/Actions/SplitTransformedPerLocationAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function execute(TransformedCollection $collection): array
3030
ksort($split);
3131

3232
foreach ($split as $splitConstruct) {
33-
usort($splitConstruct->transformed, fn (Transformed $a, Transformed $b) => $a->name <=> $b->name);
33+
usort($splitConstruct->transformed, fn (Transformed $a, Transformed $b) => $a->getName() <=> $b->getName());
3434
}
3535

3636
return array_values($split);

src/Actions/WriteTypesAction.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class WriteTypesAction
1212
{
1313
public function __construct(
1414
public TypeScriptTransformerConfig $config,
15-
public TypeScriptTransformerLog $log,
1615
) {
1716
}
1817

src/Formatters/EslintFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
class EslintFormatter implements Formatter
99
{
10-
public function format(string $file): void
10+
public function format(array $files): void
1111
{
12-
$process = new Process(['npx', '--yes', 'eslint', '--fix', '--no-ignore', $file]);
12+
$process = new Process(['npx', '--yes', 'eslint', '--fix', '--no-ignore', ...$files]);
1313
$process->run();
1414

1515
if (! $process->isSuccessful()) {

src/Formatters/Formatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
interface Formatter
66
{
7-
public function format(string $file): void;
7+
public function format(array $files): void;
88
}

src/Formatters/PrettierFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
class PrettierFormatter implements Formatter
99
{
10-
public function format(string $file): void
10+
public function format(array $files): void
1111
{
12-
$process = new Process(['npx', '--yes', 'prettier', '--write', $file]);
12+
$process = new Process(['npx', '--yes', 'prettier', '--write', ...$files]);
1313
$process->run();
1414

1515
if (! $process->isSuccessful()) {

src/Laravel/Commands/TransformTypeScriptCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\TypeScriptTransformer\Laravel\Commands;
44

55
use Illuminate\Console\Command;
6+
use Spatie\TypeScriptTransformer\Support\TypeScriptTransformerLog;
67
use Spatie\TypeScriptTransformer\TypeScriptTransformer;
78

89
class TransformTypeScriptCommand extends Command
@@ -14,7 +15,9 @@ class TransformTypeScriptCommand extends Command
1415
public function handle(
1516
TypeScriptTransformer $typeScriptTransformer
1617
): int {
17-
$log = $typeScriptTransformer->execute();
18+
$typeScriptTransformer->execute();
19+
20+
$log = TypeScriptTransformerLog::resolve();
1821

1922
if (! empty($log->infoMessages)) {
2023
foreach ($log->infoMessages as $infoMessage) {

src/Laravel/LaravelNamedRouteTypesProvider.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(
4747
) {
4848
}
4949

50-
public function provide(TypeScriptTransformerConfig $config, TypeScriptTransformerLog $log, TransformedCollection $types): void
50+
public function provide(TypeScriptTransformerConfig $config, TransformedCollection $types): void
5151
{
5252
$routeCollection = $this->resolveLaravelRoutControllerCollectionsAction->execute(
5353
defaultNamespace: null,
@@ -61,8 +61,7 @@ public function provide(TypeScriptTransformerConfig $config, TypeScriptTransform
6161
$this->parseRouteCollection($routeCollection),
6262
),
6363
$routesListReference = new CustomReference('laravel_named_routes', 'routes_list'),
64-
'NamedRouteList',
65-
$this->location,
64+
$this->location, true,
6665
);
6766

6867
$jsonEncodedRoutes = $this->routeCollectionToJson($routeCollection);
@@ -109,8 +108,7 @@ public function provide(TypeScriptTransformerConfig $config, TypeScriptTransform
109108
)
110109
),
111110
new CustomReference('laravel_named_routes', 'route_function'),
112-
'route',
113-
$this->location,
111+
$this->location, true,
114112
);
115113

116114
$types->add($transformedRoutes, $transformedRoute);

0 commit comments

Comments
 (0)