Plugin-SDK: Oberflächen für Kunden-Plugins, Generator, Doku (0.20.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m46s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m7s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m8s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m51s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m12s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m11s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m33s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 04:57:28 +00:00
parent 46b7b05f94
commit ea2200cb3e
353 changed files with 2151 additions and 1542 deletions

View file

@ -0,0 +1,123 @@
<?php
namespace App\Console\Commands;
use App\Plugins\PluginManifest;
use App\Version;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
/**
* Plugin-Generator (Plugin-SDK): erzeugt ein lauffähiges Plugin-Gerüst mit Seite,
* Startseiten-Kachel, Build-Voreinstellung und Paketier-Skript.
*/
class MakePlugin extends Command
{
protected $signature = 'inhaus:make-plugin
{slug : Kürzel, z. B. „mav-kalender“ (Kleinbuchstaben, Ziffern, Bindestriche)}
{--name= : Anzeigename, z. B. „MAV-Kalender“}
{--author= : Autor oder Organisation}
{--path= : Zielordner (Standard: plugins/<slug>)}
{--force : Vorhandenen Ordner überschreiben}';
protected $description = 'Neues Plugin mit Oberfläche anlegen (Plugin-SDK)';
public function handle(): int
{
$slug = (string) $this->argument('slug');
if (! preg_match(PluginManifest::SLUG_PATTERN, $slug)) {
$this->error('Das Kürzel darf nur Kleinbuchstaben, Ziffern und Bindestriche enthalten.');
return self::FAILURE;
}
$target = rtrim((string) ($this->option('path') ?: base_path('plugins/'.$slug)), '/');
if (is_dir($target) && ! $this->option('force')) {
$this->error("{$target} existiert bereits (--force zum Überschreiben).");
return self::FAILURE;
}
$studly = Str::studly($slug);
$namespace = 'Inhaus\\Plugins\\'.$studly;
$name = (string) ($this->option('name') ?: Str::headline($slug));
$versions = $this->frontendVersions();
$values = [
'{{slug}}' => $slug,
'{{name}}' => $name,
'{{studly}}' => $studly,
'{{namespace}}' => $namespace,
'{{namespaceJson}}' => str_replace('\\', '\\\\', $namespace),
'{{author}}' => (string) ($this->option('author') ?: 'Unbekannt'),
'{{description}}' => "{$name} – ein Plugin für Inhaus.",
'{{coreVersion}}' => Version::VERSION,
'{{v_vite}}' => $versions['vite'],
'{{v_vue}}' => $versions['vue'],
'{{v_plugin_vue}}' => $versions['@vitejs/plugin-vue'],
'{{v_tailwind}}' => $versions['tailwindcss'],
'{{v_tailwind_vite}}' => $versions['@tailwindcss/vite'],
];
$files = [
'plugin.json' => 'plugin.json.stub',
"src/{$studly}Plugin.php" => 'Plugin.php.stub',
'src/Http/Controllers/IndexController.php' => 'Controller.php.stub',
'routes/web.php' => 'web.php.stub',
'resources/js/pages/Index.vue' => 'Index.vue.stub',
'resources/js/widgets/Hello.vue' => 'Hello.vue.stub',
'resources/css/style.css' => 'style.css.stub',
'vite.config.js' => 'vite.config.js.stub',
'package.json' => 'package.json.stub',
'bin/package' => 'package.stub',
'README.md' => 'README.md.stub',
];
foreach ($files as $file => $stub) {
$this->write("{$target}/{$file}", strtr((string) file_get_contents(base_path("sdk/stubs/{$stub}")), $values));
}
// Build-Voreinstellung und Design-Tokens aus dem Portal mitgeben
$this->write("{$target}/inhaus-sdk/vite.js", (string) file_get_contents(base_path('sdk/vite.js')));
$this->write("{$target}/inhaus-sdk/theme.css", (string) file_get_contents(base_path('sdk/theme.css')));
$this->write("{$target}/.gitignore", "node_modules/\n*.zip\n");
@chmod("{$target}/bin/package", 0755);
$this->info("Plugin „{$name}“ angelegt: {$target}");
$this->line('Weiter:');
$this->line(" cd {$target} && npm install && npm run build");
$this->line(' Dann unter Administration → Plugins aktivieren (liegt es unter plugins/, erscheint es dort direkt).');
return self::SUCCESS;
}
private function write(string $path, string $content): void
{
if (! is_dir(dirname($path))) {
mkdir(dirname($path), 0775, true);
}
file_put_contents($path, $content);
}
/**
* Gleiche Versionen wie im Portal, damit Vue-Compiler und Laufzeit zusammenpassen.
*
* @return array<string, string>
*/
private function frontendVersions(): array
{
$package = json_decode((string) @file_get_contents(base_path('package.json')), true) ?: [];
$all = [...($package['dependencies'] ?? []), ...($package['devDependencies'] ?? [])];
return [
'vite' => $all['vite'] ?? '^8.0.0',
'vue' => $all['vue'] ?? '^3.5.0',
'@vitejs/plugin-vue' => $all['@vitejs/plugin-vue'] ?? '^6.0.0',
'tailwindcss' => $all['tailwindcss'] ?? '^4.0.0',
'@tailwindcss/vite' => $all['@tailwindcss/vite'] ?? '^4.0.0',
];
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace App\Http\Controllers;
use App\Plugins\PluginAssets;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
/**
* Liefert vorkompilierte Oberflächen von Kunden-Plugins aus (plugins/<slug>/dist).
* Die Version steht in der Adresse – daher dürfen Browser lange zwischenspeichern.
*/
class PluginAssetController extends Controller
{
public function __invoke(PluginAssets $assets, string $slug, string $version, string $path): BinaryFileResponse
{
$file = $assets->file($slug, $path);
abort_unless($file, 404);
return response()->file($file, [
'Content-Type' => PluginAssets::TYPES[strtolower(pathinfo($file, PATHINFO_EXTENSION))],
'Cache-Control' => 'public, max-age=31536000, immutable',
'X-Content-Type-Options' => 'nosniff',
]);
}
}

View file

@ -0,0 +1,105 @@
<?php
namespace App\Plugins;
use App\Version;
/**
* Vorkompilierte Oberflächen separat installierter Plugins (Plugin-SDK).
*
* Ein Plugin bringt unter dist/ ES-Module und optional CSS mit und beschreibt sie in
* dist/inhaus.json:
*
* { "components": { "pages/Index": "pages/Index.js", "widgets/Verse": "widgets/Verse.js" },
* "css": ["style.css"] }
*
* Mitgelieferte Plugins brauchen das nicht – sie sind Teil des Portal-Builds.
*/
class PluginAssets
{
public const MANIFEST = 'dist/inhaus.json';
/** Dateitypen, die ausgeliefert werden */
public const TYPES = [
'js' => 'text/javascript', 'mjs' => 'text/javascript', 'css' => 'text/css', 'map' => 'application/json',
'json' => 'application/json', 'svg' => 'image/svg+xml', 'png' => 'image/png', 'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg', 'webp' => 'image/webp', 'gif' => 'image/gif', 'woff2' => 'font/woff2',
];
/** @var array<string, array{base: string, components: array<string, string>, css: list<string>}>|null */
private ?array $cache = null;
public function __construct(private readonly PluginManager $plugins) {}
/**
* Für das Frontend (window.__inhausPlugins): aktive Plugins mit Oberfläche.
*
* @return array<string, array{base: string, components: array<string, string>, css: list<string>}>
*/
public function forFrontend(): array
{
if ($this->cache !== null) {
return $this->cache;
}
$this->cache = [];
foreach ($this->plugins->loaded() as $slug => $plugin) {
$manifest = $plugin->manifest;
if ($manifest->core || ! is_file($manifest->path.'/'.self::MANIFEST)) {
continue;
}
$data = json_decode((string) file_get_contents($manifest->path.'/'.self::MANIFEST), true);
if (! is_array($data)) {
continue;
}
$clean = fn ($file) => is_string($file) && preg_match('#^[A-Za-z0-9_./-]+$#', $file) && ! str_contains($file, '..') ? $file : null;
$this->cache[$slug] = [
'base' => '/plugin-assets/'.rawurlencode($slug).'/'.rawurlencode($manifest->version).'/',
'components' => array_filter(array_map($clean, (array) ($data['components'] ?? []))),
'css' => array_values(array_filter(array_map($clean, (array) ($data['css'] ?? [])))),
];
}
return $this->cache;
}
/**
* Import Map für Plugins: dieselben Module wie im Portal.
*
* @return array{imports: array<string, string>}
*/
public static function importMap(): array
{
$v = '?v='.Version::VERSION;
return ['imports' => [
'vue' => '/sdk/vue.js'.$v,
'@inertiajs/vue3' => '/sdk/inertia.js'.$v,
'@inhaus/ui' => '/sdk/ui.js'.$v,
]];
}
/**
* Pfad einer ausgelieferten Datei – nur aus dist/ eines aktiven Kunden-Plugins.
*/
public function file(string $slug, string $path): ?string
{
$plugin = $this->plugins->loaded()[$slug] ?? null;
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if (! $plugin || $plugin->manifest->core || ! isset(self::TYPES[$extension]) || str_contains($path, '..')) {
return null;
}
$dist = realpath($plugin->manifest->path.'/dist');
$file = realpath($plugin->manifest->path.'/dist/'.$path);
return $dist && $file && str_starts_with($file, $dist.DIRECTORY_SEPARATOR) && is_file($file) ? $file : null;
}
}

View file

@ -4,6 +4,7 @@ namespace App\Providers;
use App\Dashboard\Widgets;
use App\Plugins\Hooks;
use App\Plugins\PluginAssets;
use App\Plugins\PluginManager;
use App\Plugins\PluginState;
use App\Profile\ProfilePanels;
@ -28,6 +29,7 @@ class PluginServiceProvider extends ServiceProvider
$this->app->singleton(Abilities::class);
$this->app->singleton(ProfileSections::class);
$this->app->singleton(ProfilePanels::class);
$this->app->singleton(PluginAssets::class);
$this->app->make(PluginManager::class)->registerAll();
}

View file

@ -9,5 +9,5 @@ namespace App;
*/
final class Version
{
public const VERSION = '0.19.7';
public const VERSION = '0.20.0';
}