From 9ac70c593f74c49c004364bf3e8e246353f7bf4c Mon Sep 17 00:00:00 2001 From: Massimo Triassi Date: Mon, 20 Nov 2023 17:00:55 -0500 Subject: [PATCH] feat: #3 add command to create new modules on the fly --- src/Commands/ContentMakeCommand.php | 61 +++++++++++++++++++++++++++++ src/Commands/stubs/content.php.stub | 17 ++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/Commands/ContentMakeCommand.php create mode 100644 src/Commands/stubs/content.php.stub diff --git a/src/Commands/ContentMakeCommand.php b/src/Commands/ContentMakeCommand.php new file mode 100644 index 0000000..81122cd --- /dev/null +++ b/src/Commands/ContentMakeCommand.php @@ -0,0 +1,61 @@ +confirm('Would you like to use App\\Models\\Content as the name space for all generated content?')) { + File::makeDirectory(app_path('Models/Content')); + } + + parent::handle(); + } + + protected function getStub() + { + return $this->resolveStubPath("/stubs/content.php.stub"); + } + + /** + * Resolve the fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveStubPath($stub) + { + return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__.$stub; + } + + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + * @return string + */ + protected function getDefaultNamespace($rootNamespace) + { + return is_dir(app_path('Models/Content')) ? $rootNamespace.'\\Models\\Content' : $rootNamespace.'\\Models'; + } + +} \ No newline at end of file diff --git a/src/Commands/stubs/content.php.stub b/src/Commands/stubs/content.php.stub new file mode 100644 index 0000000..f33e71b --- /dev/null +++ b/src/Commands/stubs/content.php.stub @@ -0,0 +1,17 @@ +