diff --git a/src/CloudinaryServiceProvider.php b/src/CloudinaryServiceProvider.php index a0630e0..f4cbaaf 100644 --- a/src/CloudinaryServiceProvider.php +++ b/src/CloudinaryServiceProvider.php @@ -14,6 +14,9 @@ public function boot(): void if ($this->app->runningInConsole()) { $this->commands([ Console\InstallCommand::class, + Console\LivewireCommand::class, + Console\ReactCommand::class, + Console\VueCommand::class, ]); } diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 7707c32..3981632 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -11,23 +11,24 @@ class InstallCommand extends Command protected $description = 'Install the Cloudinary Laravel SDK'; - protected function hasLivewire(): bool + public function handle() { - return class_exists(\Livewire\Livewire::class); - } + if ($this->callSilently('vendor:publish', ['--tag' => 'cloudinary-config']) === 0) { + $this->info('Configuration published successfully.'); + } - protected function hasInertia(): bool - { - return class_exists(\Inertia\Inertia::class); + match ($this->getDependencies()) { + 'react' => $this->call('cloudinary:react'), + 'vue' => $this->call('cloudinary:vue'), + 'livewire' => $this->call('cloudinary:livewire'), + default => $this->info('No JavaScript framework detected.'), + }; } - protected function detectInertiaFramework(): ?string + private function getDependencies(): ?string { - if (! File::exists(base_path('package.json'))) { - return null; - } - $package = json_decode(File::get(base_path('package.json')), true); + $dependencies = array_merge( $package['dependencies'] ?? [], $package['devDependencies'] ?? [] @@ -41,73 +42,10 @@ protected function detectInertiaFramework(): ?string return 'vue'; } - if (isset($dependencies['@sveltejs/vite-plugin-svelte'])) { - return 'svelte'; + if (class_exists('Livewire\Livewire')) { + return 'livewire'; } return null; } - - protected function installLivewireComponents(): void - { - // @TODO: implement livewire components publishing - } - - protected function installInertiaComponents(string $framework): void - { - switch ($framework) { - case 'react': - $this->requireNpmPackages(['@cloudinary/react', '@cloudinary/url-gen']); - break; - case 'vue': - $this->requireNpmPackages(['@cloudinary/vue', '@cloudinary/url-gen']); - break; - } - } - - protected function requireNpmPackages(array $packages): void - { - $command = 'npm install '.implode(' ', $packages); - - if (File::exists(base_path('pnpm-lock.yaml'))) { - $command = 'pnpm add '.implode(' ', $packages); - } elseif (File::exists(base_path('yarn.lock'))) { - $command = 'yarn add '.implode(' ', $packages); - } - - // @TODO: run the command - } - - protected function installBladeComponents(): void - { - // @TODO: implement blade components publishing - } - - public function handle() - { - $this->info('Installing Cloudinary Laravel SDK...'); - - $installedComponents = false; - - if ($this->hasLivewire() && $this->confirm('We detected Livewire in your application. Would you like to install the Livewire components?')) { - $this->installLivewireComponents(); - $installedComponents = true; - } - - if (! $installedComponents && $this->hasInertia()) { - $framework = $this->detectInertiaFramework(); - if ($framework && $this->confirm("We detected Inertia.js with {$framework}. Would you like to install the {$framework} components?")) { - $this->installInertiaComponents($framework); - $installedComponents = true; - $this->info("Cloudinary {$framework} components installed successfully."); - } - } - - if (! $installedComponents) { - $this->installBladeComponents(); - $this->info('Blade components installed successfully.'); - } - - $this->info('Cloudinary Laravel SDK installation completed.'); - } } diff --git a/src/Console/LivewireCommand.php b/src/Console/LivewireCommand.php new file mode 100644 index 0000000..1b22aa8 --- /dev/null +++ b/src/Console/LivewireCommand.php @@ -0,0 +1,19 @@ +info('Installing Cloudinary Livewire components...'); + } +} diff --git a/src/Console/ReactCommand.php b/src/Console/ReactCommand.php new file mode 100644 index 0000000..907df54 --- /dev/null +++ b/src/Console/ReactCommand.php @@ -0,0 +1,19 @@ +info('Installing Cloudinary React components...'); + } +} diff --git a/src/Console/VueCommand.php b/src/Console/VueCommand.php new file mode 100644 index 0000000..05f9014 --- /dev/null +++ b/src/Console/VueCommand.php @@ -0,0 +1,19 @@ +info('Installing Cloudinary Vue components...'); + } +}