Skip to content

Commit bd6f9a6

Browse files
committed
wip
1 parent 756ab92 commit bd6f9a6

File tree

7 files changed

+24
-17
lines changed

7 files changed

+24
-17
lines changed

src/Commands/InstallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function handle(): int
3333
if ($dirExists) {
3434
File::deleteDirectory(base_path('modules'));
3535
File::makeDirectory((base_path('modules')));
36-
File::put(base_path('modules/.gitkeep'), '');
36+
File::put(base_path('modules'.DIRECTORY_SEPARATOR.'.gitkeep'), '');
3737
}
3838

3939
$this->info("> Success!");

src/Commands/ModuleListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function handle(): int
2222
foreach ($modules as $module) {
2323
// TODO: get whats loaded in the module (routes, config, etc)
2424
$name = Str::studly(str_replace('modules/', '', $module));
25-
$folder = "modules/{$name}";
25+
$folder = 'modules'.DIRECTORY_SEPARATOR.$name;
2626
$rows[] = [$name, $folder];
2727
}
2828

src/Commands/ModuleMakeCommand.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function __construct(Composer $composer)
2525

2626
public function handle(): int
2727
{
28+
$ds = DIRECTORY_SEPARATOR;
2829
$name = Str::studly($this->argument('name'));
2930
$nameSlug = Str::slug($this->argument('name'));
3031

@@ -42,25 +43,25 @@ public function handle(): int
4243
$this->line("> Creating composer.json file..");
4344

4445
File::ensureDirectoryExists(module_path($name));
45-
File::makeDirectory(module_path("{$name}/src"));
46-
File::makeDirectory(module_path("{$name}/src/Providers"));
46+
File::makeDirectory(module_path($name.$ds.'src'));
47+
File::makeDirectory(module_path($name.$ds.'src'.$ds.'Providers'));
4748

48-
$composerContent = File::get(__DIR__.'/../../stubs/composer.json.stub');
49+
$composerContent = File::get(__DIR__.$ds.'..'.$ds.'..'.$ds.'stubs'.$ds.'composer.json.stub');
4950
$composerContent = preg_replace('/_MODULENAME_/', $name, $composerContent);
5051
$composerContent = preg_replace('/_MODULENAMESLUG_/', $nameSlug, $composerContent);
5152

5253
File::put(module_path("{$name}/composer.json"), $composerContent);
5354

5455
$this->line("> Creating {$name}ServiceProvider file..");
5556

56-
$providerContent = File::get(__DIR__.'/../../stubs/ModuleNameServiceProvider.php.stub');
57+
$providerContent = File::get(__DIR__.$ds.'..'.$ds.'..'.$ds.'stubs/ModuleNameServiceProvider.php.stub');
5758
$providerContent = preg_replace('/_MODULENAME_/', $name, $providerContent);
5859

59-
File::put(module_path("{$name}/src/Providers/{$name}ServiceProvider.php"), $providerContent);
60+
File::put(module_path($name.$ds.'src'.$ds.'Providers'.$ds.$name.'ServiceProvider.php'), $providerContent);
6061

6162
$this->line("> Running composer install modules/{$nameSlug}..");
6263

63-
$installProcess = new Process(['composer', 'require', "modules/{$nameSlug}"], null);
64+
$installProcess = new Process(['composer', 'require', 'modules'.$ds.$nameSlug], null);
6465
$installProcess->setWorkingDirectory(base_path());
6566
$installProcess->mustRun(function ($type, $buffer) {
6667
$this->getOutput()->write($buffer);

src/Module.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ public function name(string $name): self
5050
public function hasViews(): self
5151
{
5252
$this->hasViews = true;
53-
$this->viewPath = $this->basePath('resources/views');
53+
$this->viewPath = $this->basePath('resources'.DIRECTORY_SEPARATOR.'views');
5454

5555
return $this;
5656
}
5757

5858
public function hasMigrations(): self
5959
{
6060
$this->hasMigrations = true;
61-
$this->migrationPath = $this->basePath('database/migrations');
61+
$this->migrationPath = $this->basePath('database'.DIRECTORY_SEPARATOR.'migrations');
6262

6363
return $this;
6464
}
@@ -96,7 +96,7 @@ public function hasConfigs(array $configNames = []): self
9696

9797
foreach ($configNames as $configName) {
9898
//.
99-
$path = $this->basePath("config/{$configName}.php");
99+
$path = $this->basePath('config'.DIRECTORY_SEPARATOR.$configName.'.php');
100100
if (! file_exists($path)) {
101101
throw new \Exception("Config file {$configName} does not exists!");
102102
}
@@ -138,7 +138,7 @@ public function hasRoutes(array $routeNames = []): self
138138

139139
foreach ($routeNames as $routeName) {
140140
//.
141-
$path = $this->basePath("routes/{$routeName}.php");
141+
$path = $this->basePath('routes'.DIRECTORY_SEPARATOR.$routeName.'.php');
142142
if (! file_exists($path)) {
143143
throw new \Exception("Route file {$routeName} does not exists!");
144144
}
@@ -223,8 +223,11 @@ public function hasServiceProviders(array $serviceProviders): self
223223

224224
public function basePath(string $directory = null): string
225225
{
226+
$ds = DIRECTORY_SEPARATOR;
227+
226228
return $directory === null
227-
? $this->basePath : "{$this->basePath}/" . ltrim($directory, '/');
229+
? $this->basePath
230+
: $this->basePath.$ds . ltrim($directory, $ds);
228231
}
229232

230233
public function setBasePath(string $path): self

src/Providers/ModuleServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ public function getModule(): Module
109109

110110
protected function getModuleBaseDir(): string
111111
{
112+
$ds = DIRECTORY_SEPARATOR;
112113
$reflector = new ReflectionClass(get_class($this));
114+
$dirName = dirname($reflector->getFileName());
113115

114-
return str_replace('/src/Providers', '', dirname($reflector->getFileName()));
116+
return str_replace($ds.'src'.$ds.'Providers', '', $dirName);
115117
}
116118

117119
/**

src/Providers/PackageServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class PackageServiceProvider extends ServiceProvider
88
{
99
public function register(): void
1010
{
11-
require_once __DIR__.'/../../src/helpers.php';
11+
$ds = DIRECTORY_SEPARATOR;
12+
require_once __DIR__.$ds.'..'.$ds.'..'.$ds.'src'.$ds.'helpers.php';
1213
}
1314

1415
public function boot(): void

stubs/composer.json.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"name": "modules/_MODULENAMESLUG_",
33
"autoload": {
44
"psr-4": {
5-
"_MODULENAME_\\": "src/",
5+
"_MODULENAME_\\": "src",
66
"_MODULENAME_\\Database\\Factories\\": "database/factories",
77
"_MODULENAME_\\Database\\Seeeders\\": "database/seeders"
88
}
99
},
1010
"autoload-dev": {
1111
"psr-4": {
12-
"_MODULENAME_\\Tests\\": "tests/"
12+
"_MODULENAME_\\Tests\\": "tests"
1313
}
1414
},
1515
"extra": {

0 commit comments

Comments
 (0)