diff --git a/app/Console/Commands/Plugin/ComposerPluginsCommand.php b/app/Console/Commands/Plugin/ComposerPluginsCommand.php new file mode 100644 index 000000000..33319e8ce --- /dev/null +++ b/app/Console/Commands/Plugin/ComposerPluginsCommand.php @@ -0,0 +1,29 @@ +error($exception->getMessage()); + } + } + } +} diff --git a/app/Console/Commands/Plugin/CreatePluginCommand.php b/app/Console/Commands/Plugin/CreatePluginCommand.php index e6fea3b01..5418ed898 100644 --- a/app/Console/Commands/Plugin/CreatePluginCommand.php +++ b/app/Console/Commands/Plugin/CreatePluginCommand.php @@ -12,10 +12,11 @@ class CreatePluginCommand extends Command {name} {author} {--description=} + {--category=} {--url=} {--updateUrl=} {--panels=} - {--category=}'; + {--composerPackages=}'; protected $description = 'Create a new plugin'; @@ -61,6 +62,7 @@ class CreatePluginCommand extends Command 'server' => 'Client Area', 'app' => 'Server List', ], 'admin,server', multiple: true); + $composerPackages = $this->option('composerPackages') ?? $this->ask('Composer Packages'); // Create base directory $this->filesystem->makeDirectory(plugin_path($id)); @@ -84,6 +86,7 @@ class CreatePluginCommand extends Command 'class' => $class, 'panels' => !is_array($panels) ? explode(',', $panels) : $panels, 'panel_version' => config('app.version') === 'canary' ? null : config('app.version'), + 'composer_packages' => !is_array($composerPackages) ? explode(',', $composerPackages) : $composerPackages, ], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); // Create src directory and create main class diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index 16b589d0b..4d0444c48 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -23,6 +23,7 @@ use Sushi\Sushi; * @property string $class * @property string|null $panels * @property string|null $panel_version + * @property string|null $composer_packages * @property PluginStatus $status * @property string|null $status_message * @property int $load_order @@ -55,6 +56,7 @@ class Plugin extends Model implements HasPluginSettings 'class' => 'string', 'panels' => 'string', 'panel_version' => 'string', + 'composer_packages' => 'string', 'status' => 'string', 'status_message' => 'string', 'load_order' => 'integer', @@ -75,6 +77,7 @@ class Plugin extends Model implements HasPluginSettings * class: string, * panels: string, * panel_version: string, + * composer_packages: string, * status: string, * status_message: string, * load_order: int @@ -102,6 +105,10 @@ class Plugin extends Model implements HasPluginSettings $data['panels'] = implode(',', $data['panels']); } + if (is_array($data['composer_packages'])) { + $data['composer_packages'] = implode(',', $data['composer_packages']); + } + $plugins[] = $data; } diff --git a/app/Services/Helpers/PluginService.php b/app/Services/Helpers/PluginService.php index 11be8bd81..75b08dd52 100644 --- a/app/Services/Helpers/PluginService.php +++ b/app/Services/Helpers/PluginService.php @@ -10,13 +10,14 @@ use Filament\Panel; use Illuminate\Console\Application as ConsoleApplication; use Illuminate\Console\Command; use Illuminate\Foundation\Application; +use Illuminate\Support\Composer; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\File; use Illuminate\Support\ServiceProvider; class PluginService { - public function __construct(private Application $app) {} + public function __construct(private Application $app, private Composer $composer) {} public function loadPlugins(): void { @@ -141,14 +142,34 @@ class PluginService } } - public function installPlugin(Plugin $plugin): void + public function requireComposerPackages(Plugin $plugin): void + { + if ($plugin->composer_packages) { + $this->composer->requirePackages(explode(',', $plugin->composer_packages)); + } + } + + public function runPluginMigrations(Plugin $plugin): void { $migrations = plugin_path($plugin->id, 'database', 'migrations'); if (file_exists($migrations)) { Artisan::call('migrate', ['--path' => $migrations, '--force' => true]); } + } - $this->setStatus($plugin, PluginStatus::Enabled); + public function installPlugin(Plugin $plugin): void + { + try { + $this->requireComposerPackages($plugin); + + $this->runPluginMigrations($plugin); + + $this->enablePlugin($plugin); + } catch (Exception $exception) { + report($exception); + + $this->setStatus($plugin, PluginStatus::Errored, $exception->getMessage()); + } } public function enablePlugin(string|Plugin $plugin): void