Skip to content

Commit

Permalink
Merge pull request #2037 from hydephp/remove-the-hyde-css-file-from-h…
Browse files Browse the repository at this point in the history
…ydefront

Remove the `hyde.css` file from HydeFront
  • Loading branch information
caendesilva authored Nov 17, 2024
2 parents b238280 + a12b565 commit 3c42843
Show file tree
Hide file tree
Showing 20 changed files with 21 additions and 733 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,41 +109,6 @@ jobs:
run: php monorepo/scripts/tests/${{ matrix.script }}.php


build-hydefront-assets:

runs-on: ubuntu-latest
needs: run-smoke-tests

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: 'npm'

- name: Install Node.js dependencies
working-directory: 'packages/hydefront'
run: npm ci

- name: Build assets for production
working-directory: 'packages/hydefront'
run: npm run build

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: 'hydefront'
path: 'packages/hydefront/dist'

- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
add: 'packages/hydefront/dist'
message: 'Compile HydeFront assets for production'
new_branch: compile-hydefront


build-tailwindcss:

runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ This serves two purposes:
- Removed CDN include for the HydeSearch plugin replaced by Alpine.js implementation in https://github.com/hydephp/develop/pull/2029
- This also removes the `<x-hyde::docs.search-input />` and `<x-hyde::docs.search-scripts />` Blade components, replaced by the new `<x-hyde::docs.hyde-search />` component.
- Removed the `.torchlight-enabled` CSS class in https://github.com/hydephp/develop/pull/2036.
- Removed The `hyde.css` file from HydeFront in https://github.com/hydephp/develop/pull/2037 as all styles were refactored to Tailwind in https://github.com/hydephp/develop/pull/2024.

### Fixed

Expand All @@ -145,6 +146,10 @@ This serves two purposes:
- Simplified the asset file locator to only serve files from the media source directory in https://github.com/hydephp/develop/pull/2012
- Added Vite HMR support in https://github.com/hydephp/develop/pull/2016

#### HydeFront

- Removed the `hyde.css` file in https://github.com/hydephp/develop/pull/2037 as all its styles were refactored to Tailwind in https://github.com/hydephp/develop/pull/2024

### Upgrade Guide

Please see the "Breaking changes & upgrade guide" section below for more information.
Expand Down
2 changes: 1 addition & 1 deletion _media/app.css

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions monorepo/docs/hydefront.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Internal HydeFront documentation

## Building and creating a new HydeFront version
## Creating a new HydeFront version

### Prerequisites

Expand Down Expand Up @@ -28,15 +28,14 @@ cd ../../
npm link hydefront
```

### Build and setup
### Setup

```bash
cd packages/hydefront
git pull origin master
npm run build
```

### Build, version, and publish
### Version and publish

Head back to the monorepo root and run the following command to bump the version of the HydeFront package:

Expand Down
4 changes: 3 additions & 1 deletion packages/framework/src/Facades/HydeFront.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public static function version(): string
/**
* Get the CDN link for a specific file.
*
* @param 'app.css'|'hyde.css'|'hyde.css.map' $file
* @deprecated This method may be removed before the final v2.0 release as there is now currently only one file available.
*
* @param 'app.css' $file
*
* @link https://cdn.jsdelivr.net/npm/hydefront@latest/dist/ for the available files.
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public function testCdnLinkReturnsCorrectUrl()
$this->assertSame($expected, HydeFront::cdnLink('styles.css'));
}

public function testCdnLinkReturnsCorrectUrlForHydeCss()
public function testCdnLinkReturnsCorrectUrlForArbitraryCss()
{
$expected = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/hyde.css';
$this->assertSame($expected, HydeFront::cdnLink('hyde.css'));
$expected = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/arbitrary.css';
$this->assertSame($expected, HydeFront::cdnLink('arbitrary.css'));
}

public function testCdnLinkReturnsCorrectUrlForInvalidFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Hyde\Framework\Testing\Unit\Views;

use Hyde\Facades\Filesystem;
use Hyde\Facades\HydeFront;
use Hyde\Hyde;
use Hyde\Support\Facades\Render;
Expand Down Expand Up @@ -88,11 +87,4 @@ public function testComponentDoesNotRenderLinkToLocalAppCssWhenCdnLinkIsEnabledI
config(['hyde.load_app_styles_from_cdn' => true]);
$this->assertStringNotContainsString('<link rel="stylesheet" href="media/app.css"', $this->renderTestView());
}

public function testComponentDoesNotRenderCdnLinkWhenALocalFileExists()
{
Filesystem::touch('_media/hyde.css');
$this->assertStringNotContainsString('https://cdn.jsdelivr.net/npm/hydefront', $this->renderTestView());
Filesystem::unlink('_media/hyde.css');
}
}
98 changes: 1 addition & 97 deletions packages/hydefront/.github/scripts/post-build.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,105 +25,9 @@
return 1;
} else {
$this->info('Root package lock verified. All looks good!');
$this->line();
}
}
}

if ($this->hasOption('inject-version')) {
$package = json_decode(file_get_contents($baseDir.'package.json'), true);
$version = $package['version'];
$css = file_get_contents($baseDir.'dist/hyde.css');

if (str_contains($css, '/*! HydeFront')) {
$this->error('Version already injected in dist/hyde.css');
return 1;
}

$template = '/*! HydeFront v{{ $version }} | MIT License | https://hydephp.com*/';
$versionString = str_replace('{{ $version }}', $version, $template);
$css = "$versionString\n$css";
file_put_contents($baseDir.'dist/hyde.css', $css);

return 0;
}

$this->info('Verifying build files...');
$exitCode = 0;

$package = json_decode(file_get_contents($baseDir.'package.json'), true);
$version = $package['version'];
$this->line("Found version '$version' in package.json");

$hydeCssVersion = getCssVersion($baseDir.'dist/hyde.css');
$this->line("Found version '$hydeCssVersion' in dist/hyde.css");

$appCssVersion = getCssVersion($baseDir.'dist/app.css');
$this->line("Found version '$appCssVersion' in dist/app.css");

if ($this->hasOption('fix')) {
$this->info('Fixing build files...');

if ($version !== $hydeCssVersion) {
$this->line(' > Updating dist/hyde.css...');
$contents = file_get_contents($baseDir.'dist/hyde.css');
$contents = str_replace($hydeCssVersion, $version, $contents);
file_put_contents($baseDir.'dist/hyde.css', $contents);
$filesChanged = true;
}

if ($version !== $appCssVersion) {
$this->line(' > Updating dist/app.css...');
$contents = file_get_contents($baseDir.'dist/app.css');
$contents = str_replace($appCssVersion, $version, $contents);
file_put_contents($baseDir.'dist/app.css', $contents);
$filesChanged = true;
}

if (isset($filesChanged)) {
$this->info('Build files fixed');

$this->info('Tip: You may want to verify the changes again.');
} else {
$this->warning('Nothing to fix!');
}
return 0;
}

if ($version !== $hydeCssVersion) {
$this->error('Version mismatch in package.json and dist/hyde.css:');
$this->warning("Expected hyde.css to have version '$version', but found '$hydeCssVersion'");
$exitCode = 1;
}

if ($version !== $appCssVersion) {
$this->error('Version mismatch in package.json and dist/app.css:');
$this->warning("Expected app.css to have version '$version', but found '$appCssVersion'");
$exitCode = 1;
}

if ($exitCode > 0) {
$this->error('Exiting with errors.');
} else {
$this->info('Build files verified. All looks good!');
}

return $exitCode;
return 0;
}));

function getCssVersion(string $path): string
{
$contents = file_get_contents($path);
$prefix = '/*! HydeFront v';
if (! str_starts_with($contents, $prefix)) {
throw new Exception('Invalid CSS file');
}
$contents = substr($contents, strlen($prefix));
// Get everything before |
$pipePos = strpos($contents, '|');
if ($pipePos === false) {
throw new Exception('Invalid CSS file');
}
$contents = substr($contents, 0, $pipePos);
return trim($contents);
}
2 changes: 1 addition & 1 deletion packages/hydefront/.github/scripts/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

$this->info('Updating version in dist files...');
$this->line('---');
passthru('php packages/hydefront/.github/scripts/post-build.php --fix --skip-root-version-check', $fixExitCode);
passthru('php packages/hydefront/.github/scripts/post-build.php --skip-root-version-check', $fixExitCode);
if ($fixExitCode !== 0) {
$this->error('Failed to update version in dist files');
FileBackupHelper::restore();
Expand Down
20 changes: 0 additions & 20 deletions packages/hydefront/.github/workflows/dependency-review.yml

This file was deleted.

34 changes: 0 additions & 34 deletions packages/hydefront/.github/workflows/devskim.yml

This file was deleted.

39 changes: 0 additions & 39 deletions packages/hydefront/.github/workflows/node.js.yml

This file was deleted.

8 changes: 1 addition & 7 deletions packages/hydefront/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ Contains the frontend assets for HydePHP.

### About the files

- **Hyde.css**:
The Hyde stylesheet contains a small set of styles that don't make sense to use with Tailwind, or that belong to generated content that is harder to modify.

Normally, this file is imported into the main.css file.

- **App.css**:
A compiled and minified file containing the TailwindCSS styles for a base Hyde installation. It includes the Hyde.css file. This file is identical to what one would get by running `npm run build` in a new HydePHP project (which incidentally is exactly how this file is generated).

A compiled and minified file containing the TailwindCSS styles for a base Hyde installation. This file is identical to what one would get by running `npm run build` in a new HydePHP project (which incidentally is exactly how this file is generated).

## Usage

Expand Down
2 changes: 1 addition & 1 deletion packages/hydefront/dist/app.css

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions packages/hydefront/dist/hyde.css

This file was deleted.

1 change: 0 additions & 1 deletion packages/hydefront/dist/hyde.css.map

This file was deleted.

7 changes: 0 additions & 7 deletions packages/hydefront/hyde.scss

This file was deleted.

Loading

0 comments on commit 3c42843

Please sign in to comment.