diff --git a/src/LaraModularServiceProvider.php b/src/LaraModularServiceProvider.php index 0814592..16f879c 100644 --- a/src/LaraModularServiceProvider.php +++ b/src/LaraModularServiceProvider.php @@ -18,18 +18,16 @@ class LaraModularServiceProvider extends ServiceProvider */ private mixed $modules_namespace; private array $modules; - + private array $commands; public function register() { + $this->commands = $this->getCommands(); // merge config $this->mergeConfigFrom( __DIR__ . '/laramodular.php', 'laramodular' ); // register console command - $this->commands([ - MakeModuleCommand::class, - MakeFilamentResourceCommand::class, - ]); + $this->commands($this->commands); // publish config $this->publishes([ __DIR__ . '/laramodular.php' => config_path('laramodular.php'), @@ -182,6 +180,15 @@ protected function registerMiddleware(Router $router, $config, $module) // } } + public function getCommands() : array + { + $commands = [MakeModuleCommand::class]; + if(class_exists("Filament\Commands\MakeResourceCommand")) { + array_push($commands, MakeFilamentResourceCommand::class); + } + return $commands; + } + } diff --git a/src/MakeFilamentResourceCommand.php b/src/MakeFilamentResourceCommand.php index 87976e6..b1b454d 100644 --- a/src/MakeFilamentResourceCommand.php +++ b/src/MakeFilamentResourceCommand.php @@ -5,6 +5,7 @@ use Filament\Support\Commands\Concerns; use Filament\Commands\MakeResourceCommand; use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Facades\File; use Illuminate\Support\Str; use ReflectionClass; @@ -48,6 +49,17 @@ public function handle(): int $this->call('make:module', ['name' => $this->module_name]); } + if (!is_dir(config('laramodular.modules_path') . DIRECTORY_SEPARATOR . $this->module_name)) { + $this->components->warn("Module {$this->module_name} does not exists!"); + $this->call('make:module', ['name' => $this->module_name]); + } +// dd(config('laramodular.modules_path') . DIRECTORY_SEPARATOR . $this->module_name . +// DIRECTORY_SEPARATOR . "Filament/Resources"); + if(!is_dir(config('laramodular.modules_path') . DIRECTORY_SEPARATOR . $this->module_name . DIRECTORY_SEPARATOR . "Filament/Resources")) + { + File::makeDirectory(config('laramodular.modules_path') . DIRECTORY_SEPARATOR . $this->module_name . + DIRECTORY_SEPARATOR . "Filament/Resources", 7777,true); + } $resource = "{$model}Resource"; $resourceClass = "{$modelClass}Resource"; $resourceNamespace = $modelNamespace; @@ -61,10 +73,10 @@ public function handle(): int $baseResourcePath = $this->getBaseResourcePath($resource); $this->namespace = $this->getNamespace($resource); - // dd($this->namespace); $resourcePath = "{$baseResourcePath}.php"; +// dd($resourcePath); $resourcePagesDirectory = "{$baseResourcePath}/Pages"; $listResourcePagePath = "{$resourcePagesDirectory}/{$this->listResourcePageClass}.php"; $manageResourcePagePath = "{$resourcePagesDirectory}/{$this->manageResourcePageClass}.php"; @@ -205,13 +217,12 @@ public function getModelNamespace($model) } public function getBaseResourcePath($resource) - { - $module = config('laramodular.modules_path').'\\'.$this->module_name; - return base_path( - (string) Str::of($resource) - ->prepend($module.'\\Filament\\Resources\\') - ->replace('\\', '/')->replace(base_path(), ''), - ); + { //E:/work/Backend/laravel/lordjooPackage/app/Modules/Categories/Filament/Resources/CategoriesResource + $module = config('laramodular.modules_path').'\\'.$this->module_name; //E:\work\Backend\laravel\lordjooPackage\app/Modules\Categories (module) + return (string) Str::of($module) + ->append('\\Filament\\Resources\\'.$resource) + ->replace('\\', '/'); + } public function pagesCode() diff --git a/src/MakeModuleCommand.php b/src/MakeModuleCommand.php index 178138c..0d908a9 100644 --- a/src/MakeModuleCommand.php +++ b/src/MakeModuleCommand.php @@ -99,7 +99,7 @@ private function makeServiceProviderFile() $stub = file_get_contents(__DIR__ . '/moduleServiceProvider.stub'); $stub = str_replace('{{moduleName}}', $this->module_name, $stub); $stub = str_replace('{{namespace}}', $this->module_namespace, $stub); - + file_put_contents($this->module_path . DIRECTORY_SEPARATOR . $this->module_name . 'ModuleServiceProvider.php', $stub); }