Skip to content

Commit 44f3979

Browse files
committed
auto load plugin manifest
1 parent c19902b commit 44f3979

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Exception/ViteHelperException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace ViteHelper\Exception;
55

6-
abstract class ViteHelperException extends \Exception
6+
use Exception;
7+
8+
abstract class ViteHelperException extends Exception
79
{
810
}

src/Utilities/ViteManifest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace ViteHelper\Utilities;
55

6+
use Cake\Core\Plugin;
67
use ViteHelper\Exception\ManifestNotFoundException;
78

89
/**
@@ -14,13 +15,17 @@ class ViteManifest
1415
* Returns the manifest records as a Collection
1516
*
1617
* @param \ViteHelper\Utilities\ViteHelperConfig $config plugin config instance
17-
* @return \ViteHelper\Utilities\ManifestRecords|\ViteHelper\Utilities\ManifestRecord[]
18+
* @return \ViteHelper\Utilities\ManifestRecords|array<\ViteHelper\Utilities\ManifestRecord>
1819
* @throws \ViteHelper\Exception\ManifestNotFoundException
1920
* @internal
2021
*/
2122
public static function getRecords(ViteHelperConfig $config): ManifestRecords
2223
{
23-
$manifestPath = $config->read('build.manifest', ConfigDefaults::BUILD_MANIFEST);
24+
if ($config->read('plugin') && $config->read('build.manifest') === null) {
25+
$manifestPath = static::getPluginManifestPath($config->read('plugin'));
26+
} else {
27+
$manifestPath = $config->read('build.manifest', ConfigDefaults::BUILD_MANIFEST);
28+
}
2429

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

3136
// phpcs:ignore
32-
$json = @file_get_contents($manifestPath);
37+
$json = @file_get_contents($manifestPath);
3338

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

6974
return new ManifestRecords($manifestArray, $manifestPath);
7075
}
76+
77+
protected static function getPluginManifestPath(string $pluginName): string
78+
{
79+
return Plugin::path($pluginName) . 'webroot' . DS . 'manifest.json';
80+
}
7181
}

0 commit comments

Comments
 (0)