Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'),
Expand Down
10 changes: 10 additions & 0 deletions src/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions src/Installers/FileInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/ValueObjects/PublishableFolder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Esign\InstallCommand\ValueObjects;

class PublishableFolder
{
public function __construct(
public string $path,
public string $target,
) {}
}
9 changes: 9 additions & 0 deletions tests/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public function it_can_publish_files(): void
$this->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
{
Expand Down
5 changes: 5 additions & 0 deletions tests/Support/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions tests/Support/stubs/resources/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello from stub');
5 changes: 5 additions & 0 deletions tests/Support/stubs/resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>Stub layout</h1>
</body>
</html>
Loading