55namespace Hyde \Console \Commands ;
66
77use Hyde \Console \Concerns \AsksToRebuildSite ;
8- use Hyde \Framework \Features \Templates \Homepages ;
9- use Hyde \Framework \Features \Templates \PublishableContract ;
8+ use Hyde \Console \Concerns \Command ;
109use Hyde \Framework \Services \ChecksumService ;
1110use Hyde \Hyde ;
1211use Illuminate \Support \Collection ;
13- use LaravelZero \Framework \Commands \Command ;
12+ use Illuminate \Support \Facades \Artisan ;
13+ use function array_key_exists ;
14+ use function file_exists ;
15+ use function str_replace ;
16+ use function strstr ;
1417
1518/**
1619 * Publish one of the default homepages.
1720 *
21+ * @todo Refactor to use vendor:publish and to use code similar to {@see \Hyde\Console\Commands\PublishViewsCommand}
22+ *
1823 * @deprecated May be replaced by vendor:publish in the future.
1924 * @see \Hyde\Framework\Testing\Feature\Commands\PublishHomepageCommandTest
2025 */
@@ -29,29 +34,48 @@ class PublishHomepageCommand extends Command
2934 /** @var string */
3035 protected $ description = 'Publish one of the default homepages to index.blade.php. ' ;
3136
37+ protected array $ options = [
38+ 'welcome ' => [
39+ 'name ' => 'Welcome ' ,
40+ 'description ' => 'The default welcome page. ' ,
41+ 'group ' => 'hyde-welcome-page ' ,
42+ ],
43+ 'posts ' => [
44+ 'name ' => 'Posts Feed ' ,
45+ 'description ' => 'A feed of your latest posts. Perfect for a blog site! ' ,
46+ 'group ' => 'hyde-posts-page ' ,
47+ ],
48+ 'blank ' => [
49+ 'name ' => 'Blank Starter ' ,
50+ 'description ' => 'A blank Blade template with just the base layout. ' ,
51+ 'group ' => 'hyde-blank-page ' ,
52+ ],
53+ ];
54+
3255 public function handle (): int
3356 {
3457 $ selected = $ this ->parseSelection ();
3558
36- if (! Homepages::exists ($ selected )) {
37- $ this ->error ("Homepage $ selected does not exist. " );
38-
39- return 404 ;
40- }
41-
4259 if (! $ this ->canExistingFileBeOverwritten ()) {
4360 $ this ->error ('A modified index.blade.php file already exists. Use --force to overwrite. ' );
4461
4562 return 409 ;
4663 }
4764
48- Homepages::get ($ selected )->publish (true );
65+ $ tagExists = array_key_exists ($ selected , $ this ->options );
66+
67+ Artisan::call ('vendor:publish ' , [
68+ '--tag ' => $ this ->options [$ selected ]['group ' ] ?? $ selected ,
69+ '--force ' => true , // Todo add force state dynamically depending on existing file state
70+ ], ! $ tagExists ? $ this ->output : null );
4971
50- $ this ->line ("<info>Published page</info> [<comment> $ selected</comment>] " );
72+ if ($ tagExists ) {
73+ $ this ->infoComment ("Published page [ $ selected] " );
5174
52- $ this ->askToRebuildSite ();
75+ $ this ->askToRebuildSite ();
76+ }
5377
54- return Command::SUCCESS ;
78+ return $ tagExists ? Command::SUCCESS : 404 ;
5579 }
5680
5781 protected function parseSelection (): string
@@ -77,7 +101,7 @@ protected function formatPublishableChoices(): array
77101
78102 protected function getTemplateOptions (): Collection
79103 {
80- return Homepages:: options ()-> map ( fn ( PublishableContract $ page ): array => $ page :: toArray () );
104+ return new Collection ( $ this -> options );
81105 }
82106
83107 protected function parseChoiceIntoKey (string $ choice ): string
0 commit comments