6
6
7
7
namespace Magento \Deploy \Model \Deploy ;
8
8
9
- use Magento \Deploy \Model \DeployManager ;
10
9
use Magento \Framework \App \Filesystem \DirectoryList ;
11
- use Magento \Framework \App \Utility \Files ;
12
10
use Magento \Framework \Filesystem ;
13
11
use Magento \Framework \Filesystem \Directory \WriteInterface ;
14
12
use Symfony \Component \Console \Output \OutputInterface ;
15
13
use Magento \Framework \Console \Cli ;
16
14
use Magento \Deploy \Console \Command \DeployStaticOptionsInterface as Options ;
17
- use \Magento \Framework \RequireJs \Config as RequireJsConfig ;
15
+ use Magento \Framework \RequireJs \Config as RequireJsConfig ;
16
+ use Magento \Framework \Translate \Js \Config as TranslationJsConfig ;
17
+ use Magento \Framework \App \ObjectManager ;
18
+ use Magento \Deploy \Model \DeployStrategyFactory ;
18
19
20
+ /**
21
+ * To avoid duplication of deploying of all static content per each theme/local, this class uses copying/symlinking
22
+ * of default static files to other locales, separately calls deploy for js dictionary per each locale
23
+ */
19
24
class LocaleQuickDeploy implements DeployInterface
20
25
{
21
26
/**
@@ -38,16 +43,42 @@ class LocaleQuickDeploy implements DeployInterface
38
43
*/
39
44
private $ options = [];
40
45
46
+ /**
47
+ * @var TranslationJsConfig
48
+ */
49
+ private $ translationJsConfig ;
50
+
51
+ /**
52
+ * @var DeployStrategyFactory
53
+ */
54
+ private $ deployStrategyFactory ;
55
+
56
+ /**
57
+ * @var DeployInterface[]
58
+ */
59
+ private $ deploys ;
60
+
41
61
/**
42
62
* @param Filesystem $filesystem
43
63
* @param OutputInterface $output
44
64
* @param array $options
65
+ * @param TranslationJsConfig $translationJsConfig
66
+ * @param DeployStrategyFactory $deployStrategyFactory
45
67
*/
46
- public function __construct (\Magento \Framework \Filesystem $ filesystem , OutputInterface $ output , $ options = [])
47
- {
68
+ public function __construct (
69
+ Filesystem $ filesystem ,
70
+ OutputInterface $ output ,
71
+ $ options = [],
72
+ TranslationJsConfig $ translationJsConfig = null ,
73
+ DeployStrategyFactory $ deployStrategyFactory = null
74
+ ) {
48
75
$ this ->filesystem = $ filesystem ;
49
76
$ this ->output = $ output ;
50
77
$ this ->options = $ options ;
78
+ $ this ->translationJsConfig = $ translationJsConfig
79
+ ?: ObjectManager::getInstance ()->get (TranslationJsConfig::class);
80
+ $ this ->deployStrategyFactory = $ deployStrategyFactory
81
+ ?: ObjectManager::getInstance ()->get (DeployStrategyFactory::class);
51
82
}
52
83
53
84
/**
@@ -67,13 +98,13 @@ private function getStaticDirectory()
67
98
*/
68
99
public function deploy ($ area , $ themePath , $ locale )
69
100
{
70
- if (isset ($ this ->options [Options::DRY_RUN ]) && $ this -> options [Options:: DRY_RUN ] ) {
101
+ if (! empty ($ this ->options [Options::DRY_RUN ])) {
71
102
return Cli::RETURN_SUCCESS ;
72
103
}
73
104
74
105
$ this ->output ->writeln ("=== {$ area } -> {$ themePath } -> {$ locale } === " );
75
106
76
- if (! isset ($ this ->options [self ::DEPLOY_BASE_LOCALE ])) {
107
+ if (empty ($ this ->options [self ::DEPLOY_BASE_LOCALE ])) {
77
108
throw new \InvalidArgumentException ('Deploy base locale must be set for Quick Deploy ' );
78
109
}
79
110
$ processedFiles = 0 ;
@@ -88,7 +119,7 @@ public function deploy($area, $themePath, $locale)
88
119
$ this ->deleteLocaleResource ($ newLocalePath );
89
120
$ this ->deleteLocaleResource ($ newRequireJsPath );
90
121
91
- if (isset ($ this ->options [Options::SYMLINK_LOCALE ]) && $ this -> options [Options:: SYMLINK_LOCALE ] ) {
122
+ if (! empty ($ this ->options [Options::SYMLINK_LOCALE ])) {
92
123
$ this ->getStaticDirectory ()->createSymlink ($ baseLocalePath , $ newLocalePath );
93
124
$ this ->getStaticDirectory ()->createSymlink ($ baseRequireJsPath , $ newRequireJsPath );
94
125
@@ -98,20 +129,61 @@ public function deploy($area, $themePath, $locale)
98
129
$ this ->getStaticDirectory ()->readRecursively ($ baseLocalePath ),
99
130
$ this ->getStaticDirectory ()->readRecursively ($ baseRequireJsPath )
100
131
);
132
+ $ jsDictionaryEnabled = $ this ->translationJsConfig ->dictionaryEnabled ();
101
133
foreach ($ localeFiles as $ path ) {
102
134
if ($ this ->getStaticDirectory ()->isFile ($ path )) {
103
- $ destination = $ this ->replaceLocaleInPath ($ path , $ baseLocale , $ locale );
104
- $ this ->getStaticDirectory ()->copyFile ($ path , $ destination );
105
- $ processedFiles ++;
135
+ if (!$ jsDictionaryEnabled || !$ this ->isJsDictionary ($ path )) {
136
+ $ destination = $ this ->replaceLocaleInPath ($ path , $ baseLocale , $ locale );
137
+ $ this ->getStaticDirectory ()->copyFile ($ path , $ destination );
138
+ $ processedFiles ++;
139
+ }
106
140
}
107
141
}
108
142
143
+ if ($ jsDictionaryEnabled ) {
144
+ $ this ->getDeploy (
145
+ DeployStrategyFactory::DEPLOY_STRATEGY_JS_DICTIONARY ,
146
+ [
147
+ 'output ' => $ this ->output ,
148
+ 'translationJsConfig ' => $ this ->translationJsConfig
149
+ ]
150
+ )
151
+ ->deploy ($ area , $ themePath , $ locale );
152
+ $ processedFiles ++;
153
+ }
154
+
109
155
$ this ->output ->writeln ("\nSuccessful copied: {$ processedFiles } files; errors: {$ errorAmount }\n--- \n" );
110
156
}
111
157
112
158
return Cli::RETURN_SUCCESS ;
113
159
}
114
160
161
+ /**
162
+ * Get deploy strategy according to required strategy
163
+ *
164
+ * @param string $strategy
165
+ * @param array $params
166
+ * @return DeployInterface
167
+ */
168
+ private function getDeploy ($ strategy , $ params )
169
+ {
170
+ if (empty ($ this ->deploys [$ strategy ])) {
171
+ $ this ->deploys [$ strategy ] = $ this ->deployStrategyFactory ->create ($ strategy , $ params );
172
+ }
173
+ return $ this ->deploys [$ strategy ];
174
+ }
175
+
176
+ /**
177
+ * Define if provided path is js dictionary
178
+ *
179
+ * @param string $path
180
+ * @return bool
181
+ */
182
+ private function isJsDictionary ($ path )
183
+ {
184
+ return strpos ($ path , $ this ->translationJsConfig ->getDictionaryFileName ()) !== false ;
185
+ }
186
+
115
187
/**
116
188
* @param string $path
117
189
* @return void
0 commit comments