Skip to content

Commit

Permalink
Adding updates to plugin manager
Browse files Browse the repository at this point in the history
  • Loading branch information
tnylea committed Oct 13, 2024
1 parent 3d1268c commit 0a29e58
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
34 changes: 34 additions & 0 deletions app/Filament/Pages/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Filament\Notifications\Notification;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Artisan;

class Plugins extends Page
{
Expand Down Expand Up @@ -84,6 +85,8 @@ public function activate($pluginFolder)
$installedPlugins[] = $pluginFolder;
$this->updateInstalledPlugins($installedPlugins);

$this->runPostActivationCommands($pluginFolder);

Notification::make()
->title('Successfully activated ' . $pluginFolder . ' plugin')
->success()
Expand All @@ -93,6 +96,37 @@ public function activate($pluginFolder)
$this->refreshPlugins();
}

private function runPostActivationCommands($pluginFolder)
{
$studlyFolderName = Str::studly($pluginFolder);
$pluginClass = "Wave\\Plugins\\{$studlyFolderName}\\{$studlyFolderName}Plugin";

if (class_exists($pluginClass)) {
$plugin = new $pluginClass(app());

if (method_exists($plugin, 'getPostActivationCommands')) {
$commands = $plugin->getPostActivationCommands();

foreach ($commands as $command) {
if (is_string($command)) {
Artisan::call($command);
} elseif (is_callable($command)) {
$command();
}
}
}

// Run migrations if they exist
$migrationPath = resource_path("plugins/{$pluginFolder}/database/migrations");
if (File::isDirectory($migrationPath)) {
Artisan::call('migrate', [
'--path' => "resources/plugins/{$pluginFolder}/database/migrations",
'--force' => true,
]);
}
}
}

public function deactivate($pluginFolder)
{
$installedPlugins = $this->getInstalledPlugins();
Expand Down
5 changes: 5 additions & 0 deletions wave/src/Plugins/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public function boot()

// You can add additional methods that plugins should implement
abstract public function getPluginInfo(): array;

public function postActivation()
{
// Default implementation (empty)
}
}
13 changes: 13 additions & 0 deletions wave/src/Plugins/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ protected function findPluginFile($pluginName)
return null;
}

protected function runPostActivationCommands(Plugin $plugin)
{
$commands = $plugin->getPostActivationCommands();

foreach ($commands as $command) {
if (is_string($command)) {
Artisan::call($command);
} elseif (is_callable($command)) {
$command();
}
}
}

protected function getInstalledPlugins()
{
$path = resource_path('plugins/installed.json');
Expand Down

0 comments on commit 0a29e58

Please sign in to comment.