forked from magento/ece-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGECLOUD-3011: Add Baler Support (magento#660)
- Loading branch information
Showing
10 changed files
with
564 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\MagentoCloud\Config\Validator\Build; | ||
|
||
use Magento\MagentoCloud\Config\Magento\Shared\ReaderInterface; | ||
use Magento\MagentoCloud\Config\Validator; | ||
use Magento\MagentoCloud\Config\ValidatorInterface; | ||
use Symfony\Component\Process\ExecutableFinder; | ||
|
||
/** | ||
* Verify that the build configuration is ready for baler. | ||
*/ | ||
class BalerSupport implements ValidatorInterface | ||
{ | ||
/** | ||
* @var ExecutableFinder | ||
*/ | ||
private $finder; | ||
|
||
/** | ||
* @var Validator\ResultFactory | ||
*/ | ||
private $resultFactory; | ||
|
||
/** | ||
* @var ReaderInterface | ||
*/ | ||
private $configReader; | ||
|
||
/** | ||
* @param Validator\ResultFactory $resultFactory | ||
* @param ExecutableFinder $finder | ||
* @param ReaderInterface $configReader | ||
*/ | ||
public function __construct( | ||
Validator\ResultFactory $resultFactory, | ||
ExecutableFinder $finder, | ||
ReaderInterface $configReader | ||
) { | ||
$this->resultFactory = $resultFactory; | ||
$this->finder = $finder; | ||
$this->configReader = $configReader; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
*/ | ||
public function validate(): Validator\ResultInterface | ||
{ | ||
$errors = []; | ||
|
||
if ($this->finder->find('baler') === null) { | ||
$errors[] = 'Path to baler executable could not be found.' | ||
. ' The Node package may not be installed or may not be linked.'; | ||
} | ||
|
||
$magentoConfig = $this->configReader->read(); | ||
|
||
if (!isset($magentoConfig['modules']['Magento_Baler']) || !$magentoConfig['modules']['Magento_Baler']) { | ||
$errors[] = 'The Magento_Baler module is not installed or is disabled.'; | ||
} | ||
|
||
$jsConfig = $magentoConfig['system']['default']['dev']['js'] ?? []; | ||
|
||
if (!isset($jsConfig['enable_baler_js_bundling']) || !$jsConfig['enable_baler_js_bundling']) { | ||
$errors[] = 'The Magento config dev/js/enable_baler_js_bundling must be enabled in app/etc/config.php.'; | ||
} | ||
|
||
foreach (['minify_files', 'enable_js_bundling', 'merge_files'] as $configKey) { | ||
if (!isset($jsConfig[$configKey]) || $jsConfig[$configKey]) { | ||
$errors[] = sprintf('The Magento config dev/js/%s must be disabled in app/etc/config.php.', $configKey); | ||
} | ||
} | ||
|
||
return $errors === [] | ||
? $this->resultFactory->success() | ||
: $this->resultFactory->error( | ||
'Baler JS bundling cannot be used because of the following issues:', | ||
implode(PHP_EOL, $errors) | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\MagentoCloud\Step\Build; | ||
|
||
use Magento\MagentoCloud\Config\Stage\BuildInterface; | ||
use Magento\MagentoCloud\Config\ValidatorInterface; | ||
use Magento\MagentoCloud\Config\Validator\Result; | ||
use Magento\MagentoCloud\Filesystem\Flag; | ||
use Magento\MagentoCloud\Shell\ShellException; | ||
use Magento\MagentoCloud\Shell\ShellInterface; | ||
use Magento\MagentoCloud\Step\StepException; | ||
use Magento\MagentoCloud\Step\StepInterface; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Attempt to perform JS bundling using Baler. | ||
*/ | ||
class RunBaler implements StepInterface | ||
{ | ||
/** | ||
* @var BuildInterface | ||
*/ | ||
private $buildConfig; | ||
|
||
/** | ||
* @var Flag\Manager | ||
*/ | ||
private $flagManager; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @var ValidatorInterface | ||
*/ | ||
private $validator; | ||
|
||
/** | ||
* @var ShellInterface | ||
*/ | ||
private $shell; | ||
|
||
/** | ||
* @param LoggerInterface $logger, | ||
* @param BuildInterface $buildConfig, | ||
* @param Flag\Manager $flagManager, | ||
* @param ValidatorInterface $validator, | ||
* @param ShellInterface $shell | ||
*/ | ||
public function __construct( | ||
LoggerInterface $logger, | ||
BuildInterface $buildConfig, | ||
Flag\Manager $flagManager, | ||
ValidatorInterface $validator, | ||
ShellInterface $shell | ||
) { | ||
$this->logger = $logger; | ||
$this->buildConfig = $buildConfig; | ||
$this->flagManager = $flagManager; | ||
$this->validator = $validator; | ||
$this->shell = $shell; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute() | ||
{ | ||
if (!$this->buildConfig->get(BuildInterface::VAR_SCD_USE_BALER)) { | ||
$this->logger->debug('Baler JS bundling is disabled.'); | ||
|
||
return; | ||
} | ||
|
||
if (!$this->flagManager->exists(Flag\Manager::FLAG_STATIC_CONTENT_DEPLOY_IN_BUILD)) { | ||
$this->logger->notice('Cannot run baler because static content has not been deployed.'); | ||
|
||
return; | ||
} | ||
|
||
$result = $this->validator->validate(); | ||
|
||
if ($result instanceof Result\Error) { | ||
$this->logger->warning($result->getError()); | ||
|
||
foreach (explode(PHP_EOL, $result->getSuggestion()) as $detail) { | ||
$this->logger->warning(' - ' . $detail); | ||
} | ||
|
||
return; | ||
} | ||
|
||
$this->logger->info('Running Baler JS bundler.'); | ||
|
||
try { | ||
$this->shell->execute('baler'); | ||
} catch (ShellException $exception) { | ||
throw new StepException($exception->getMessage(), $exception->getCode(), $exception); | ||
} | ||
|
||
$this->logger->info('Baler JS bundling complete.'); | ||
} | ||
} |
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
Oops, something went wrong.