diff --git a/src/Console/Commands/ModuleMakeComponentCommand.php b/src/Console/Commands/ModuleMakeComponentCommand.php new file mode 100644 index 0000000..49b7c61 --- /dev/null +++ b/src/Console/Commands/ModuleMakeComponentCommand.php @@ -0,0 +1,110 @@ +getModuleInput(); + $filename = Str::studly($this->getNameInput()); + $folder = $this->getFolderPath(); + + $name = $this->qualifyClass($module.'\\'.$folder.'\\'.$filename); + $path = $this->getPath($name); + if ($this->files->exists($path) && ! $this->option('force')) { + $this->logFileExist($name); + + return true; + } + + $type = ''; + + if ($this->option('inline')) { + $type = 'inline.'; + } + + $this->setStubFile("view-component.{$type}"); + $this->makeDirectory($path); + + $this->files->put($path, $this->buildClass($name)); + + if (! $this->option('inline')) { + $this->call( + ModuleMakeViewCommand::class, + [ + 'name' => 'Components/'.Str::snake($filename, '-'), + '--module' => $module, + '--quiet' => true, + ] + ); + } + + $this->logFileCreated($name); + + return true; + } + + protected function buildClass($name): string + { + if ($this->option('inline')) { + return str_replace( + ['{{view}}', '{{ view }}'], + "<<<'blade'\n
\n \n
\nblade", + parent::buildClass($name) + ); + } + + return parent::buildClass($name); + } + + protected function getFolderPath(): string + { + return 'Components'; + } +} diff --git a/src/Console/Commands/ModuleMakeViewCommand.php b/src/Console/Commands/ModuleMakeViewCommand.php index c9946ca..4b6a6ea 100644 --- a/src/Console/Commands/ModuleMakeViewCommand.php +++ b/src/Console/Commands/ModuleMakeViewCommand.php @@ -56,7 +56,7 @@ public function handle() $this->call( ModuleMakeTestCommand::class, [ - 'name' => ($filename), + 'name' => $filename, '--module' => $module, '--pest' => true, '--view' => true, diff --git a/src/Console/Commands/ModuleMakerCommand.php b/src/Console/Commands/ModuleMakerCommand.php index 23a6114..12f44b7 100644 --- a/src/Console/Commands/ModuleMakerCommand.php +++ b/src/Console/Commands/ModuleMakerCommand.php @@ -333,12 +333,16 @@ protected function setStubFile(string $file): void protected function logFileCreated(string $path) { - $this->components->info(sprintf('%s [%s] created successfully.', $this->type, $path)); + if (! $this->hasOption('quiet') || ! $this->option('quiet')) { + $this->components->info(sprintf('%s [%s] created successfully.', $this->type, $path)); + } } protected function logFileExist(string $path) { - $this->components->error(sprintf('%s [%s] already exist.', $this->type, $path)); + if (! $this->hasOption('quiet') || ! $this->option('quiet')) { + $this->components->error(sprintf('%s [%s] already exist.', $this->type, $path)); + } } /** diff --git a/src/Console/Commands/templates/view-component.inline.sample b/src/Console/Commands/templates/view-component.inline.sample new file mode 100644 index 0000000..e5ecb65 --- /dev/null +++ b/src/Console/Commands/templates/view-component.inline.sample @@ -0,0 +1,26 @@ +autoloadHelper($moduleRootPath, $module); $this->autoloadViews($moduleRootPath, $module); $this->autoloadTranslations($moduleRootPath, $module); + $this->autoloadViewComponents($module); } } + } /** @@ -205,6 +209,14 @@ private function autoloadViews(string $moduleRootPath, string $module): void } } + private function autoloadViewComponents(string $module): void + { + Blade::componentNamespace( + "Modules\\{$module}\\Components", + $this->getModuleNamespace(name: $module) + ); + } + private function autoloadTranslations(string $moduleRootPath, string $module): void { $path = "{$moduleRootPath}/{$module}/Lang"; @@ -234,6 +246,7 @@ protected function registerMakeCommand() { $this->commands([ ModuleCommand::class, + ModuleMakeComponentCommand::class, ModuleMakeControllerCommand::class, ModuleMakeEventCommand::class, ModuleMakeJobCommand::class,