Skip to content

Commit 2498e76

Browse files
authored
Merge pull request #912 from hydephp/vendor-publish-command
Create vendor:publish command
2 parents d557740 + daa60ab commit 2498e76

File tree

6 files changed

+126
-2
lines changed

6 files changed

+126
-2
lines changed

packages/framework/src/Console/Commands/PublishHomepageCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/**
1616
* Publish one of the default homepages.
1717
*
18+
* @deprecated May be replaced by vendor:publish in the future.
1819
* @see \Hyde\Framework\Testing\Feature\Commands\PublishHomepageCommandTest
1920
*/
2021
class PublishHomepageCommand extends Command

packages/framework/src/Console/Commands/PublishViewsCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
/**
1212
* Publish the Hyde Blade views.
13+
*
14+
* @deprecated May be replaced by vendor:publish in the future.
1315
*/
1416
class PublishViewsCommand extends Command
1517
{

packages/framework/src/Console/Commands/UpdateConfigsCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
namespace Hyde\Console\Commands;
66

77
use Hyde\Hyde;
8-
use Illuminate\Support\Facades\File;
8+
use Illuminate\Support\Facades\Artisan;
99
use LaravelZero\Framework\Commands\Command;
1010

1111
/**
1212
* Publish the Hyde Config Files.
1313
*
14+
* @deprecated May be replaced by vendor:publish in the future.
1415
* @see \Hyde\Framework\Testing\Feature\Commands\UpdateConfigsCommandTest
1516
*/
1617
class UpdateConfigsCommand extends Command
@@ -23,7 +24,10 @@ class UpdateConfigsCommand extends Command
2324

2425
public function handle(): int
2526
{
26-
File::copyDirectory(Hyde::vendorPath('config'), Hyde::path('config'));
27+
Artisan::call('vendor:publish', [
28+
'--tag' => 'configs',
29+
'--force' => true,
30+
]);
2731

2832
$this->line('<info>Published config files to</info> <comment>'.Hyde::path('config').'</comment>');
2933

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hyde\Console\Commands;
6+
7+
use Illuminate\Foundation\Console\VendorPublishCommand as BaseCommand;
8+
use Illuminate\Support\ServiceProvider;
9+
use NunoMaduro\LaravelConsoleSummary\LaravelConsoleSummaryServiceProvider;
10+
11+
/**
12+
* Publish any publishable assets from vendor packages.
13+
*
14+
* @see \Hyde\Framework\Testing\Feature\Commands\VendorPublishCommandTest
15+
*/
16+
class VendorPublishCommand extends BaseCommand
17+
{
18+
/**
19+
* Our child method filters the options available to the parent method.
20+
*/
21+
public function handle(): void
22+
{
23+
$originalPublishers = ServiceProvider::$publishes;
24+
$originalGroups = ServiceProvider::$publishGroups;
25+
26+
// This provider's publisher is not needed as it's covered by Laravel Zero
27+
unset(ServiceProvider::$publishes[LaravelConsoleSummaryServiceProvider::class]);
28+
29+
// Rename the config group to be more helpful
30+
if (isset(ServiceProvider::$publishGroups['config'])) {
31+
ServiceProvider::$publishGroups['vendor-configs'] = ServiceProvider::$publishGroups['config'];
32+
unset(ServiceProvider::$publishGroups['config']);
33+
}
34+
35+
parent::handle();
36+
37+
ServiceProvider::$publishes = $originalPublishers;
38+
ServiceProvider::$publishGroups = $originalGroups;
39+
}
40+
}

packages/framework/src/Console/HydeConsoleServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function register(): void
2626
Commands\MakePageCommand::class,
2727
Commands\MakePostCommand::class,
2828

29+
Commands\VendorPublishCommand::class,
2930
Commands\PublishHomepageCommand::class,
3031
Commands\PublishViewsCommand::class,
3132
Commands\UpdateConfigsCommand::class,
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hyde\Framework\Testing\Feature\Commands;
6+
7+
use Hyde\Testing\TestCase;
8+
use Illuminate\Support\ServiceProvider;
9+
use NunoMaduro\LaravelConsoleSummary\LaravelConsoleSummaryServiceProvider;
10+
11+
/**
12+
* @covers \Hyde\Console\Commands\VendorPublishCommand
13+
*/
14+
class VendorPublishCommandTest extends TestCase
15+
{
16+
protected function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
$this->originalPublishers = ServiceProvider::$publishes;
21+
$this->originalGroups = ServiceProvider::$publishGroups;
22+
}
23+
24+
protected function tearDown(): void
25+
{
26+
ServiceProvider::$publishes = $this->originalPublishers;
27+
ServiceProvider::$publishGroups = $this->originalGroups;
28+
29+
parent::tearDown();
30+
}
31+
32+
public function test_command_prompts_for_provider_or_tag()
33+
{
34+
ServiceProvider::$publishes = [
35+
'ExampleProvider' => '',
36+
];
37+
ServiceProvider::$publishGroups = [
38+
'example-configs' => [],
39+
];
40+
41+
$this->artisan('vendor:publish')
42+
->expectsChoice('Which provider or tag\'s files would you like to publish?', 'Tag: example-configs', [
43+
'<comment>Publish files from all providers and tags listed below</comment>',
44+
'<fg=gray>Provider:</> ExampleProvider',
45+
'<fg=gray>Tag:</> example-configs',
46+
])
47+
->assertExitCode(0);
48+
}
49+
50+
public function test_unhelpful_publishers_are_removed()
51+
{
52+
ServiceProvider::$publishes = [
53+
LaravelConsoleSummaryServiceProvider::class => '',
54+
];
55+
ServiceProvider::$publishGroups = [];
56+
57+
$this->artisan('vendor:publish')
58+
->expectsChoice('Which provider or tag\'s files would you like to publish?', 'Tag: example-configs', [
59+
'<comment>Publish files from all providers and tags listed below</comment>',
60+
])->assertExitCode(0);
61+
}
62+
63+
public function test_config_group_is_renamed_to_be_more_helpful()
64+
{
65+
ServiceProvider::$publishes = [];
66+
ServiceProvider::$publishGroups = [
67+
'config' => [],
68+
];
69+
70+
$this->artisan('vendor:publish')
71+
->expectsChoice('Which provider or tag\'s files would you like to publish?', 'Tag: vendor-configs', [
72+
'<comment>Publish files from all providers and tags listed below</comment>',
73+
'<fg=gray>Tag:</> vendor-configs',
74+
])->assertExitCode(0);
75+
}
76+
}

0 commit comments

Comments
 (0)