Skip to content

Commit

Permalink
auto load plugin manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
passchn committed Oct 29, 2023
1 parent 0d74d22 commit 4b71f36
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
/config/Migrations/schema-dump-default.lock
/vendor/
/.idea/
.DS_Store
.DS_Store
.phpunit.cache
4 changes: 3 additions & 1 deletion src/Exception/ViteHelperException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace ViteHelper\Exception;

abstract class ViteHelperException extends \Exception
use Exception;

abstract class ViteHelperException extends Exception
{
}
16 changes: 13 additions & 3 deletions src/Utilities/ViteManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace ViteHelper\Utilities;

use Cake\Core\Plugin;
use ViteHelper\Exception\ManifestNotFoundException;

/**
Expand All @@ -14,13 +15,17 @@ class ViteManifest
* Returns the manifest records as a Collection
*
* @param \ViteHelper\Utilities\ViteHelperConfig $config plugin config instance
* @return \ViteHelper\Utilities\ManifestRecords|\ViteHelper\Utilities\ManifestRecord[]
* @return \ViteHelper\Utilities\ManifestRecords|array<\ViteHelper\Utilities\ManifestRecord>
* @throws \ViteHelper\Exception\ManifestNotFoundException
* @internal
*/
public static function getRecords(ViteHelperConfig $config): ManifestRecords

Check failure on line 22 in src/Utilities/ViteManifest.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

PHPDoc tag @return with type array<ViteHelper\Utilities\ManifestRecord>|ViteHelper\Utilities\ManifestRecords is not subtype of native type ViteHelper\Utilities\ManifestRecords.
{
$manifestPath = $config->read('build.manifest', ConfigDefaults::BUILD_MANIFEST);
if ($config->read('plugin') && $config->read('build.manifest') === null) {
$manifestPath = static::getPluginManifestPath($config->read('plugin'));
} else {
$manifestPath = $config->read('build.manifest', ConfigDefaults::BUILD_MANIFEST);
}

if (!is_readable($manifestPath)) {
throw new ManifestNotFoundException(
Expand All @@ -29,7 +34,7 @@ public static function getRecords(ViteHelperConfig $config): ManifestRecords
}

// phpcs:ignore
$json = @file_get_contents($manifestPath);
$json = @file_get_contents($manifestPath);

if ($json === false) {
throw new ManifestNotFoundException('Could not parse manifest.json');
Expand Down Expand Up @@ -68,4 +73,9 @@ public static function getRecords(ViteHelperConfig $config): ManifestRecords

return new ManifestRecords($manifestArray, $manifestPath);
}

protected static function getPluginManifestPath(string $pluginName): string
{
return Plugin::path($pluginName) . 'webroot' . DS . 'manifest.json';
}
}

0 comments on commit 4b71f36

Please sign in to comment.