diff --git a/src/Pwa/Bundle/AssetService.php b/src/Pwa/Bundle/AssetService.php index ef0e5a3..1a75d5f 100644 --- a/src/Pwa/Bundle/AssetService.php +++ b/src/Pwa/Bundle/AssetService.php @@ -4,6 +4,7 @@ use League\Flysystem\FileNotFoundException; use League\Flysystem\FilesystemInterface; +use Shopware\Core\Framework\App\AppEntity; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; @@ -28,7 +29,7 @@ class AssetService implements EventSubscriberInterface /** * @var string */ - private $resourcesDirectory = '/Resources/app/pwa'; + private $resourcesDirectory = '/src/Resources/app/pwa'; /** * @var Kernel @@ -41,6 +42,11 @@ class AssetService implements EventSubscriberInterface private $pluginRepository; + /** + * @var EntityRepositoryInterface + */ + private $appRepository; + /** * @var FormattingHelper */ @@ -51,10 +57,16 @@ class AssetService implements EventSubscriberInterface */ private $fileSystem; - public function __construct(Kernel $kernel, EntityRepositoryInterface $pluginRepository, FormattingHelper $helper, FilesystemInterface $fileSystem) + public function __construct( + Kernel $kernel, + EntityRepositoryInterface $pluginRepository, + EntityRepositoryInterface $appRepository, + FormattingHelper $helper, + FilesystemInterface $fileSystem) { $this->kernel = $kernel; $this->pluginRepository = $pluginRepository; + $this->appRepository = $appRepository; $this->helper = $helper; $this->fileSystem = $fileSystem; } @@ -73,7 +85,7 @@ public function dumpBundles(): string $archivePath = $this->kernel->getCacheDir() . '/../../' . $this->assetArtifactDirectory . '.zip'; // Look for assets - list($bundles, $checksum) = $this->getBundles(); + list($bundles, $checksum) = $this->getExtensions(); // Zip directory $this->createAssetsArchive($archivePath, $bundles); @@ -119,35 +131,38 @@ private function createAssetsArchive(string $archivePath, array $bundles) $zip->close(); } - private function getBundles() + private function getExtensions() { $criteria = new Criteria(); $criteria->addFilter(new EqualsFilter('active', true)); /** @var PluginCollection $plugins */ $plugins = $this->pluginRepository->search($criteria, Context::createDefaultContext()); - $pluginNames = $plugins->map(function (PluginEntity $plugin) { - return $plugin->getName(); - }); + $apps = $this->appRepository->search($criteria, Context::createDefaultContext()); - /** @var BundleInterface[] $kernelBundles */ - $kernelBundles = $this->kernel->getBundles(); + $kernelProjectDir = $this->kernel->getProjectDir(); - foreach ($kernelBundles as $kernelBundle) - { - if(!in_array($kernelBundle->getName(), $pluginNames)) { - continue; - } + $extensionMetaData = []; + + /** @var $apps iterable */ + foreach($apps as $app) { + $extensionMetaData[] = [ + 'name' => $app->getName(), + 'path' => implode([$kernelProjectDir, $app->getPath()], DIRECTORY_SEPARATOR) + ]; + } - $bundles[] = [ - 'name' => $kernelBundle->getName(), - 'path' => $kernelBundle->getPath() + /** @var $apps iterable */ + foreach($plugins as $plugin) { + $extensionMetaData[] = [ + 'name' => $plugin->getName(), + 'path' => implode([$kernelProjectDir, $plugin->getPath()], DIRECTORY_SEPARATOR) ]; } - $checksum = md5(\GuzzleHttp\json_encode($bundles)); + $checksum = md5(\GuzzleHttp\json_encode($extensionMetaData)); - return [$bundles, $checksum]; + return [$extensionMetaData, $checksum]; } private function writeToPublicDirectory(string $sourceArchive, string $checksum = null): string diff --git a/src/Resources/config/bundle.xml b/src/Resources/config/bundle.xml index e0e23ed..ec1845a 100644 --- a/src/Resources/config/bundle.xml +++ b/src/Resources/config/bundle.xml @@ -39,6 +39,7 @@ +