-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHighPerformanceStaticDeployTask.php
More file actions
59 lines (48 loc) · 1.8 KB
/
HighPerformanceStaticDeployTask.php
File metadata and controls
59 lines (48 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace Hypernode\Deploy\Deployer\Task\Build;
use Hypernode\Deploy\Deployer\Task\TaskBase;
use Hypernode\DeployConfiguration\Configuration;
use function Deployer\get;
use function Deployer\run;
use function Deployer\task;
use function Deployer\within;
/**
* High-performance static content deployment using elgentos/magento2-static-deploy.
*
* @see https://github.com/elgentos/magento2-static-deploy
*/
class HighPerformanceStaticDeployTask extends TaskBase
{
private const BINARY_PATH = '/opt/magento2-static-deploy';
public function configure(Configuration $config): void
{
if (!$this->isEnabled($config)) {
return;
}
task('magento:deploy:assets', function () {
$themes = get('magento_themes', []);
$themeArgs = $this->buildThemeArgs($themes);
$locales = get('static_content_locales', 'en_US');
$contentVersion = get('content_version', time());
within('{{release_or_current_path}}', function () use ($themeArgs, $locales, $contentVersion) {
run(self::BINARY_PATH . " --force --area=frontend --area=adminhtml $themeArgs --content-version=$contentVersion --verbose $locales");
});
})->select('stage=build');
}
public function isEnabled(Configuration $config): bool
{
$variables = $config->getVariables();
$buildVariables = $config->getVariables('build');
return $variables['high_performance_static_deploy']
?? $buildVariables['high_performance_static_deploy']
?? false;
}
/**
* @param array<string, string> $themes
*/
public function buildThemeArgs(array $themes): string
{
return implode(' ', array_map(fn($t) => "--theme=$t", array_keys($themes)));
}
}