Skip to content

Commit 1d79bd5

Browse files
authored
Merge pull request #2013 from hydephp/new-vite-build-command-flag
[2.x] Replace `--run-dev` and `--run-prod` build command flags with `--run-vite` flag
2 parents 3b89ec0 + 25bbab8 commit 1d79bd5

4 files changed

Lines changed: 38 additions & 19 deletions

File tree

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ This serves two purposes:
9292
- **Breaking:** You must now use `npm run build` to compile your assets, instead of `npm run prod`
9393
- 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
9494
- 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
95+
- **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
96+
- 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
9597

9698
### Deprecated
9799

docs/getting-started/console-commands.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Here is a quick reference of all the available commands. You can also run `php h
6666
<a name="build" style="display: inline-block; position: absolute; margin-top: -5rem;"></a>
6767

6868
```bash
69-
php hyde build [--run-dev] [--run-prod] [--run-prettier] [--pretty-urls] [--no-api]
69+
php hyde build [--run-vite] [--run-prettier] [--pretty-urls] [--no-api]
7070
```
7171

7272
Build the static site
@@ -75,8 +75,7 @@ Build the static site
7575

7676
| | |
7777
|------------------|--------------------------------------------|
78-
| `--run-dev` | Run the NPM dev script after build |
79-
| `--run-prod` | Run the NPM prod script after build |
78+
| `--run-vite` | Build frontend assets using Vite |
8079
| `--run-prettier` | Format the output using NPM Prettier |
8180
| `--pretty-urls` | Should links in output use pretty URLs? |
8281
| `--no-api` | Disable API calls, for example, Torchlight |

packages/framework/src/Console/Commands/BuildSiteCommand.php

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ class BuildSiteCommand extends Command
2626
{
2727
/** @var string */
2828
protected $signature = 'build
29-
{--run-dev : Run the NPM dev script after build}
30-
{--run-prod : Run the NPM prod script after build}
29+
{--run-vite : Build frontend assets using Vite}
3130
{--run-prettier : Format the output using NPM Prettier}
3231
{--pretty-urls : Should links in output use pretty URLs?}
33-
{--no-api : Disable API calls, for example, Torchlight}';
32+
{--no-api : Disable API calls, for example, Torchlight}
33+
{--run-dev : [Removed] Use --run-vite instead}
34+
{--run-prod : [Removed] Use --run-vite instead}';
3435

3536
/** @var string */
3637
protected $description = 'Build the static site';
@@ -40,6 +41,12 @@ class BuildSiteCommand extends Command
4041

4142
public function handle(): int
4243
{
44+
// CodeCoverageIgnoreStart
45+
if ($this->option('run-dev') || $this->option('run-prod')) {
46+
return $this->deprecatedRunMixCommandFailure();
47+
}
48+
// CodeCoverageIgnoreEnd
49+
4350
$timeStart = microtime(true);
4451

4552
$this->title('Building your static site!');
@@ -85,6 +92,10 @@ protected function runPreBuildActions(): void
8592
Config::set(['hyde.pretty_urls' => true]);
8693
}
8794

95+
if ($this->option('run-vite')) {
96+
$this->runNodeCommand('npm run build', 'Building frontend assets for production!');
97+
}
98+
8899
$this->taskService->runPreBuildTasks();
89100
}
90101

@@ -99,14 +110,6 @@ public function runPostBuildActions(): void
99110
'prettify code'
100111
);
101112
}
102-
103-
if ($this->option('run-dev')) {
104-
$this->runNodeCommand('npm run dev', 'Building frontend assets for development!');
105-
}
106-
107-
if ($this->option('run-prod')) {
108-
$this->runNodeCommand('npm run build', 'Building frontend assets for production!');
109-
}
110113
}
111114

112115
protected function printFinishMessage(float $timeStart): void
@@ -158,4 +161,21 @@ protected function getExitCode(): int
158161

159162
return Command::SUCCESS;
160163
}
164+
165+
/**
166+
* This method is called when the removed --run-dev or --run-prod options are used.
167+
*
168+
* @deprecated Use --run-vite instead
169+
* @since v2.0 - This will be removed after 2-3 minor releases depending on the timeframe between them. (~v2.3)
170+
*
171+
* @codeCoverageIgnore
172+
*/
173+
protected function deprecatedRunMixCommandFailure(): int
174+
{
175+
$this->error('The --run-dev and --run-prod options have been removed in HydePHP v2.0.');
176+
$this->info('Please use --run-vite instead to build assets for production with Vite.');
177+
$this->line('See https://github.com/hydephp/develop/pull/2013 for more information.');
178+
179+
return Command::FAILURE;
180+
}
161181
}

packages/framework/tests/Feature/StaticSiteServiceTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,13 @@ public function testNodeActionOutputs()
160160
{
161161
Process::fake();
162162

163-
$this->artisan('build --run-prettier --run-dev --run-prod')
164-
->expectsOutput('Prettifying code! This may take a second.')
165-
->expectsOutput('Building frontend assets for development! This may take a second.')
163+
$this->artisan('build --run-prettier --run-vite')
166164
->expectsOutput('Building frontend assets for production! This may take a second.')
165+
->expectsOutput('Prettifying code! This may take a second.')
167166
->assertExitCode(0);
168167

169-
Process::assertRan(fn ($process) => $process->command === 'npx prettier '.Hyde::pathToRelative(Hyde::sitePath()).'/**/*.html --write --bracket-same-line');
170-
Process::assertRan(fn ($process) => $process->command === 'npm run dev');
171168
Process::assertRan(fn ($process) => $process->command === 'npm run build');
169+
Process::assertRan(fn ($process) => $process->command === 'npx prettier '.Hyde::pathToRelative(Hyde::sitePath()).'/**/*.html --write --bracket-same-line');
172170
}
173171

174172
public function testPrettyUrlsOptionOutput()

0 commit comments

Comments
 (0)