Skip to content

Commit

Permalink
Merge pull request #86 from modnlimited/main
Browse files Browse the repository at this point in the history
Enable publishing assets from the install command.
  • Loading branch information
freekmurze authored Mar 14, 2023
2 parents b50f736 + 97c36db commit bab6202
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class YourPackageServiceProvider extends PackageServiceProvider
->hasInstallCommand(function(InstallCommand $command) {
$command
->publishConfigFile()
->publishAssets()
->publishMigrations()
->copyAndRegisterServiceProviderInApp()
->askToStarRepoOnGitHub();
Expand Down Expand Up @@ -407,6 +408,7 @@ class YourPackageServiceProvider extends PackageServiceProvider
->hasInstallCommand(function(InstallCommand $command) {
$command
->publishConfigFile()
->publishAssets()
->publishMigrations()
->askToRunMigrations()
->copyAndRegisterServiceProviderInApp()
Expand All @@ -425,6 +427,7 @@ php artisan your-package-name:install
Using the code above, that command will:

- publish the config file
- publish the assets
- publish the migrations
- copy the `/resources/stubs/MyProviderName.php.stub` from your package to `app/Providers/MyServiceProviderName.php`, and also register that
provider in `config/app.php`
Expand All @@ -448,6 +451,7 @@ public function configurePackage(Package $package): void
$command->info('Hello, and welcome to my great new package!')
})
->publishConfigFile()
->publishAssets()
->publishMigrations()
->askToRunMigrations()
->copyAndRegisterServiceProviderInApp()
Expand Down
17 changes: 17 additions & 0 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class InstallCommand extends Command

protected bool $shouldPublishConfigFile = false;

protected bool $shouldPublishAssets = false;

protected bool $shouldPublishMigrations = false;

protected bool $askToRunMigrations = false;
Expand Down Expand Up @@ -51,6 +53,14 @@ public function handle()
'--tag' => "{$this->package->shortName()}-config",
]);
}

if ($this->shouldPublishAssets) {
$this->comment('Publishing assets...');

$this->callSilently("vendor:publish", [
'--tag' => "{$this->package->shortName()}-assets",
]);
}

if ($this->shouldPublishMigrations) {
$this->comment('Publishing migration...');
Expand Down Expand Up @@ -103,6 +113,13 @@ public function publishConfigFile(): self

return $this;
}

public function publishAssets(): self
{
$this->shouldPublishAssets = true;

return $this;
}

public function publishMigrations(): self
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use function PHPUnit\Framework\assertDirectoryExists;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use function Spatie\PestPluginTestTime\testTime;

trait ConfigureAssetsTest
{
public function configurePackage(Package $package)
{
testTime()->freeze('2020-01-01 00:00:00');

$package
->name('laravel-package-tools')
->hasAssets()
->hasInstallCommand(function (InstallCommand $command) {
$command->publishAssets();
});
}
}

uses(ConfigureAssetsTest::class);

it('can install the assets', function () {
$assetPath = public_path('/vendor/package-tools');

$this
->artisan('package-tools:install')
->assertSuccessful();

assertDirectoryExists($assetPath);
});

0 comments on commit bab6202

Please sign in to comment.