Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d263500
feat: enhance PathNamespace trait with clean and namespace formatting…
solomon-ochepa Apr 29, 2025
62d8e47
fix: update composer stub to use APP_PATH_NAMESPACE and APP_PATH inst…
solomon-ochepa Apr 28, 2025
8563991
refactor: enhance path and namespace handling in GeneratorPath class
solomon-ochepa May 9, 2025
8e0eeab
fix: Create `getAppPathNamespaceReplacement()`, and refactor ModuleGe…
solomon-ochepa Apr 29, 2025
15c90ae
Create `GeneratorCommand::default_namespace()`
solomon-ochepa Apr 29, 2025
12a7b69
fix: update app path configuration references to use 'paths.app' inst…
solomon-ochepa Apr 29, 2025
9439d27
refactor: update `module_path` function to use `module` helper and th…
solomon-ochepa May 1, 2025
cdfc9a9
refactor: update paths in config for consistency and clarity
solomon-ochepa May 5, 2025
09354a9
refactor: standardize default namespace retrieval in command classes
solomon-ochepa Apr 29, 2025
f51c99c
fix: update module path to use lowercase 'modules' for consistency
solomon-ochepa May 5, 2025
5607304
refactor: update `getDefaultNamespace()` method to specify default pa…
solomon-ochepa May 5, 2025
84cb1ba
feat: add language files for Recipe module with initial translations
solomon-ochepa May 5, 2025
f223fb5
refactor: streamline app path handling and enhance module namespace r…
solomon-ochepa May 7, 2025
e609dee
tests: Refactor module structure to use 'App' namespace by default fo…
solomon-ochepa May 6, 2025
fac9960
refactor: add PathNamespace trait to Module class for improved path h…
solomon-ochepa May 22, 2025
73c6e6c
fix: correct wording in app path configuration comments for clarity
solomon-ochepa Jun 25, 2025
b6e231b
refactor: update stub files for improved response structure and routi…
solomon-ochepa Jun 25, 2025
ec415f0
feat: add Path helper class for utility methods handling of path and …
solomon-ochepa Jul 4, 2025
2da03c4
refactor: replace custom path cleaning and studlying methods with Pat…
solomon-ochepa Jul 4, 2025
a9eee00
refactor: add deprecated getModuleAppPath and getModuleBasePath metho…
solomon-ochepa Jul 4, 2025
2ed853f
Update snapshot tests
solomon-ochepa Jul 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
'AUTHOR_EMAIL',
'MODULE_NAMESPACE',
'PROVIDER_NAMESPACE',
'APP_FOLDER_NAME',
'APP_PATH_NAMESPACE',
'APP_PATH',
],
],
'gitkeep' => true,
Expand All @@ -85,7 +86,7 @@
| This path will also be added automatically to the list of scanned folders.
|
*/
'modules' => base_path('Modules'),
'modules' => base_path('modules'),

/*
|--------------------------------------------------------------------------
Expand All @@ -110,13 +111,17 @@

/*
|--------------------------------------------------------------------------
| The app path
| app/ path
|--------------------------------------------------------------------------
|
| app folder name
| for example can change it to 'src' or 'App'
| Specifies the path for the app/ directory.
|
| Examples:
| 'app/' = (default Laravel directory),
| 'src/' = (custom directory),
| '/' = (root directory).
*/
'app_folder' => 'app/',
'app' => 'app/',

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -147,7 +152,7 @@
'policies' => ['path' => 'app/Policies', 'generate' => false],
'provider' => ['path' => 'app/Providers', 'generate' => true],
'repository' => ['path' => 'app/Repositories', 'generate' => false],
'resource' => ['path' => 'app/Transformers', 'generate' => false],
'resource' => ['path' => 'app/Resources', 'generate' => false],
'route-provider' => ['path' => 'app/Providers', 'generate' => true],
'rules' => ['path' => 'app/Rules', 'generate' => false],
'services' => ['path' => 'app/Services', 'generate' => false],
Expand Down
6 changes: 2 additions & 4 deletions src/Commands/Actions/ModelShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ private function formatModuleNamespace(string $path): string
return
Str::of($path)
->after(base_path().DIRECTORY_SEPARATOR)
->replace(
[config('modules.paths.app_folder'), '/', '.php'],
['', '\\', ''],
)->toString();
->replace(['/', '.php'], ['\\', ''])
->toString();
}

public function findModels(string $model): Collection
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\Console\PromptsForMissingInput;
use Illuminate\Support\Collection;
use Nwidart\Modules\Contracts\ConfirmableCommand;
use Nwidart\Modules\Traits\PathNamespace;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -18,6 +19,7 @@
abstract class BaseCommand extends Command implements PromptsForMissingInput
{
use ConfirmableTrait;
use PathNamespace;
use Prohibitable;

public const ALL = 'All';
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Make/ActionMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());

$filePath = GenerateConfigReader::read('actions')->getPath() ?? config('modules.paths.app_folder').'Actions';
$filePath = GenerateConfigReader::read('actions')->getPath() ?? config('modules.paths.app').'Actions';

return $path.$filePath.'/'.$this->getActionName().'.php';
}
Expand Down Expand Up @@ -66,7 +66,7 @@ private function getClassNameWithoutNamespace(): array|string

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.actions.namespace', 'Actions');
return $this->default_namespace('actions');
}

protected function getStubName(): string
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Make/CastMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());

$filePath = GenerateConfigReader::read('casts')->getPath() ?? config('modules.paths.app_folder').'Casts';
$filePath = GenerateConfigReader::read('casts')->getPath() ?? config('modules.paths.app').'Casts';

return $path.$filePath.'/'.$this->getCastName().'.php';
}
Expand Down Expand Up @@ -65,7 +65,7 @@ private function getClassNameWithoutNamespace(): array|string

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.casts.namespace', 'Casts');
return $this->default_namespace('casts');
}

protected function getStubName(): string
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/ChannelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ final class ChannelMakeCommand extends GeneratorCommand

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.channels.namespace')
?? ltrim(config('modules.paths.generator.channels.path', 'Broadcasting'), config('modules.paths.app_folder', ''));
return $this->default_namespace('channels');
}

/**
Expand Down
6 changes: 2 additions & 4 deletions src/Commands/Make/ClassMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getDestinationFilePath(): string
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());

$filePath = GenerateConfigReader::read('class')->getPath() ?? config('modules.paths.app_folder').'Classes';
$filePath = GenerateConfigReader::read('class')->getPath() ?? config('modules.paths.app').'Classes';

return $this->typePath($path.$filePath.'/'.$this->getFileName().'.php');
}
Expand Down Expand Up @@ -84,8 +84,6 @@ public function typeClass(): string

public function getDefaultNamespace(): string
{
$type = $this->type();

return config("modules.paths.generator.{$type}.namespace", 'Classes');
return $this->default_namespace($this->type(), $this->app_path("app/{$this->type()}"));
}
}
3 changes: 1 addition & 2 deletions src/Commands/Make/CommandMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class CommandMakeCommand extends GeneratorCommand

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.command.namespace')
?? ltrim(config('modules.paths.generator.command.path', 'Console'), config('modules.paths.app_folder', ''));
return $this->default_namespace('command');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/ComponentClassMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ protected function writeComponentViewTemplate()

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.component-class.namespace')
?? ltrim(config('modules.paths.generator.component-class.path', 'View/Component'), config('modules.paths.app_folder', ''));
return $this->default_namespace('component-class');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/ControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ private function getControllerNameWithoutNamespace()

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.controller.namespace')
?? ltrim(config('modules.paths.generator.controller.path', 'Http/Controllers'), config('modules.paths.app_folder'));
return $this->default_namespace('controller');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Make/EnumMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());

$filePath = GenerateConfigReader::read('enums')->getPath() ?? config('modules.paths.app_folder').'Enums';
$filePath = GenerateConfigReader::read('enums')->getPath() ?? config('modules.paths.app').'Enums';

return $path.$filePath.'/'.$this->getEnumName().'.php';
}
Expand Down Expand Up @@ -65,7 +65,7 @@ private function getClassNameWithoutNamespace(): array|string

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.enums.namespace', 'Enums');
return $this->default_namespace('enums');
}

protected function getStubName(): string
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/EventMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ protected function getFileName()

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.event.namespace')
?? ltrim(config('modules.paths.generator.event.path', 'Events'), config('modules.paths.app_folder', ''));
return $this->default_namespace('event');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/EventProviderMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ private function getClassNameWithoutNamespace(): array|string

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.provider.namespace')
?? ltrim(config('modules.paths.generator.provider.path', 'Providers'), config('modules.paths.app_folder', ''));
return $this->default_namespace('provider');
}

protected function getStubName(): string
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Make/ExceptionMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());

$filePath = GenerateConfigReader::read('exceptions')->getPath() ?? config('modules.paths.app_folder').'Exceptions';
$filePath = GenerateConfigReader::read('exceptions')->getPath() ?? config('modules.paths.app').'Exceptions';

return $path.$filePath.'/'.$this->getExceptionName().'.php';
}
Expand Down Expand Up @@ -67,7 +67,7 @@ private function getClassNameWithoutNamespace(): array|string

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.exceptions.namespace', 'Exceptions');
return $this->default_namespace('exceptions');
}

protected function getStubName(): string
Expand Down
9 changes: 2 additions & 7 deletions src/Commands/Make/FactoryMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,14 @@ private function getModelName()
*/
public function getDefaultNamespace(): string
{
return config('modules.paths.generator.factory.namespace')
?? ltrim(config('modules.paths.generator.factory.path', 'Database/Factories'), config('modules.paths.app_folder', ''));
return $this->default_namespace('factory');
}

/**
* Get model namespace.
*/
public function getModelNamespace(): string
{
$path = ltrim(config('modules.paths.generator.model.path', 'Entities'), config('modules.paths.app_folder', ''));

$path = str_replace('/', '\\', $path);

return $this->laravel['modules']->config('namespace').'\\'.$this->laravel['modules']->findOrFail($this->getModuleName()).'\\'.$path;
return $this->module_namespace($this->argument('module'), $this->default_namespace('model'));
}
}
8 changes: 8 additions & 0 deletions src/Commands/Make/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public function getDefaultNamespace(): string
return '';
}

/**
* Get a default namespace from config.
*/
public function default_namespace(string $key, string $default = ''): string
{
return config("modules.paths.generator.{$key}.namespace") ?? $this->namespace(config("modules.paths.generator.{$key}.path") ?? $default);
}

/**
* Get class namespace.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Make/HelperMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());

$filePath = GenerateConfigReader::read('helpers')->getPath() ?? config('modules.paths.app_folder').'Helpers';
$filePath = GenerateConfigReader::read('helpers')->getPath() ?? config('modules.paths.app').'Helpers';

return $path.$filePath.'/'.$this->getHelperName().'.php';
}
Expand Down Expand Up @@ -66,7 +66,7 @@ private function getClassNameWithoutNamespace(): array|string

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.helpers.namespace', 'Helpers');
return $this->default_namespace('helpers');
}

protected function getStubName(): string
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Make/InterfaceMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getDestinationFilePath(): string
{
$path = $this->laravel['modules']->getModulePath($this->getModuleName());

$filePath = GenerateConfigReader::read('interfaces')->getPath() ?? config('modules.paths.app_folder').'Interfaces';
$filePath = GenerateConfigReader::read('interfaces')->getPath() ?? config('modules.paths.app').'Interfaces';

return $path.$filePath.'/'.$this->getInterfaceName().'.php';
}
Expand Down Expand Up @@ -65,7 +65,7 @@ private function getClassNameWithoutNamespace(): array|string

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.interfaces.namespace', 'Interfaces');
return $this->default_namespace('interfaces');
}

protected function getStubName(): string
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/JobMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class JobMakeCommand extends GeneratorCommand

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.jobs.namespace')
?? ltrim(config('modules.paths.generator.jobs.path', 'Jobs'), config('modules.paths.app_folder', ''));
return $this->default_namespace('jobs');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/ListenerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ protected function getTemplateContents()

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.listener.namespace')
?? ltrim(config('modules.paths.generator.listener.path', 'Listeners'), config('modules.paths.app_folder', ''));
return $this->default_namespace('listener');
}

protected function getEventName(Module $module)
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/MailMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class MailMakeCommand extends GeneratorCommand

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.emails.namespace')
?? ltrim(config('modules.paths.generator.emails.path', 'Emails'), config('modules.paths.app_folder', ''));
return $this->default_namespace('emails');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/MiddlewareMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class MiddlewareMakeCommand extends GeneratorCommand

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.filter.namespace')
?? ltrim(config('modules.paths.generator.filter.path', 'Http/Middleware'), config('modules.paths.app_folder', ''));
return $this->default_namespace('filter');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ private function getFillable(): string
*/
public function getDefaultNamespace(): string
{
return config('modules.paths.generator.model.namespace')
?? ltrim(config('modules.paths.generator.model.path', 'Models'), config('modules.paths.app_folder', ''));
return $this->default_namespace('model');
}
}
3 changes: 1 addition & 2 deletions src/Commands/Make/NotificationMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ final class NotificationMakeCommand extends GeneratorCommand

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.notifications.namespace')
?? ltrim(config('modules.paths.generator.notifications.path', 'Notifications'), config('modules.paths.app_folder', ''));
return $this->default_namespace('notifications');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/ObserverMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public function handle(): int
*/
public function getDefaultNamespace(): string
{
return config('modules.paths.generator.observer.namespace')
?? ltrim(config('modules.paths.generator.observer.path', 'Observers'), config('modules.paths.app_folder', ''));
return $this->default_namespace('observer');
}
}
3 changes: 1 addition & 2 deletions src/Commands/Make/PolicyMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class PolicyMakeCommand extends GeneratorCommand

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.policies.namespace')
?? ltrim(config('modules.paths.generator.policies.path', 'Policies'), config('modules.paths.app_folder', ''));
return $this->default_namespace('policies');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Make/ProviderMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class ProviderMakeCommand extends GeneratorCommand

public function getDefaultNamespace(): string
{
return config('modules.paths.generator.provider.namespace')
?? ltrim(config('modules.paths.generator.provider.path', 'Providers'), config('modules.paths.app_folder', ''));
return $this->default_namespace('provider');
}

/**
Expand Down
Loading