Skip to content

Commit 9ed37ac

Browse files
authored
Improve artisan commands (#484)
* Improve commands * update
1 parent 8b37185 commit 9ed37ac

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

src/Console/CreateMiddleware.php renamed to src/Commands/CreateMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Inertia\Console;
3+
namespace Inertia\Commands;
44

55
use Illuminate\Console\GeneratorCommand;
66
use Symfony\Component\Console\Input\InputOption;

src/Console/StartSsr.php renamed to src/Commands/StartSsr.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Inertia\Console;
3+
namespace Inertia\Commands;
44

55
use Illuminate\Console\Command;
66
use Symfony\Component\Process\Process;
@@ -24,15 +24,15 @@ class StartSsr extends Command
2424
/**
2525
* Start the SSR server via a Node process.
2626
*/
27-
public function handle()
27+
public function handle(): int
2828
{
2929
$ssrBundle = config('inertia.ssr.bundle', base_path('bootstrap/ssr/ssr.mjs'));
3030

3131
if (! file_exists($ssrBundle)) {
3232
$this->error('Inertia SSR bundle not found: '.$ssrBundle);
3333
$this->info('Set the correct Inertia SSR bundle path in your `inertia.ssr.bundle` config.');
3434

35-
return 1;
35+
return self::FAILURE;
3636
}
3737

3838
$process = new Process(['node', $ssrBundle]);
@@ -46,5 +46,7 @@ public function handle()
4646
$this->error(trim($data));
4747
}
4848
}
49+
50+
return self::SUCCESS;
4951
}
5052
}

src/Console/StopSsr.php renamed to src/Commands/StopSsr.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Inertia\Console;
3+
namespace Inertia\Commands;
44

55
use Illuminate\Console\Command;
66

@@ -23,21 +23,23 @@ class StopSsr extends Command
2323
/**
2424
* Stop the SSR server.
2525
*/
26-
public function handle()
26+
public function handle(): int
2727
{
2828
$url = str_replace('/render', '', config('inertia.ssr.url', 'http://127.0.0.1:13714')).'/shutdown';
2929

3030
$ch = curl_init($url);
3131
curl_exec($ch);
3232

33-
if (curl_error($ch) === 'Empty reply from server') {
34-
$this->info('Inertia SSR server stopped.');
35-
} else {
33+
if (curl_error($ch) !== 'Empty reply from server') {
3634
$this->error('Unable to connect to Inertia SSR server.');
3735

38-
return 1;
36+
return self::FAILURE;
3937
}
4038

39+
$this->info('Inertia SSR server stopped.');
40+
4141
curl_close($ch);
42+
43+
return self::SUCCESS;
4244
}
4345
}

src/ServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ protected function registerConsoleCommands(): void
6464
}
6565

6666
$this->commands([
67-
Console\CreateMiddleware::class,
68-
Console\StartSsr::class,
69-
Console\StopSsr::class,
67+
Commands\CreateMiddleware::class,
68+
Commands\StartSsr::class,
69+
Commands\StopSsr::class,
7070
]);
7171
}
7272

0 commit comments

Comments
 (0)