Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to clear peak content from install script #362

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions StarterKitPostInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function handle($console): void
$this->installPuppeteerAndBrowsershot();
$this->installTranslations();
$this->setTimezone();
$this->runPeakClearSite();
$this->writeFiles();
$this->cleanUp();
$this->starPeakRepo();
Expand Down Expand Up @@ -165,6 +166,19 @@ protected function setTimezone(): void
$this->replaceInApp("'timezone' => '{$currentTimezone}'", "'timezone' => '{$newTimezone}'");
}

protected function runPeakClearSite(): void
{
if (!$this->interactive || !Process::isTtySupported()) {
return;
}

$this->run(
command: 'php artisan statamic:peak:clear-site',
tty: true,
spinner: false,
);
}

protected function writeFiles(): void
{
app('files')->put(base_path('.env'), $this->env);
Expand Down Expand Up @@ -211,7 +225,6 @@ protected function starPeakRepo(): void
protected function finish(): void
{
info('[✓] Peak is installed. Enjoy the view!');
warning('Run `php please peak:clear-site` to get rid of default content.');
warning('Run `php please peak:install-preset` to install premade sets onto your website.');
warning('Run `php please peak:install-block` to install premade blocks onto your page builder.');
}
Expand Down Expand Up @@ -328,17 +341,26 @@ protected function createGithubRepo(): void
);
}

protected function run(string $command, string $processingMessage = '', string $successMessage = '', ?string $errorMessage = null): bool
protected function run(string $command, string $processingMessage = '', string $successMessage = '', ?string $errorMessage = null, bool $tty = false, bool $spinner = true, int $timeout = 120): bool
{
$process = new Process(explode(' ', $command));
$process->setTimeout(120);
$process->setTimeout($timeout);

if ($tty) {
$process->setTty(true);
}

try {
$this->withSpinner(
fn() => $process->mustRun(),
$processingMessage,
$successMessage
);
$spinner ?
$this->withSpinner(
fn() => $process->mustRun(),
$processingMessage,
$successMessage
) :
$this->withoutSpinner(
fn() => $process->mustRun(),
$successMessage
);

return true;
} catch (ProcessFailedException $exception) {
Expand Down Expand Up @@ -452,6 +474,15 @@ protected function appendToGitignore(string $toIgnore): void
app('files')->append(base_path('.gitignore'), "\n{$toIgnore}");
}

protected function withoutSpinner(callable $callback, string $successMessage = ''): void
{
$callback();

if ($successMessage) {
info("[✓] $successMessage");
}
}

protected function selectLanguageToInstall(Collection $installedLanguages): string
{
return suggest(
Expand Down