Skip to content

Commit fa072ac

Browse files
added clean static files cache task
1 parent 66bd007 commit fa072ac

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

gulpfile.js

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
/*
55
* 1. Copy gulpfile and package.json in to the root directory
66
* 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"
88
(If you alrady instaled Grunt please remove node_module directory)
99
*/
10-
10+
1111
/* ==========================================================================
1212
How to use
13-
========================================================================== */
13+
========================================================================== */
1414
/*
1515
* 1. Run : php bin\magento dev:source-theme:deploy --locale="en_AU" --area="Frontend" --theme="Netstarter/YOURTHEMENAME"
1616
* 2. Run : php bin\magento setup:static-content:deploy en_AU
@@ -21,9 +21,10 @@
2121
* 3.d. Compilation of certain theme with minification (+~2.5s): gulp less --luma --min<br/>
2222
* 3.e. Compilation of certain theme with sourcemap(+~1.5s), can't be used with minification: gulp less --luma --map<br/>
2323
* 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/>
2525
* 4. For using liveReload install extension for your browser: http://livereload.com/
2626
* 5. For clear the magento cache: gulp cache-flush
27+
* 6. For clear the magento static files cache: gulp clean --luma
2728
<br/>4.a. Turn on the extension on the page of project.
2829
*/
2930

@@ -81,24 +82,24 @@ var lessFiles = [];
8182
* Get all themes, create paths for less files and push them to the Array.
8283
*/
8384
if (!themeName) {
84-
for (i in themesConfig) {
85+
for (var i in themesConfig) {
8586
// Create path
8687
var path = './pub/static/' + themesConfig[i].area + '/' + themesConfig[i].name + '/' + themesConfig[i].locale + '/';
8788

8889
// Push names of less files to the Array
89-
for (j in themesConfig[i].files) {
90+
for (var j in themesConfig[i].files) {
9091
lessFiles.push(path + themesConfig[i].files[j] + '.' + themesConfig[i].dsl);
9192
}
9293
}
9394
}
9495

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.
9697
else {
9798
// Create path
9899
var path = './pub/static/' + themesConfig[themeName].area + '/' + themesConfig[themeName].name + '/' + themesConfig[themeName].locale + '/';
99100

100101
// Push names of less files to the Array
101-
for (i in themesConfig[themeName].files) {
102+
for (var i in themesConfig[themeName].files) {
102103
lessFiles.push(path + themesConfig[themeName].files[i] + '.' + themesConfig[themeName].dsl)
103104
}
104105
}
@@ -116,13 +117,13 @@ gulp.task('less', function() {
116117
console.log('\x1b[32m', '====================================' ,'\x1b[0m');
117118
console.log('Running \x1b[36mLess\x1b[0m compilation for \x1b[36m' + lessFiles.length + ' files:\x1b[0m');
118119

119-
for (i in lessFiles) {
120+
for (var i in lessFiles) {
120121
console.log('\x1b[32m',lessFiles[i],'\x1b[0m');
121122
}
122123

123124
// Get Array with files
124125
return gulp.src(lessFiles)
125-
126+
126127
// Source map
127128
.pipe(gulpif(sourceMapArg >= 0, sourcemaps.init()))
128129

@@ -133,14 +134,14 @@ gulp.task('less', function() {
133134

134135
// Minify css
135136
.pipe(gulpif(minCssArg >= 0, cssmin()))
136-
137+
137138
.pipe(gulpif(sourceMapArg >= 0, sourcemaps.write('.')))
138-
139+
139140
// Destination folder
140141
.pipe(gulp.dest( path + 'css/'))
141142

142143
// Live reload
143-
.pipe(gulpif(liveReload >= 0, livereload()))
144+
.pipe(gulpif(liveReload >= 0, livereload()));
144145
});
145146

146147
// Watcher task
@@ -172,7 +173,7 @@ gulp.task('exec', function (cb) {
172173
else {
173174
console.log('Please add your defined Theme ex: --luma'.red);
174175
}
175-
})
176+
});
176177

177178
// Static content deploy task
178179
gulp.task('deploy', function (cb) {
@@ -183,18 +184,34 @@ gulp.task('deploy', function (cb) {
183184
cb(err);
184185
});
185186
}
186-
187+
187188
else {
188189
console.log('Please add your defined Theme ex: --luma'.red);
189190
}
190-
})
191-
191+
});
192192

193-
// cache flush task
193+
// Cache flush task
194194
gulp.task('cache-flush', function (cb) {
195195
exec('php bin/magento cache:flush', function (err, stdout, stderr) {
196196
console.log(stdout);
197197
console.log(stderr);
198198
cb(err);
199199
});
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

Comments
 (0)