diff --git a/src/Concerns/CanManipulateFiles.php b/src/Concerns/CanManipulateFiles.php index 5dfda8f0..727f525c 100644 --- a/src/Concerns/CanManipulateFiles.php +++ b/src/Concerns/CanManipulateFiles.php @@ -3,8 +3,11 @@ namespace Coolsam\Modules\Concerns; use Coolsam\Modules\Facades\FilamentModules; +use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Filesystem\Filesystem; use Nwidart\Modules\Module; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use function Laravel\Prompts\confirm; @@ -34,12 +37,17 @@ protected function checkForCollision(array $paths): bool /** * @param array $replacements + * + * @throws FileNotFoundException + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ protected function copyStubToApp(string $stub, string $targetPath, array $replacements = []): void { + $D = DIRECTORY_SEPARATOR; $filesystem = app(Filesystem::class); - $stubPath = $this->getDefaultStubPath() . "/{$stub}.stub"; + $stubPath = $this->getDefaultStubPath() . "{$D}{$stub}.stub"; $stub = str($filesystem->get($stubPath)); @@ -72,7 +80,7 @@ protected function writeFile(string $path, string $contents): void protected function getDefaultStubPath(): string { - return $this->getModule()->appPath('Commands/stubs'); + return $this->getModule()->appPath('Commands' . DIRECTORY_SEPARATOR . 'stubs'); } protected function getModule(): Module diff --git a/src/Concerns/GeneratesModularFiles.php b/src/Concerns/GeneratesModularFiles.php index 17b1b39e..a07fd849 100644 --- a/src/Concerns/GeneratesModularFiles.php +++ b/src/Concerns/GeneratesModularFiles.php @@ -19,7 +19,7 @@ protected function getArguments(): array protected function resolveStubPath($stub): string { - return FilamentModules::packagePath('Commands/' . trim($stub, DIRECTORY_SEPARATOR)); + return FilamentModules::packagePath('Commands' . DIRECTORY_SEPARATOR . trim($stub, DIRECTORY_SEPARATOR)); } public function getModule(): Module @@ -43,7 +43,7 @@ protected function getPath($name): string { $name = Str::replaceFirst($this->rootNamespace(), 'app', $name); - return $this->getModule()->getExtraPath(str_replace('\\', '/', $name) . '.php'); + return $this->getModule()->getExtraPath(str_replace('\\', DIRECTORY_SEPARATOR, $name) . '.php'); } protected function possibleModels() diff --git a/tests/Unit/GeneratesModularFilesConcernTest.php b/tests/Unit/GeneratesModularFilesConcernTest.php index 470576ca..6bbfcf44 100644 --- a/tests/Unit/GeneratesModularFilesConcernTest.php +++ b/tests/Unit/GeneratesModularFilesConcernTest.php @@ -13,6 +13,8 @@ public function getRelativeNamespace(): string public function getStub() { + $d = DIRECTORY_SEPARATOR; + return $this->resolveStubPath('stubs/filament-plugin.stub'); } }; @@ -20,6 +22,7 @@ public function getStub() test('can generate the correct stubs path', function () { // include the GeneratesModularFiles trait + $d = DIRECTORY_SEPARATOR; expect($this->trait->getStub()) - ->toEqual(realpath(__DIR__ . '/../../src/Commands/stubs/filament-plugin.stub')); + ->toEqual(realpath(__DIR__ . "{$d}..{$d}..{$d}src{$d}Commands{$d}stubs{$d}filament-plugin.stub")); });