|
2 | 2 |
|
3 | 3 | namespace EragLaravelPwa\Commands;
|
4 | 4 |
|
| 5 | +use EragLaravelPwa\Services\PWAService; |
5 | 6 | use Illuminate\Console\Command;
|
6 | 7 | use Illuminate\Support\Facades\Config;
|
7 |
| -use Illuminate\Support\Facades\File; |
8 | 8 |
|
9 | 9 | class PWACommand extends Command
|
10 | 10 | {
|
| 11 | + public function __construct(protected PWAService $pwaService) |
| 12 | + { |
| 13 | + parent::__construct(); |
| 14 | + } |
| 15 | + |
11 | 16 | /**
|
12 | 17 | * The name and signature of the console command.
|
13 | 18 | *
|
@@ -53,31 +58,12 @@ public function handle(): void
|
53 | 58 | return;
|
54 | 59 | }
|
55 | 60 |
|
56 |
| - unset($manifest['start_url']); |
57 |
| - $icons = $manifest['icons']; |
58 |
| - unset($manifest['icons']); |
59 |
| - |
60 |
| - $arrayMergeManifest = array_merge($manifest, ['start_url' => '/'], ['icons' => $icons]); |
61 |
| - |
62 |
| - $jsonData = json_encode($arrayMergeManifest, JSON_PRETTY_PRINT); |
63 |
| - if ($jsonData === false) { |
64 |
| - $this->error('Failed to encode manifest array to JSON. Aborting operation.'); |
65 |
| - |
66 |
| - return; |
67 |
| - } |
68 |
| - |
69 |
| - $jsonData = str_replace('\/', '/', $jsonData); |
70 |
| - |
71 |
| - $filePath = public_path('manifest.json'); |
72 |
| - if (! File::isWritable(public_path())) { |
73 |
| - $this->error('Public directory is not writable. Check file permissions.'); |
74 |
| - |
75 |
| - return; |
| 61 | + if ($this->pwaService->createOrUpdate($manifest)) { |
| 62 | + $this->info('Manifest JSON updated successfully ✔'); |
76 | 63 | }
|
77 | 64 |
|
78 |
| - File::put($filePath, $jsonData); |
| 65 | + $this->info('Failed to write the manifest file.'); |
79 | 66 |
|
80 |
| - $this->info('Manifest JSON updated successfully ✔'); |
81 | 67 | } catch (\Exception $e) {
|
82 | 68 | // Catch any errors and display an error message
|
83 | 69 | $this->error('An error occurred while updating the manifest: '.$e->getMessage());
|
|
0 commit comments