4
4
/*
5
5
* 1. Copy gulpfile and package.json in to the root directory
6
6
* 2. Install node.js for your OS: https://nodejs.org/en/
7
- * 3. Install modules: run a command in a root directory of your project "npm install"
7
+ * 3. Install modules: run a command in a root directory of your project "npm install"
8
8
(If you alrady instaled Grunt please remove node_module directory)
9
9
*/
10
-
10
+
11
11
/* ==========================================================================
12
12
How to use
13
- ========================================================================== */
13
+ ========================================================================== */
14
14
/*
15
15
* 1. Run : php bin\magento dev:source-theme:deploy --locale="en_AU" --area="Frontend" --theme="Netstarter/YOURTHEMENAME"
16
16
* 2. Run : php bin\magento setup:static-content:deploy en_AU
21
21
* 3.d. Compilation of certain theme with minification (+~2.5s): gulp less --luma --min<br/>
22
22
* 3.e. Compilation of certain theme with sourcemap(+~1.5s), can't be used with minification: gulp less --luma --map<br/>
23
23
* 3.f. Compilation with live reload: gulp less --luma --live<br/>
24
- * 3.g. Watcher with liveReload: gulp watch --luma --live<br/>
24
+ * 3.g. Watcher with liveReload: gulp watch --luma --live<br/>
25
25
* 4. For using liveReload install extension for your browser: http://livereload.com/
26
26
* 5. For clear the magento cache: gulp cache-flush
27
+ * 6. For clear the magento static files cache: gulp clean --luma
27
28
<br/>4.a. Turn on the extension on the page of project.
28
29
*/
29
30
@@ -81,24 +82,24 @@ var lessFiles = [];
81
82
* Get all themes, create paths for less files and push them to the Array.
82
83
*/
83
84
if ( ! themeName ) {
84
- for ( i in themesConfig ) {
85
+ for ( var i in themesConfig ) {
85
86
// Create path
86
87
var path = './pub/static/' + themesConfig [ i ] . area + '/' + themesConfig [ i ] . name + '/' + themesConfig [ i ] . locale + '/' ;
87
88
88
89
// Push names of less files to the Array
89
- for ( j in themesConfig [ i ] . files ) {
90
+ for ( var j in themesConfig [ i ] . files ) {
90
91
lessFiles . push ( path + themesConfig [ i ] . files [ j ] + '.' + themesConfig [ i ] . dsl ) ;
91
92
}
92
93
}
93
94
}
94
95
95
- // Get certain theme, create paths for less files and push them to the Array.
96
+ // Get certain theme, create paths for less files and push them to the Array.
96
97
else {
97
98
// Create path
98
99
var path = './pub/static/' + themesConfig [ themeName ] . area + '/' + themesConfig [ themeName ] . name + '/' + themesConfig [ themeName ] . locale + '/' ;
99
100
100
101
// Push names of less files to the Array
101
- for ( i in themesConfig [ themeName ] . files ) {
102
+ for ( var i in themesConfig [ themeName ] . files ) {
102
103
lessFiles . push ( path + themesConfig [ themeName ] . files [ i ] + '.' + themesConfig [ themeName ] . dsl )
103
104
}
104
105
}
@@ -116,13 +117,13 @@ gulp.task('less', function() {
116
117
console . log ( '\x1b[32m' , '====================================' , '\x1b[0m' ) ;
117
118
console . log ( 'Running \x1b[36mLess\x1b[0m compilation for \x1b[36m' + lessFiles . length + ' files:\x1b[0m' ) ;
118
119
119
- for ( i in lessFiles ) {
120
+ for ( var i in lessFiles ) {
120
121
console . log ( '\x1b[32m' , lessFiles [ i ] , '\x1b[0m' ) ;
121
122
}
122
123
123
124
// Get Array with files
124
125
return gulp . src ( lessFiles )
125
-
126
+
126
127
// Source map
127
128
. pipe ( gulpif ( sourceMapArg >= 0 , sourcemaps . init ( ) ) )
128
129
@@ -133,14 +134,14 @@ gulp.task('less', function() {
133
134
134
135
// Minify css
135
136
. pipe ( gulpif ( minCssArg >= 0 , cssmin ( ) ) )
136
-
137
+
137
138
. pipe ( gulpif ( sourceMapArg >= 0 , sourcemaps . write ( '.' ) ) )
138
-
139
+
139
140
// Destination folder
140
141
. pipe ( gulp . dest ( path + 'css/' ) )
141
142
142
143
// Live reload
143
- . pipe ( gulpif ( liveReload >= 0 , livereload ( ) ) )
144
+ . pipe ( gulpif ( liveReload >= 0 , livereload ( ) ) ) ;
144
145
} ) ;
145
146
146
147
// Watcher task
@@ -172,7 +173,7 @@ gulp.task('exec', function (cb) {
172
173
else {
173
174
console . log ( 'Please add your defined Theme ex: --luma' . red ) ;
174
175
}
175
- } )
176
+ } ) ;
176
177
177
178
// Static content deploy task
178
179
gulp . task ( 'deploy' , function ( cb ) {
@@ -183,18 +184,34 @@ gulp.task('deploy', function (cb) {
183
184
cb ( err ) ;
184
185
} ) ;
185
186
}
186
-
187
+
187
188
else {
188
189
console . log ( 'Please add your defined Theme ex: --luma' . red ) ;
189
190
}
190
- } )
191
-
191
+ } ) ;
192
192
193
- // cache flush task
193
+ // Cache flush task
194
194
gulp . task ( 'cache-flush' , function ( cb ) {
195
195
exec ( 'php bin/magento cache:flush' , function ( err , stdout , stderr ) {
196
196
console . log ( stdout ) ;
197
197
console . log ( stderr ) ;
198
198
cb ( err ) ;
199
199
} ) ;
200
- } )
200
+ } ) ;
201
+
202
+ // Clean static files cache
203
+ gulp . task ( 'clean' , function ( cb ) {
204
+ if ( themeName ) {
205
+ exec ( 'rm -rf var/cache var/view_preprocessed pub/static/' + themesConfig [ themeName ] . area + '/' +
206
+ themesConfig [ themeName ] . name + '/' ,
207
+ function ( err , stdout , stderr ) {
208
+ console . log ( stdout ) ;
209
+ console . log ( stderr ) ;
210
+ cb ( err ) ;
211
+ } ) ;
212
+ }
213
+
214
+ else {
215
+ console . log ( 'Please add your defined Theme ex: --luma' . red ) ;
216
+ }
217
+ } ) ;
0 commit comments