mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-09 18:19:27 +01:00
allow plugins to load additionals composer packages
This commit is contained in:
parent
2ee4df8139
commit
72b9a24ac4
29
app/Console/Commands/Plugin/ComposerPluginsCommand.php
Normal file
29
app/Console/Commands/Plugin/ComposerPluginsCommand.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Plugin;
|
||||||
|
|
||||||
|
use App\Facades\Plugins;
|
||||||
|
use App\Models\Plugin;
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class ComposerPluginsCommand extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'p:plugin:composer';
|
||||||
|
|
||||||
|
protected $description = 'Runs composer require on all installed plugins.';
|
||||||
|
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$plugins = Plugin::all();
|
||||||
|
foreach ($plugins as $plugin) {
|
||||||
|
try {
|
||||||
|
Plugins::requireComposerPackages($plugin);
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
report($exception);
|
||||||
|
|
||||||
|
$this->error($exception->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,10 +12,11 @@ class CreatePluginCommand extends Command
|
|||||||
{name}
|
{name}
|
||||||
{author}
|
{author}
|
||||||
{--description=}
|
{--description=}
|
||||||
|
{--category=}
|
||||||
{--url=}
|
{--url=}
|
||||||
{--updateUrl=}
|
{--updateUrl=}
|
||||||
{--panels=}
|
{--panels=}
|
||||||
{--category=}';
|
{--composerPackages=}';
|
||||||
|
|
||||||
protected $description = 'Create a new plugin';
|
protected $description = 'Create a new plugin';
|
||||||
|
|
||||||
@ -61,6 +62,7 @@ class CreatePluginCommand extends Command
|
|||||||
'server' => 'Client Area',
|
'server' => 'Client Area',
|
||||||
'app' => 'Server List',
|
'app' => 'Server List',
|
||||||
], 'admin,server', multiple: true);
|
], 'admin,server', multiple: true);
|
||||||
|
$composerPackages = $this->option('composerPackages') ?? $this->ask('Composer Packages');
|
||||||
|
|
||||||
// Create base directory
|
// Create base directory
|
||||||
$this->filesystem->makeDirectory(plugin_path($id));
|
$this->filesystem->makeDirectory(plugin_path($id));
|
||||||
@ -84,6 +86,7 @@ class CreatePluginCommand extends Command
|
|||||||
'class' => $class,
|
'class' => $class,
|
||||||
'panels' => !is_array($panels) ? explode(',', $panels) : $panels,
|
'panels' => !is_array($panels) ? explode(',', $panels) : $panels,
|
||||||
'panel_version' => config('app.version') === 'canary' ? null : config('app.version'),
|
'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));
|
], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||||
|
|
||||||
// Create src directory and create main class
|
// Create src directory and create main class
|
||||||
|
|||||||
@ -23,6 +23,7 @@ use Sushi\Sushi;
|
|||||||
* @property string $class
|
* @property string $class
|
||||||
* @property string|null $panels
|
* @property string|null $panels
|
||||||
* @property string|null $panel_version
|
* @property string|null $panel_version
|
||||||
|
* @property string|null $composer_packages
|
||||||
* @property PluginStatus $status
|
* @property PluginStatus $status
|
||||||
* @property string|null $status_message
|
* @property string|null $status_message
|
||||||
* @property int $load_order
|
* @property int $load_order
|
||||||
@ -55,6 +56,7 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
'class' => 'string',
|
'class' => 'string',
|
||||||
'panels' => 'string',
|
'panels' => 'string',
|
||||||
'panel_version' => 'string',
|
'panel_version' => 'string',
|
||||||
|
'composer_packages' => 'string',
|
||||||
'status' => 'string',
|
'status' => 'string',
|
||||||
'status_message' => 'string',
|
'status_message' => 'string',
|
||||||
'load_order' => 'integer',
|
'load_order' => 'integer',
|
||||||
@ -75,6 +77,7 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
* class: string,
|
* class: string,
|
||||||
* panels: string,
|
* panels: string,
|
||||||
* panel_version: string,
|
* panel_version: string,
|
||||||
|
* composer_packages: string,
|
||||||
* status: string,
|
* status: string,
|
||||||
* status_message: string,
|
* status_message: string,
|
||||||
* load_order: int
|
* load_order: int
|
||||||
@ -102,6 +105,10 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
$data['panels'] = implode(',', $data['panels']);
|
$data['panels'] = implode(',', $data['panels']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_array($data['composer_packages'])) {
|
||||||
|
$data['composer_packages'] = implode(',', $data['composer_packages']);
|
||||||
|
}
|
||||||
|
|
||||||
$plugins[] = $data;
|
$plugins[] = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,13 +10,14 @@ use Filament\Panel;
|
|||||||
use Illuminate\Console\Application as ConsoleApplication;
|
use Illuminate\Console\Application as ConsoleApplication;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
|
use Illuminate\Support\Composer;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class PluginService
|
class PluginService
|
||||||
{
|
{
|
||||||
public function __construct(private Application $app) {}
|
public function __construct(private Application $app, private Composer $composer) {}
|
||||||
|
|
||||||
public function loadPlugins(): void
|
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');
|
$migrations = plugin_path($plugin->id, 'database', 'migrations');
|
||||||
if (file_exists($migrations)) {
|
if (file_exists($migrations)) {
|
||||||
Artisan::call('migrate', ['--path' => $migrations, '--force' => true]);
|
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
|
public function enablePlugin(string|Plugin $plugin): void
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user