)} {--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 */ 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', ]; } }