diff --git a/src/Console/Commands/Foundation/VendorPublishCommand.php b/src/Console/Commands/Foundation/VendorPublishCommand.php new file mode 100644 index 0000000..4e8c35c --- /dev/null +++ b/src/Console/Commands/Foundation/VendorPublishCommand.php @@ -0,0 +1,52 @@ +pathsToPublish($tag); + + if ($publishing = count($pathsToPublish) > 0) { + $this->components->info(sprintf( + 'Publishing %sassets', + $tag ? "[$tag] " : '', + )); + } + + $module = $this->module(); + + foreach ($pathsToPublish as $from => &$to) { + if ($module) { + $this->updateTargetPath($module, $to); + } + + $this->publishItem($from, $to); + } + + if ($publishing === false) { + $this->components->info('No publishable resources for tag ['.$tag.'].'); + } else { + $this->laravel['events']->dispatch(new VendorTagPublished($tag, $pathsToPublish)); + + $this->newLine(); + } + } + + protected function updateTargetPath(ModuleConfig $module, string &$path) + { + $base_path = $this->laravel->basePath(); + $module_path = $module->path(); + + $path = str_replace($base_path, $module_path, $path); + } +} diff --git a/src/Support/ModularizedCommandsServiceProvider.php b/src/Support/ModularizedCommandsServiceProvider.php index defd063..c9e55ae 100644 --- a/src/Support/ModularizedCommandsServiceProvider.php +++ b/src/Support/ModularizedCommandsServiceProvider.php @@ -5,8 +5,10 @@ use Illuminate\Console\Application; use Illuminate\Console\Application as Artisan; use Illuminate\Database\Console\Migrations\MigrateMakeCommand as OriginalMakeMigrationCommand; +use Illuminate\Foundation\Console\VendorPublishCommand as OriginalVendorPublishCommand; use Illuminate\Support\ServiceProvider; use InterNACHI\Modular\Console\Commands\Database\SeedCommand; +use InterNACHI\Modular\Console\Commands\Foundation\VendorPublishCommand; use InterNACHI\Modular\Console\Commands\Make\MakeCast; use InterNACHI\Modular\Console\Commands\Make\MakeChannel; use InterNACHI\Modular\Console\Commands\Make\MakeCommand; @@ -60,7 +62,7 @@ class ModularizedCommandsServiceProvider extends ServiceProvider 'command.component.make' => MakeComponent::class, 'command.seed' => SeedCommand::class, ]; - + public function register(): void { // Register our overrides via the "booted" event to ensure that we override @@ -71,10 +73,11 @@ public function register(): void $this->registerMakeCommandOverrides(); $this->registerMigrationCommandOverrides(); $this->registerLivewireOverrides($artisan); + $this->registerVendorPuslishCommandOverride(); }); }); } - + protected function registerMakeCommandOverrides() { foreach ($this->overrides as $alias => $class_name) { @@ -82,30 +85,30 @@ protected function registerMakeCommandOverrides() $this->app->singleton(get_parent_class($class_name), $class_name); } } - + protected function registerMigrationCommandOverrides() { // Laravel 8 $this->app->singleton('command.migrate.make', function($app) { return new MakeMigration($app['migration.creator'], $app['composer']); }); - + // Laravel 9 $this->app->singleton(OriginalMakeMigrationCommand::class, function($app) { return new MakeMigration($app['migration.creator'], $app['composer']); }); } - + protected function registerLivewireOverrides(Artisan $artisan) { // Don't register commands if Livewire isn't installed if (! class_exists(Livewire\MakeCommand::class)) { return; } - + // Replace the resolved command with our subclass $artisan->resolveCommands([MakeLivewire::class]); - + // Ensure that if 'make:livewire' or 'livewire:make' is resolved from the container // in the future, our subclass is used instead $this->app->extend(Livewire\MakeCommand::class, function() { @@ -115,4 +118,11 @@ protected function registerLivewireOverrides(Artisan $artisan) return new MakeLivewire(); }); } + + protected function registerVendorPuslishCommandOverride() + { + $this->app->singleton(OriginalVendorPublishCommand::class, function($app) { + return new VendorPublishCommand($app['files']); + }); + } } diff --git a/tests/Commands/Foundation/VendorPublishCommandTest.php b/tests/Commands/Foundation/VendorPublishCommandTest.php new file mode 100644 index 0000000..630407e --- /dev/null +++ b/tests/Commands/Foundation/VendorPublishCommandTest.php @@ -0,0 +1,36 @@ +requiresLaravelVersion('9.2.0'); + + $this->artisan('vendor:publish', ['--help' => true]) + ->expectsOutputToContain('--module') + ->assertExitCode(0); + } + + public function test_it_published_to_correct_module() + { + $this->requiresLaravelVersion('9.2.0'); + + $command = VendorPublishCommand::class; + $arguments = ['--tag' => 'laravel-mail']; + $expected_path = 'resources/views/vendor/mail/html/layout.blade.php'; + + $this->assertModuleCommandResults($command, $arguments, $expected_path, []); + } +}