From 90e3068a482c45a4c8fb88a9dc51bd53aa345421 Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Fri, 11 Aug 2023 11:35:38 +0200 Subject: [PATCH 1/5] Add simple license check before running generate command --- src/Commands/StaticSiteGenerate.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Commands/StaticSiteGenerate.php b/src/Commands/StaticSiteGenerate.php index 054be48..205316a 100644 --- a/src/Commands/StaticSiteGenerate.php +++ b/src/Commands/StaticSiteGenerate.php @@ -55,6 +55,17 @@ public function handle() { Partyline::bind($this); + if (config('statamic.editions.pro') && ! config('statamic.system.license_key')) { + $this->error('Statamic Pro is enabled but no site key was found.'); + $this->warn('Please set a valid site key in your .env file.'); + + if (! $this->confirm('Do you wish to continue with the ssg:generate command?', true)) { + $this->line('Static site generation canceled.'); + + return 0; + }; + } + if (! $workers = $this->option('workers')) { $this->comment('You may be able to speed up site generation significantly by installing spatie/fork and using multiple workers (requires PHP 8+).'); } From 6812f65b24603cd46bdf7aa36d9a43ac808f8ca9 Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Fri, 11 Aug 2023 11:44:21 +0200 Subject: [PATCH 2/5] whoops --- src/Commands/StaticSiteGenerate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/StaticSiteGenerate.php b/src/Commands/StaticSiteGenerate.php index 205316a..9c6cbce 100644 --- a/src/Commands/StaticSiteGenerate.php +++ b/src/Commands/StaticSiteGenerate.php @@ -63,7 +63,7 @@ public function handle() $this->line('Static site generation canceled.'); return 0; - }; + } } if (! $workers = $this->option('workers')) { From 50723ab5e4ff482abaf391728ae7ef99aa7cfe8e Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 11 Aug 2023 11:23:55 -0400 Subject: [PATCH 3/5] default to no, if interactive. --- src/Commands/StaticSiteGenerate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/StaticSiteGenerate.php b/src/Commands/StaticSiteGenerate.php index 9c6cbce..fe74502 100644 --- a/src/Commands/StaticSiteGenerate.php +++ b/src/Commands/StaticSiteGenerate.php @@ -59,7 +59,7 @@ public function handle() $this->error('Statamic Pro is enabled but no site key was found.'); $this->warn('Please set a valid site key in your .env file.'); - if (! $this->confirm('Do you wish to continue with the ssg:generate command?', true)) { + if (! $this->confirm('Do you wish to continue with the ssg:generate command?', $this->option('no-interaction'))) { $this->line('Static site generation canceled.'); return 0; From 1c71d8926ba736f476c67786b1143a6e5f309539 Mon Sep 17 00:00:00 2001 From: Jack McDade Date: Fri, 11 Aug 2023 11:30:10 -0400 Subject: [PATCH 4/5] Update license check wording --- src/Commands/StaticSiteGenerate.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Commands/StaticSiteGenerate.php b/src/Commands/StaticSiteGenerate.php index fe74502..9a15bc4 100644 --- a/src/Commands/StaticSiteGenerate.php +++ b/src/Commands/StaticSiteGenerate.php @@ -56,10 +56,10 @@ public function handle() Partyline::bind($this); if (config('statamic.editions.pro') && ! config('statamic.system.license_key')) { - $this->error('Statamic Pro is enabled but no site key was found.'); - $this->warn('Please set a valid site key in your .env file.'); + $this->error('Statamic Pro is enabled but no site license was found.'); + $this->warn('Please set a valid Statamic License Key in your .env file.'); - if (! $this->confirm('Do you wish to continue with the ssg:generate command?', $this->option('no-interaction'))) { + if (! $this->confirm('By continuing you agree that this build is for testing purposes only. Do you wish to continue?', $this->option('no-interaction'))) { $this->line('Static site generation canceled.'); return 0; From 872a702d75541609d92e70a8ee670f8e1b1414c2 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 11 Aug 2023 12:03:51 -0400 Subject: [PATCH 5/5] fix tests by avoiding asking the question entirely if using no-interaction --- src/Commands/StaticSiteGenerate.php | 3 ++- tests/Concerns/RunsGeneratorCommand.php | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Commands/StaticSiteGenerate.php b/src/Commands/StaticSiteGenerate.php index 9a15bc4..0660f00 100644 --- a/src/Commands/StaticSiteGenerate.php +++ b/src/Commands/StaticSiteGenerate.php @@ -58,8 +58,9 @@ public function handle() if (config('statamic.editions.pro') && ! config('statamic.system.license_key')) { $this->error('Statamic Pro is enabled but no site license was found.'); $this->warn('Please set a valid Statamic License Key in your .env file.'); + $confirmationText = 'By continuing you agree that this build is for testing purposes only. Do you wish to continue?'; - if (! $this->confirm('By continuing you agree that this build is for testing purposes only. Do you wish to continue?', $this->option('no-interaction'))) { + if (! $this->option('no-interaction') && ! $this->confirm($confirmationText)) { $this->line('Static site generation canceled.'); return 0; diff --git a/tests/Concerns/RunsGeneratorCommand.php b/tests/Concerns/RunsGeneratorCommand.php index eb7da72..1b12e7c 100644 --- a/tests/Concerns/RunsGeneratorCommand.php +++ b/tests/Concerns/RunsGeneratorCommand.php @@ -26,6 +26,8 @@ protected function generate($options = []) { $this->assertFalse($this->files->exists($this->destination)); + $options['--no-interaction'] ??= true; + $this ->artisan('statamic:ssg:generate', $options) ->doesntExpectOutputToContain('pages not generated');