|
18 | 18 | use function Tempest\uri; |
19 | 19 | use Tempest\View\View; |
20 | 20 | use Tempest\View\ViewRenderer; |
| 21 | +use Throwable; |
21 | 22 |
|
22 | 23 | final readonly class StaticGenerateCommand |
23 | 24 | { |
@@ -57,40 +58,48 @@ public function __invoke(): void |
57 | 58 |
|
58 | 59 | $file = path($publicPath, $fileName); |
59 | 60 |
|
60 | | - $response = $this->router->dispatch( |
61 | | - new GenericRequest( |
62 | | - method: Method::GET, |
63 | | - uri: $uri, |
64 | | - ), |
65 | | - ); |
| 61 | + try { |
| 62 | + $response = $this->router->dispatch( |
| 63 | + new GenericRequest( |
| 64 | + method: Method::GET, |
| 65 | + uri: $uri, |
| 66 | + ), |
| 67 | + ); |
66 | 68 |
|
67 | | - if ($response->getStatus() !== Status::OK) { |
68 | | - $this->writeln("- <error>{$uri}</error> > {$response->getStatus()->value}"); |
| 69 | + if ($response->getStatus() !== Status::OK) { |
| 70 | + $this->writeln("- <error>{$uri}</error> > {$response->getStatus()->value}"); |
69 | 71 |
|
70 | | - continue; |
71 | | - } |
| 72 | + continue; |
| 73 | + } |
72 | 74 |
|
73 | | - $body = $response->getBody(); |
| 75 | + $body = $response->getBody(); |
74 | 76 |
|
75 | | - $content = $body instanceof View |
76 | | - ? $this->viewRenderer->render($body) |
77 | | - : $body; |
| 77 | + $content = $body instanceof View |
| 78 | + ? $this->viewRenderer->render($body) |
| 79 | + : $body; |
78 | 80 |
|
79 | | - if (! is_string($content)) { |
80 | | - $this->writeln("- <error>{$uri}</error> > No textual body"); |
| 81 | + if (! is_string($content)) { |
| 82 | + $this->writeln("- <error>{$uri}</error> > No textual body"); |
81 | 83 |
|
82 | | - continue; |
83 | | - } |
| 84 | + continue; |
| 85 | + } |
84 | 86 |
|
85 | | - $directory = pathinfo($file, PATHINFO_DIRNAME); |
| 87 | + $directory = pathinfo($file, PATHINFO_DIRNAME); |
86 | 88 |
|
87 | | - if (! is_dir($directory)) { |
88 | | - mkdir($directory, recursive: true); |
89 | | - } |
| 89 | + if (! is_dir($directory)) { |
| 90 | + mkdir($directory, recursive: true); |
| 91 | + } |
90 | 92 |
|
91 | | - file_put_contents($file, $content); |
| 93 | + file_put_contents($file, $content); |
92 | 94 |
|
93 | | - $this->writeln("- <em>{$uri}</em> > <u>{$file}</u>"); |
| 95 | + $this->writeln("- <em>{$uri}</em> > <u>{$file}</u>"); |
| 96 | + } catch (Throwable $e) { |
| 97 | + $this->writeln("- <error>{$uri}</error> {$e->getMessage()}"); |
| 98 | + |
| 99 | + ob_get_clean(); |
| 100 | + |
| 101 | + continue; |
| 102 | + } |
94 | 103 | } |
95 | 104 | } |
96 | 105 |
|
|
0 commit comments