-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61338d0
commit fa9517b
Showing
10 changed files
with
122 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright © Magefan ([email protected]). All rights reserved. | ||
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php). | ||
* | ||
* Glory to Ukraine! Glory to the heroes! | ||
*/ | ||
|
||
namespace Magefan\RocketJavaScript\Plugin\Deploy\Package\Bundle; | ||
|
||
use Magento\Deploy\Package\Bundle\RequireJs; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
class RequireJsPlugin | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
const BUNDLING_OPTIMIZATION_ENABLED = 'mfrocketjavascript/general/enable_js_bundling_optimization'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
const INCLUDE_IN_BUNDLING = 'mfrocketjavascript/general/included_in_bundling'; | ||
|
||
/** | ||
* @var \Magento\Framework\App\Config\ScopeConfigInterface | ||
*/ | ||
protected $scopeConfig; | ||
|
||
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig) | ||
/** | ||
* mixed | ||
*/ | ||
protected $allowedFiles; | ||
|
||
/** | ||
* Construct | ||
* | ||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig | ||
*/ | ||
public function __construct(ScopeConfigInterface $scopeConfig) | ||
{ | ||
$this->scopeConfig = $scopeConfig; | ||
} | ||
|
||
public function aroundAddFile(RequireJs $subject, callable $proceed, $filePath, $sourcePath, $contentType) { | ||
/** | ||
* Improve bundling | ||
*/ | ||
public function aroundAddFile(RequireJs $subject, callable $proceed, $filePath, $sourcePath, $contentType) | ||
{ | ||
|
||
$jsOptimization = $this->scopeConfig->getValue('mfrocketjavascript/general/enable_javaScript_bundling_optimization', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); | ||
$jsOptimization = $this->scopeConfig->getValue(self::BUNDLING_OPTIMIZATION_ENABLED, ScopeInterface::SCOPE_STORE); | ||
if ($jsOptimization) { | ||
$includeInBundling = $this->scopeConfig->getValue('mfrocketjavascript/general/included_in_bundling', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); | ||
$allowedFiles = str_replace("\r","\n", $includeInBundling); | ||
$allowedFiles = explode("\n", $allowedFiles); | ||
|
||
foreach ($allowedFiles as $key => $allowedFile) { | ||
$allowedFiles[$key] = trim($allowedFile); | ||
if (empty($allowedFiles[$key])) { | ||
unset($allowedFiles[$key]); | ||
} | ||
} | ||
|
||
foreach ($allowedFiles as $allowed) { | ||
$allowedFiles[] = str_replace('.min.js', '.js', $allowed); | ||
} | ||
$allowedFiles = $this->getAllowedFiles(); | ||
|
||
$include = false; | ||
foreach ($allowedFiles as $allowedFile) { | ||
|
@@ -42,8 +66,35 @@ public function aroundAddFile(RequireJs $subject, callable $proceed, $filePath, | |
if (!$include) { | ||
return true; | ||
} | ||
|
||
} | ||
return $proceed($filePath, $sourcePath, $contentType); | ||
} | ||
} | ||
|
||
public function getAllowedFiles() | ||
{ | ||
if (null === $this->allowedFiles) { | ||
$includeInBundling = $this->scopeConfig->getValue(self::INCLUDE_IN_BUNDLING, ScopeInterface::SCOPE_STORE); | ||
$allowedFiles = str_replace("\r", "\n", $includeInBundling); | ||
$allowedFiles = explode("\n", $allowedFiles); | ||
|
||
foreach ($allowedFiles as $key => $allowedFile) { | ||
$allowedFiles[$key] = trim($allowedFile); | ||
if (empty($allowedFiles[$key])) { | ||
unset($allowedFiles[$key]); | ||
} | ||
} | ||
|
||
foreach ($allowedFiles as $allowed) { | ||
if (false !== strpos($allowed, '.min.js')) { | ||
$allowedFiles[] = str_replace('.min.js', '.js', $allowed); | ||
} else { | ||
$allowedFiles[] = str_replace('.js', '.min.js', $allowed); | ||
} | ||
} | ||
|
||
$this->allowedFiles = $allowedFiles; | ||
} | ||
|
||
return $this->allowedFiles; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magefan ([email protected]). All rights reserved. | ||
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php). | ||
* | ||
* Glory to Ukraine! Glory to the heroes! | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Deploy\Package\Bundle\RequireJs"> | ||
<plugin name="magefan_rocketjavascript_plugin_deploy_package_bundle_requirejs" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
<?xml version="1.0" ?> | ||
<!-- | ||
/** | ||
* Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved. | ||
* Copyright © Magefan (support@magefan.com). All rights reserved. | ||
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php). | ||
* | ||
* Glory to Ukraine! Glory to the heroes! | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Magefan_RocketJavaScript" setup_version="2.0.0"/> | ||
<module name="Magefan_RocketJavaScript" setup_version="2.1.0"> | ||
<sequence> | ||
<module name="Magefan_Community"/> | ||
</sequence> | ||
</module> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters