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 28, 2023
1 parent c19902b commit 44f3979
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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
{
$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 44f3979

Please sign in to comment.