@@ -11,23 +11,24 @@ class InstallCommand extends Command
11
11
12
12
protected $ description = 'Install the Cloudinary Laravel SDK ' ;
13
13
14
- protected function hasLivewire (): bool
14
+ public function handle ()
15
15
{
16
- return class_exists (\Livewire \Livewire::class);
17
- }
16
+ if ($ this ->callSilently ('vendor:publish ' , ['--tag ' => 'cloudinary-config ' ]) === 0 ) {
17
+ $ this ->info ('Configuration published successfully. ' );
18
+ }
18
19
19
- protected function hasInertia (): bool
20
- {
21
- return class_exists (\Inertia \Inertia::class);
20
+ match ($ this ->getDependencies ()) {
21
+ 'react ' => $ this ->call ('cloudinary:react ' ),
22
+ 'vue ' => $ this ->call ('cloudinary:vue ' ),
23
+ 'livewire ' => $ this ->call ('cloudinary:livewire ' ),
24
+ default => $ this ->info ('No JavaScript framework detected. ' ),
25
+ };
22
26
}
23
27
24
- protected function detectInertiaFramework (): ?string
28
+ private function getDependencies (): ?string
25
29
{
26
- if (! File::exists (base_path ('package.json ' ))) {
27
- return null ;
28
- }
29
-
30
30
$ package = json_decode (File::get (base_path ('package.json ' )), true );
31
+
31
32
$ dependencies = array_merge (
32
33
$ package ['dependencies ' ] ?? [],
33
34
$ package ['devDependencies ' ] ?? []
@@ -41,73 +42,10 @@ protected function detectInertiaFramework(): ?string
41
42
return 'vue ' ;
42
43
}
43
44
44
- if (isset ( $ dependencies [ ' @sveltejs/vite-plugin-svelte ' ] )) {
45
- return 'svelte ' ;
45
+ if (class_exists ( ' Livewire\Livewire ' )) {
46
+ return 'livewire ' ;
46
47
}
47
48
48
49
return null ;
49
50
}
50
-
51
- protected function installLivewireComponents (): void
52
- {
53
- // @TODO: implement livewire components publishing
54
- }
55
-
56
- protected function installInertiaComponents (string $ framework ): void
57
- {
58
- switch ($ framework ) {
59
- case 'react ' :
60
- $ this ->requireNpmPackages (['@cloudinary/react ' , '@cloudinary/url-gen ' ]);
61
- break ;
62
- case 'vue ' :
63
- $ this ->requireNpmPackages (['@cloudinary/vue ' , '@cloudinary/url-gen ' ]);
64
- break ;
65
- }
66
- }
67
-
68
- protected function requireNpmPackages (array $ packages ): void
69
- {
70
- $ command = 'npm install ' .implode (' ' , $ packages );
71
-
72
- if (File::exists (base_path ('pnpm-lock.yaml ' ))) {
73
- $ command = 'pnpm add ' .implode (' ' , $ packages );
74
- } elseif (File::exists (base_path ('yarn.lock ' ))) {
75
- $ command = 'yarn add ' .implode (' ' , $ packages );
76
- }
77
-
78
- // @TODO: run the command
79
- }
80
-
81
- protected function installBladeComponents (): void
82
- {
83
- // @TODO: implement blade components publishing
84
- }
85
-
86
- public function handle ()
87
- {
88
- $ this ->info ('Installing Cloudinary Laravel SDK... ' );
89
-
90
- $ installedComponents = false ;
91
-
92
- if ($ this ->hasLivewire () && $ this ->confirm ('We detected Livewire in your application. Would you like to install the Livewire components? ' )) {
93
- $ this ->installLivewireComponents ();
94
- $ installedComponents = true ;
95
- }
96
-
97
- if (! $ installedComponents && $ this ->hasInertia ()) {
98
- $ framework = $ this ->detectInertiaFramework ();
99
- if ($ framework && $ this ->confirm ("We detected Inertia.js with {$ framework }. Would you like to install the {$ framework } components? " )) {
100
- $ this ->installInertiaComponents ($ framework );
101
- $ installedComponents = true ;
102
- $ this ->info ("Cloudinary {$ framework } components installed successfully. " );
103
- }
104
- }
105
-
106
- if (! $ installedComponents ) {
107
- $ this ->installBladeComponents ();
108
- $ this ->info ('Blade components installed successfully. ' );
109
- }
110
-
111
- $ this ->info ('Cloudinary Laravel SDK installation completed. ' );
112
- }
113
51
}
0 commit comments