Skip to content

Commit

Permalink
Merge pull request #22 from savannabits/0.x-dev
Browse files Browse the repository at this point in the history
Modification: changed the src path to app in generated modules
  • Loading branch information
coolsam726 authored Apr 8, 2024
2 parents 2d80db9 + d5929c8 commit 68ba841
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
19 changes: 7 additions & 12 deletions config/modular.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
'namespace' => 'Modules',
'vendor' => 'modular',
'directory_tree' => [
'app',
'app/Console',
'app/Console/Commands',
'app/Http',
'app/Http/Controllers',
'app/Models',
'app/Providers',
'bootstrap',
'bootstrap/cache',
'config',
Expand All @@ -20,18 +27,6 @@
'resources/js',
'resources/css',
'routes',
'src',
'src/Console',
'src/Console/Commands',
'src/Exceptions',
'src/Facades',
'src/Http',
'src/Http/Controllers',
'src/Models',
'src/Policies',
'src/Providers',
'src/Support/Concerns',
'src/Support/Contracts',
'storage',
'tests',
],
Expand Down
5 changes: 3 additions & 2 deletions src/Commands/ModuleMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Str;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Savannabits\Modular\Facades\Modular;
use Savannabits\Modular\Support\Concerns\CanManipulateFiles;

use function Laravel\Prompts\text;
Expand Down Expand Up @@ -86,7 +87,7 @@ private function generateModuleComposerFile(): void
],
'autoload' => [
'psr-4' => [
$this->moduleNamespace.'\\' => 'src/',
$this->moduleNamespace.'\\' => 'app/',
$this->moduleNamespace.'\\Database\\Factories\\' => 'database/factories/',
$this->moduleNamespace.'\\Database\\Seeders\\' => 'database/seeders/',
],
Expand Down Expand Up @@ -123,7 +124,7 @@ private function generateModuleComposerFile(): void
*/
private function generateModuleServiceProvider(): void
{
$path = $this->modulePath.'/src/'.$this->moduleStudlyName.'ServiceProvider.php';
$path = Modular::module($this->moduleName)->appPath($this->moduleStudlyName.'ServiceProvider.php');
$namespace = $this->moduleNamespace;
$class = $this->moduleStudlyName.'ServiceProvider';
$this->copyStubToApp('module.provider', $path, [
Expand Down
10 changes: 9 additions & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@ public function factoriesPath(string $path = '', bool $relative = false): string
return $this->databasePath('factories'.DIRECTORY_SEPARATOR.trim($path, DIRECTORY_SEPARATOR), $relative);
}

/**
* @deprecated Use appPath instead
*/
public function srcPath(string $path = '', bool $relative = false): string
{
return $this->path('src'.DIRECTORY_SEPARATOR.trim($path, DIRECTORY_SEPARATOR), $relative);
return $this->appPath($path, $relative);
}

public function appPath(string $path = '', bool $relative = false): string
{
return $this->path('app'.DIRECTORY_SEPARATOR.trim($path, DIRECTORY_SEPARATOR), $relative);
}

public function resourcePath(string $string, bool $relative = false): string
Expand Down
4 changes: 2 additions & 2 deletions src/Support/Concerns/GeneratesModularFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ protected function getPath($name): string
{
$name = Str::replaceFirst($this->rootNamespace(), '', $name);

return $this->getModule()->srcPath(str_replace('\\', '/', $name).'.php');
return $this->getModule()->appPath(str_replace('\\', '/', $name).'.php');
}

protected function possibleModels()
{
$modelPath = $this->getModule()->srcPath('Models');
$modelPath = $this->getModule()->appPath('Models');

return collect(Finder::create()->files()->depth(0)->in($modelPath))
->map(fn ($file) => $file->getBasename('.php'))
Expand Down

0 comments on commit 68ba841

Please sign in to comment.