From 7e998a2ccf8e66acf1091c61c797f8d7d9bff705 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 11 Nov 2024 18:42:24 +0100 Subject: [PATCH 1/5] Replace `--run-dev` and `--run-prod` build flags with `--run-vite` --- RELEASE_NOTES.md | 1 + docs/getting-started/console-commands.md | 5 ++--- .../framework/src/Console/Commands/BuildSiteCommand.php | 9 ++------- .../framework/tests/Feature/StaticSiteServiceTest.php | 4 +--- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c249bb0dfe4..b9d4991a996 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -92,6 +92,7 @@ This serves two purposes: - **Breaking:** You must now use `npm run build` to compile your assets, instead of `npm run prod` - Bundled assets are now compiled directly into the `_media` folder, and will not be copied to the `_site/media` folder by the NPM command in https://github.com/hydephp/develop/pull/2011 - The realtime compiler now only serves assets from the media source directory (`_media`), and no longer checks the site output directory (`_site/media`) in https://github.com/hydephp/develop/pull/2012 +- **Breaking:** Replaced `--run-dev` and `--run-prod` build command flags with a single `--run-vite` flag that uses Vite to build assets in https://github.com/hydephp/develop/pull/2013 ### Deprecated diff --git a/docs/getting-started/console-commands.md b/docs/getting-started/console-commands.md index c6e4471c4eb..2be9c7de878 100644 --- a/docs/getting-started/console-commands.md +++ b/docs/getting-started/console-commands.md @@ -66,7 +66,7 @@ Here is a quick reference of all the available commands. You can also run `php h ```bash -php hyde build [--run-dev] [--run-prod] [--run-prettier] [--pretty-urls] [--no-api] +php hyde build [--run-vite] [--run-prettier] [--pretty-urls] [--no-api] ``` Build the static site @@ -75,8 +75,7 @@ Build the static site | | | |------------------|--------------------------------------------| -| `--run-dev` | Run the NPM dev script after build | -| `--run-prod` | Run the NPM prod script after build | +| `--run-vite` | Build frontend assets using Vite | | `--run-prettier` | Format the output using NPM Prettier | | `--pretty-urls` | Should links in output use pretty URLs? | | `--no-api` | Disable API calls, for example, Torchlight | diff --git a/packages/framework/src/Console/Commands/BuildSiteCommand.php b/packages/framework/src/Console/Commands/BuildSiteCommand.php index b5aa1950af2..b966f6f36f3 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -26,8 +26,7 @@ class BuildSiteCommand extends Command { /** @var string */ protected $signature = 'build - {--run-dev : Run the NPM dev script after build} - {--run-prod : Run the NPM prod script after build} + {--run-vite : Build frontend assets using Vite} {--run-prettier : Format the output using NPM Prettier} {--pretty-urls : Should links in output use pretty URLs?} {--no-api : Disable API calls, for example, Torchlight}'; @@ -100,11 +99,7 @@ public function runPostBuildActions(): void ); } - if ($this->option('run-dev')) { - $this->runNodeCommand('npm run dev', 'Building frontend assets for development!'); - } - - if ($this->option('run-prod')) { + if ($this->option('run-vite')) { $this->runNodeCommand('npm run build', 'Building frontend assets for production!'); } } diff --git a/packages/framework/tests/Feature/StaticSiteServiceTest.php b/packages/framework/tests/Feature/StaticSiteServiceTest.php index 25931842235..c63a8a66b66 100644 --- a/packages/framework/tests/Feature/StaticSiteServiceTest.php +++ b/packages/framework/tests/Feature/StaticSiteServiceTest.php @@ -160,14 +160,12 @@ public function testNodeActionOutputs() { Process::fake(); - $this->artisan('build --run-prettier --run-dev --run-prod') + $this->artisan('build --run-prettier --run-vite') ->expectsOutput('Prettifying code! This may take a second.') - ->expectsOutput('Building frontend assets for development! This may take a second.') ->expectsOutput('Building frontend assets for production! This may take a second.') ->assertExitCode(0); Process::assertRan(fn ($process) => $process->command === 'npx prettier '.Hyde::pathToRelative(Hyde::sitePath()).'/**/*.html --write --bracket-same-line'); - Process::assertRan(fn ($process) => $process->command === 'npm run dev'); Process::assertRan(fn ($process) => $process->command === 'npm run build'); } From 9625d125d23fcf14bcedd8c93c19e36c1f0d18ce Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 11 Nov 2024 18:58:51 +0100 Subject: [PATCH 2/5] Retransfer assets after Vite build --- .../framework/src/Console/Commands/BuildSiteCommand.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/framework/src/Console/Commands/BuildSiteCommand.php b/packages/framework/src/Console/Commands/BuildSiteCommand.php index b966f6f36f3..f32982aa624 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -6,6 +6,7 @@ use Hyde\Hyde; use Hyde\Facades\Config; +use Illuminate\Support\Arr; use Hyde\Support\BuildWarnings; use Hyde\Console\Concerns\Command; use Hyde\Framework\Services\BuildService; @@ -101,6 +102,13 @@ public function runPostBuildActions(): void if ($this->option('run-vite')) { $this->runNodeCommand('npm run build', 'Building frontend assets for production!'); + + /** @var \Hyde\Framework\Actions\PreBuildTasks\TransferMediaAssets $task */ + $task = Arr::first($this->taskService->getRegisteredTasks(), function (string $task): bool { + return class_basename($task) === 'TransferMediaAssets'; + }); + + (new $task)->run($this->output); // Transfer media assets to the public directory } } From 57e96f0892efc505f7ad6121531eeb42223b7c03 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 11 Nov 2024 18:58:55 +0100 Subject: [PATCH 3/5] Revert "Retransfer assets after Vite build" This reverts commit 9625d125d23fcf14bcedd8c93c19e36c1f0d18ce. --- .../framework/src/Console/Commands/BuildSiteCommand.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/framework/src/Console/Commands/BuildSiteCommand.php b/packages/framework/src/Console/Commands/BuildSiteCommand.php index f32982aa624..b966f6f36f3 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -6,7 +6,6 @@ use Hyde\Hyde; use Hyde\Facades\Config; -use Illuminate\Support\Arr; use Hyde\Support\BuildWarnings; use Hyde\Console\Concerns\Command; use Hyde\Framework\Services\BuildService; @@ -102,13 +101,6 @@ public function runPostBuildActions(): void if ($this->option('run-vite')) { $this->runNodeCommand('npm run build', 'Building frontend assets for production!'); - - /** @var \Hyde\Framework\Actions\PreBuildTasks\TransferMediaAssets $task */ - $task = Arr::first($this->taskService->getRegisteredTasks(), function (string $task): bool { - return class_basename($task) === 'TransferMediaAssets'; - }); - - (new $task)->run($this->output); // Transfer media assets to the public directory } } From 9f3c99fb027769a415703a79a183bfb2c88d625c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 11 Nov 2024 19:03:38 +0100 Subject: [PATCH 4/5] Moved the Vite build step to run before the pre-build tasks --- RELEASE_NOTES.md | 1 + .../framework/src/Console/Commands/BuildSiteCommand.php | 8 ++++---- .../framework/tests/Feature/StaticSiteServiceTest.php | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b9d4991a996..7d14e72431f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -93,6 +93,7 @@ This serves two purposes: - Bundled assets are now compiled directly into the `_media` folder, and will not be copied to the `_site/media` folder by the NPM command in https://github.com/hydephp/develop/pull/2011 - The realtime compiler now only serves assets from the media source directory (`_media`), and no longer checks the site output directory (`_site/media`) in https://github.com/hydephp/develop/pull/2012 - **Breaking:** Replaced `--run-dev` and `--run-prod` build command flags with a single `--run-vite` flag that uses Vite to build assets in https://github.com/hydephp/develop/pull/2013 +- Moved the Vite build step to run before the site build to prevent duplicate media asset transfers in https://github.com/hydephp/develop/pull/2013 ### Deprecated diff --git a/packages/framework/src/Console/Commands/BuildSiteCommand.php b/packages/framework/src/Console/Commands/BuildSiteCommand.php index b966f6f36f3..917cee2772a 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -84,6 +84,10 @@ protected function runPreBuildActions(): void Config::set(['hyde.pretty_urls' => true]); } + if ($this->option('run-vite')) { + $this->runNodeCommand('npm run build', 'Building frontend assets for production!'); + } + $this->taskService->runPreBuildTasks(); } @@ -98,10 +102,6 @@ public function runPostBuildActions(): void 'prettify code' ); } - - if ($this->option('run-vite')) { - $this->runNodeCommand('npm run build', 'Building frontend assets for production!'); - } } protected function printFinishMessage(float $timeStart): void diff --git a/packages/framework/tests/Feature/StaticSiteServiceTest.php b/packages/framework/tests/Feature/StaticSiteServiceTest.php index c63a8a66b66..64376c3aa23 100644 --- a/packages/framework/tests/Feature/StaticSiteServiceTest.php +++ b/packages/framework/tests/Feature/StaticSiteServiceTest.php @@ -161,12 +161,12 @@ public function testNodeActionOutputs() Process::fake(); $this->artisan('build --run-prettier --run-vite') - ->expectsOutput('Prettifying code! This may take a second.') ->expectsOutput('Building frontend assets for production! This may take a second.') + ->expectsOutput('Prettifying code! This may take a second.') ->assertExitCode(0); - Process::assertRan(fn ($process) => $process->command === 'npx prettier '.Hyde::pathToRelative(Hyde::sitePath()).'/**/*.html --write --bracket-same-line'); Process::assertRan(fn ($process) => $process->command === 'npm run build'); + Process::assertRan(fn ($process) => $process->command === 'npx prettier '.Hyde::pathToRelative(Hyde::sitePath()).'/**/*.html --write --bracket-same-line'); } public function testPrettyUrlsOptionOutput() From 25bbab88d63fd59c1a2730342e03e30023177865 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 11 Nov 2024 19:21:56 +0100 Subject: [PATCH 5/5] Add a temporary helper to give a helpful error message --- .../src/Console/Commands/BuildSiteCommand.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Console/Commands/BuildSiteCommand.php b/packages/framework/src/Console/Commands/BuildSiteCommand.php index 917cee2772a..3bc8f3d367c 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -29,7 +29,9 @@ class BuildSiteCommand extends Command {--run-vite : Build frontend assets using Vite} {--run-prettier : Format the output using NPM Prettier} {--pretty-urls : Should links in output use pretty URLs?} - {--no-api : Disable API calls, for example, Torchlight}'; + {--no-api : Disable API calls, for example, Torchlight} + {--run-dev : [Removed] Use --run-vite instead} + {--run-prod : [Removed] Use --run-vite instead}'; /** @var string */ protected $description = 'Build the static site'; @@ -39,6 +41,12 @@ class BuildSiteCommand extends Command public function handle(): int { + // CodeCoverageIgnoreStart + if ($this->option('run-dev') || $this->option('run-prod')) { + return $this->deprecatedRunMixCommandFailure(); + } + // CodeCoverageIgnoreEnd + $timeStart = microtime(true); $this->title('Building your static site!'); @@ -153,4 +161,21 @@ protected function getExitCode(): int return Command::SUCCESS; } + + /** + * This method is called when the removed --run-dev or --run-prod options are used. + * + * @deprecated Use --run-vite instead + * @since v2.0 - This will be removed after 2-3 minor releases depending on the timeframe between them. (~v2.3) + * + * @codeCoverageIgnore + */ + protected function deprecatedRunMixCommandFailure(): int + { + $this->error('The --run-dev and --run-prod options have been removed in HydePHP v2.0.'); + $this->info('Please use --run-vite instead to build assets for production with Vite.'); + $this->line('See https://github.com/hydephp/develop/pull/2013 for more information.'); + + return Command::FAILURE; + } }