-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
Copy pathDeployRequireJsConfig.php
119 lines (105 loc) · 3.37 KB
/
DeployRequireJsConfig.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Deploy\Service;
use Magento\Framework\Locale\ResolverInterfaceFactory;
use Magento\Framework\Locale\ResolverInterface;
use Magento\RequireJs\Model\FileManagerFactory;
use Magento\Framework\View\DesignInterfaceFactory;
use Magento\Framework\View\Design\Theme\ListInterface;
use Magento\Framework\View\Asset\RepositoryFactory;
use Magento\Framework\RequireJs\ConfigFactory;
/**
* Deploy RequireJS configuration service
*/
class DeployRequireJsConfig
{
/**
* Default jobs amount
*/
const DEFAULT_JOBS_AMOUNT = 4;
/**
* @var ListInterface
*/
private $themeList;
/**
* @var DesignInterfaceFactory
*/
private $designFactory;
/**
* @var RepositoryFactory
*/
private $assetRepoFactory;
/**
* @var FileManagerFactory
*/
private $fileManagerFactory;
/**
* @var ConfigFactory
*/
private $requireJsConfigFactory;
/**
* @var ResolverInterfaceFactory
*/
private $localeFactory;
/**
* DeployRequireJsConfig constructor
*
* @param ListInterface $themeList
* @param DesignInterfaceFactory $designFactory
* @param RepositoryFactory $assetRepoFactory
* @param FileManagerFactory $fileManagerFactory
* @param ConfigFactory $requireJsConfigFactory
* @param ResolverInterfaceFactory $localeFactory
*/
public function __construct(
ListInterface $themeList,
DesignInterfaceFactory $designFactory,
RepositoryFactory $assetRepoFactory,
FileManagerFactory $fileManagerFactory,
ConfigFactory $requireJsConfigFactory,
ResolverInterfaceFactory $localeFactory
) {
$this->themeList = $themeList;
$this->designFactory = $designFactory;
$this->assetRepoFactory = $assetRepoFactory;
$this->fileManagerFactory = $fileManagerFactory;
$this->requireJsConfigFactory = $requireJsConfigFactory;
$this->localeFactory = $localeFactory;
}
/**
* @param string $areaCode
* @param string $themePath
* @param string $localeCode
* @return bool true on success
*/
public function deploy($areaCode, $themePath, $localeCode)
{
/** @var \Magento\Framework\View\Design\ThemeInterface $theme */
$theme = $this->themeList->getThemeByFullPath($areaCode . '/' . $themePath);
/** @var \Magento\Theme\Model\View\Design $design */
$design = $this->designFactory->create()->setDesignTheme($theme, $areaCode);
/** @var ResolverInterface $locale */
$locale = $this->localeFactory->create();
$locale->setLocale($localeCode);
$design->setLocale($locale);
$assetRepo = $this->assetRepoFactory->create(['design' => $design]);
/** @var \Magento\RequireJs\Model\FileManager $fileManager */
$fileManager = $this->fileManagerFactory->create(
[
'config' => $this->requireJsConfigFactory->create(
[
'assetRepo' => $assetRepo,
'design' => $design,
]
),
'assetRepo' => $assetRepo,
]
);
$fileManager->createRequireJsConfigAsset();
$fileManager->createMinResolverAsset();
return true;
}
}