diff --git a/README.md b/README.md index a32abca..9786c7c 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ use Esign\InstallCommand\ValueObjects\AppendableFile; use Esign\InstallCommand\ValueObjects\ComposerPackage; use Esign\InstallCommand\ValueObjects\NodePackage; use Esign\InstallCommand\ValueObjects\PublishableFile; +use Esign\InstallCommand\ValueObjects\PublishableFolder; class MyInstallCommand extends InstallCommand { @@ -37,6 +38,10 @@ class MyInstallCommand extends InstallCommand path: __DIR__ . '/../../stubs/my-stub.stub', target: base_path('my-stub.php'), ), + new PublishableFolder( + path: __DIR__ . '/../../stubs/resources', + target: base_path('resources'), + ), new AppendableFile( path: __DIR__ . '/../../stubs/my-appendable-stub.stub', target: base_path('my-appendable-stub.php'), diff --git a/src/InstallCommand.php b/src/InstallCommand.php index 726bba8..5dc16a6 100755 --- a/src/InstallCommand.php +++ b/src/InstallCommand.php @@ -10,6 +10,7 @@ use Esign\InstallCommand\ValueObjects\ComposerPackage; use Esign\InstallCommand\ValueObjects\NodePackage; use Esign\InstallCommand\ValueObjects\PublishableFile; +use Esign\InstallCommand\ValueObjects\PublishableFolder; use Illuminate\Console\Command; use Illuminate\Process\Exceptions\ProcessFailedException; @@ -57,6 +58,15 @@ protected function installFiles(): void ); }); + $fileCollection + ->filter(fn ($publishableFile) => $publishableFile instanceof PublishableFolder) + ->each(function (PublishableFolder $publishableFolder) { + $this->fileInstaller->publishFolder( + path: $publishableFolder->path, + target: $publishableFolder->target + ); + }); + $fileCollection ->filter(fn ($publishableFile) => $publishableFile instanceof AppendableFile) ->each(function (AppendableFile $appendableFile) { diff --git a/src/Installers/FileInstaller.php b/src/Installers/FileInstaller.php index dd5d35d..35ae62f 100644 --- a/src/Installers/FileInstaller.php +++ b/src/Installers/FileInstaller.php @@ -22,6 +22,18 @@ public function publishFile(string $path, string $target): void ); } + public function publishFolder(string $path, string $target): void + { + $this->filesystem->ensureDirectoryExists( + path: $target + ); + + $this->filesystem->copyDirectory( + directory: $path, + destination: $target, + ); + } + public function appendToFile(string $path, string $target, ?string $search): void { $noSearchResultSupplied = is_null($search); diff --git a/src/ValueObjects/PublishableFolder.php b/src/ValueObjects/PublishableFolder.php new file mode 100644 index 0000000..cc45179 --- /dev/null +++ b/src/ValueObjects/PublishableFolder.php @@ -0,0 +1,11 @@ +assertFileExists(app_path('Services/UserService.php')); } + #[Test] + public function it_can_publish_folders(): void + { + $this->artisan(InstallCommand::class); + + $this->assertFileExists(base_path('resources/vendor/stubs/js/app.js')); + $this->assertFileExists(base_path('resources/vendor/stubs/views/layouts/app.blade.php')); + } + #[Test] public function it_can_append_after_the_search_value_in_a_file(): void { diff --git a/tests/Support/InstallCommand.php b/tests/Support/InstallCommand.php index fb9a160..9696b0c 100644 --- a/tests/Support/InstallCommand.php +++ b/tests/Support/InstallCommand.php @@ -7,6 +7,7 @@ use Esign\InstallCommand\ValueObjects\ComposerPackage; use Esign\InstallCommand\ValueObjects\NodePackage; use Esign\InstallCommand\ValueObjects\PublishableFile; +use Esign\InstallCommand\ValueObjects\PublishableFolder; class InstallCommand extends BaseInstallCommand { @@ -19,6 +20,10 @@ protected function publishableFiles(): array path: __DIR__ . '/stubs/app/Services/UserService.php', target: base_path('app/Services/UserService.php'), ), + new PublishableFolder( + path: __DIR__ . '/stubs/resources', + target: base_path('resources/vendor/stubs'), + ), new AppendableFile( path: __DIR__ . '/stubs/app/Models/User.php', target: base_path('app/Models/User.php'), diff --git a/tests/Support/stubs/resources/js/app.js b/tests/Support/stubs/resources/js/app.js new file mode 100644 index 0000000..7139973 --- /dev/null +++ b/tests/Support/stubs/resources/js/app.js @@ -0,0 +1 @@ +console.log('hello from stub'); diff --git a/tests/Support/stubs/resources/views/layouts/app.blade.php b/tests/Support/stubs/resources/views/layouts/app.blade.php new file mode 100644 index 0000000..d1a5fe7 --- /dev/null +++ b/tests/Support/stubs/resources/views/layouts/app.blade.php @@ -0,0 +1,5 @@ + + +

Stub layout

+ +