deployStaticFile = $deployStaticFile; $this->packageFileFactory = $packageFileFactory; $this->formatter = $formatter; $this->minification = $minification; } /** * @inheritdoc */ public function process(Package $package, array $options) { if ($package->isVirtual()) { return true; } // delete existing map files $this->deployStaticFile->deleteFile($package->getPath() . '/' . RepositoryMap::MAP_NAME); $this->deployStaticFile->deleteFile($package->getPath() . '/' . RepositoryMap::REQUIRE_JS_MAP_NAME); $this->deployStaticFile->deleteFile($package->getPath() . '/' . RepositoryMap::RESULT_MAP_NAME); if (!$package->getParam('build_map')) { return true; } $this->options = $options; $packageMap = $package->getParentMap(); if ($packageMap) { $this->deployStaticFile->writeFile( RepositoryMap::MAP_NAME, $package->getPath(), json_encode($packageMap) ); $this->deployStaticFile->writeFile( $this->minification->addMinifiedSign(RepositoryMap::REQUIRE_JS_MAP_NAME), $package->getPath(), $this->getRequireJsMap($packageMap) ); } $resultMap = $package->getResultMap(); if ($resultMap) { $this->deployStaticFile->writeFile( RepositoryMap::RESULT_MAP_NAME, $package->getPath(), json_encode($resultMap) ); } return true; } /** * Retrieve require js map * * @param array $map * @return string */ private function getRequireJsMap(array $map) { $jsonMap = []; foreach ($map as $fileId => $fileInfo) { if (!in_array(pathinfo($fileId, PATHINFO_EXTENSION), ['js', 'html'])) { continue; } $fileId = '/' . $fileId; // add leading slash to match exclude patterns $filePath = $this->minification->addMinifiedSign(str_replace(Repository::FILE_ID_SEPARATOR, '/', $fileId)); $filePath = substr($filePath, 1); // and remove $jsonMap[$filePath] = '../../../../' . $fileInfo['area'] . '/' . $fileInfo['theme'] . '/' . $fileInfo['locale'] . '/'; } $jsonMap = json_encode($jsonMap); return "require.config({\"config\": {\"baseUrlInterceptor\":{$jsonMap}}});"; } }