Skip to content

Commit

Permalink
Rework installer prompts and fix wrong directory
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Mar 25, 2022
1 parent 17852f8 commit c15a4ac
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 52 deletions.
86 changes: 45 additions & 41 deletions src/Commands/HydeInstallerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ public function handle(): int
$this->line('The installer will guide you through the process of setting up your new Hyde site!');

$this->installer->name = $this->ask('What is the name of your site?', $this->installer->name);
$this->installer->site_url = $this->installer->setSiteUrl(
$this->ask('What is the name of your site?', $this->installer->site_url)
);
if (isset($this->installer->warnings['site_url_warning'])) {
$this->warn($this->installer->warnings['site_url_warning']['message']);
// Unset the warning so it is not shown again later
unset($this->installer->warnings['site_url_warning']);
}

$this->promptForUrl();

$this->promptForHomepage();

Expand All @@ -63,45 +57,55 @@ public function handle(): int
return 0;
}

private function promptForUrl()
{
if ($this->choice('Do you have a domain name you\'d like to set up?', [
'no',
'yes',
], 'no') === 'yes') {
$this->installer->site_url = $this->installer->setSiteUrl(
$this->ask('What is the url of your site?', $this->installer->site_url)
);
if (isset($this->installer->warnings['site_url_warning'])) {
$this->warn($this->installer->warnings['site_url_warning']['message']);
// Unset the warning so it is not shown again later
unset($this->installer->warnings['site_url_warning']);
}
} else {
$this->comment('Okay, skipping setting up URL.');
}

}

private function promptForHomepage()
{
$this->newLine();
$this->info('Hyde has a couple different homepages to choose from.');

$options = [
'welcome' => 'Default Welcome Page',
'post-feed' => 'Feed of Latest Posts',
'blank' => 'A Blank Layout Page',
];
$default = 'welcome';

if (file_exists(Hyde::path('resources/views/index.blade.php'))) {
$this->line('Note: You already have an index.blade.php file.');
$options = array_merge([
'current' => 'Keep Current Page'
], $options);
$default = 'current';
if (file_exists(Hyde::path('resources/views/pages/index.blade.php'))) {
$this->warn('<error>Warning:</error> You already have a homepage file (resources/views/pages/index.blade.php). If you select \'yes\' it will be overwritten.');
}

$this->installer->homepage = $this->choice(
'Which homepage would you like to use?',
$options,
$default
);

if (($this->installer->homepage !== null)
&& ($this->installer->homepage !== 'current')
&& file_exists(Hyde::path('resources/views/index.blade.php'))
) {
if ($this->choice('Would you like to overwrite existing files?', [
'no',
'yes',
], 'no') === 'yes') {
$this->installer->allowFileOverwrites = true;
$this->warn('Okay, allowing files to be overwritten.');
} else {
$this->info('Okay, files will not be overwritten.');
}
if ($this->choice('Would you like to set the index.blade.php file?', [
'no',
'yes',
], 'no') === 'yes') {
$options = [
'welcome: Default Welcome Page',
'post-feed: Feed of Latest Posts',
'blank: A Blank Layout Page',
];

$this->installer->homepage = strtok($this->choice(
'Which homepage would you like to use?',
$options,
0
), ':');

} else {
$this->comment('Okay, skipping setting up a homepage.');
}

}

private function printInstallerProperties()
Expand Down
12 changes: 1 addition & 11 deletions src/Services/HydeInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class HydeInstaller
public string|null $homepage;

public array $warnings = [];
public bool $allowFileOverwrites = false;

public function __construct()
{
Expand Down Expand Up @@ -138,18 +137,9 @@ private function ensureDotEnvIsSetup()
*/
private function publishHomepage(): void
{
if (file_exists(Hyde::path('resources/views/index.blade.php')) && $this->allowFileOverwrites !== true) {
$this->warnings[] = [
'level' => 'warn',
'message' => 'Refusing to publish homepage as an index.blade.php already exists.',
'context' => 'You can force the file to overwritten using php hyde publish:homepage --force.'
];
return;
}

copy(
Hyde::path("vendor/hyde/framework/resources/views/homepages/$this->homepage.blade.php"),
Hyde::path("resources/views/index.blade.php")
Hyde::path("resources/views/pages/index.blade.php")
);
}
}

0 comments on commit c15a4ac

Please sign in to comment.