|
3 | 3 | namespace Lomkit\Rest\Console\Commands;
|
4 | 4 |
|
5 | 5 | use Illuminate\Console\Command;
|
| 6 | +use Illuminate\Filesystem\Filesystem; |
6 | 7 | use Illuminate\Support\Str;
|
7 | 8 | use Lomkit\Rest\Console\ResolvesStubPath;
|
8 | 9 |
|
@@ -41,9 +42,39 @@ public function handle()
|
41 | 42 | $this->setAppNamespace();
|
42 | 43 | $this->updateApiRoutes();
|
43 | 44 |
|
| 45 | + $this->uncommentApiRoutesFile(); |
| 46 | + |
44 | 47 | $this->info('Laravel Rest Api is ready. Type \'php artisan route:list\' to see your new routes !');
|
45 | 48 | }
|
46 | 49 |
|
| 50 | + /** |
| 51 | + * Uncomment the API routes file in the application bootstrap file. |
| 52 | + * |
| 53 | + * @return void |
| 54 | + */ |
| 55 | + protected function uncommentApiRoutesFile() |
| 56 | + { |
| 57 | + $appBootstrapPath = $this->laravel->bootstrapPath('app.php'); |
| 58 | + |
| 59 | + $content = file_get_contents($appBootstrapPath); |
| 60 | + |
| 61 | + if (str_contains($content, '// api: ')) { |
| 62 | + (new Filesystem())->replaceInFile( |
| 63 | + '// api: ', |
| 64 | + 'api: ', |
| 65 | + $appBootstrapPath, |
| 66 | + ); |
| 67 | + } elseif (str_contains($content, 'web: __DIR__.\'/../routes/web.php\',') && !str_contains($content, 'api: __DIR__.\'/../routes/api.php\',')) { |
| 68 | + (new Filesystem())->replaceInFile( |
| 69 | + 'web: __DIR__.\'/../routes/web.php\',', |
| 70 | + 'web: __DIR__.\'/../routes/web.php\','.PHP_EOL.' api: __DIR__.\'/../routes/api.php\',', |
| 71 | + $appBootstrapPath, |
| 72 | + ); |
| 73 | + } else { |
| 74 | + $this->components->warn('Unable to automatically add API route definition to bootstrap file. API route file should be registered manually if you did not already run `php artisan install:api`.'); |
| 75 | + } |
| 76 | + } |
| 77 | + |
47 | 78 | /**
|
48 | 79 | * Update the User model namespace in the generated files.
|
49 | 80 | *
|
|
0 commit comments