diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c249bb0dfe4..7d14e72431f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -92,6 +92,8 @@ 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 +- 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/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..3bc8f3d367c 100644 --- a/packages/framework/src/Console/Commands/BuildSiteCommand.php +++ b/packages/framework/src/Console/Commands/BuildSiteCommand.php @@ -26,11 +26,12 @@ 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}'; + {--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'; @@ -40,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!'); @@ -85,6 +92,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(); } @@ -99,14 +110,6 @@ public function runPostBuildActions(): void 'prettify code' ); } - - if ($this->option('run-dev')) { - $this->runNodeCommand('npm run dev', 'Building frontend assets for development!'); - } - - if ($this->option('run-prod')) { - $this->runNodeCommand('npm run build', 'Building frontend assets for production!'); - } } protected function printFinishMessage(float $timeStart): void @@ -158,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; + } } diff --git a/packages/framework/tests/Feature/StaticSiteServiceTest.php b/packages/framework/tests/Feature/StaticSiteServiceTest.php index 25931842235..64376c3aa23 100644 --- a/packages/framework/tests/Feature/StaticSiteServiceTest.php +++ b/packages/framework/tests/Feature/StaticSiteServiceTest.php @@ -160,15 +160,13 @@ public function testNodeActionOutputs() { Process::fake(); - $this->artisan('build --run-prettier --run-dev --run-prod') - ->expectsOutput('Prettifying code! This may take a second.') - ->expectsOutput('Building frontend assets for development! This may take a second.') + $this->artisan('build --run-prettier --run-vite') ->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 dev'); 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()