-
Notifications
You must be signed in to change notification settings - Fork 13
/
gulpfile.js
105 lines (83 loc) · 2.81 KB
/
gulpfile.js
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
var gulp = require('gulp'),
less = require('gulp-less'),
gutil = require('gulp-util'),
chalk = require('chalk'),
clean = require('gulp-clean'),
run = require('gulp-run'),
sourcemap = require('gulp-sourcemaps'),
themesConfig = require('./dev/tools/gulp/themes');
var options = ((process.argv.slice(2))[1]).substring(2);
/**
* Watch task
*/
gulp.task('watch',
function() {
var theme = themesConfig[options];
theme.src.forEach(function(module) {
gulp.watch([ module + '/**/*.less'], ['css']);
});
});
/**
* Less Compile Task.
*/
gulp.task('css', function() {
var theme = themesConfig[options],
filesToCompile = [];
theme.files.forEach(function(file) {
filesToCompile.push(
theme.dest + '/' + theme.locale[0] + '/' + file + '.' + theme.lang
);
});
theme.locale.forEach(function(locale) {
return gulp
.src(filesToCompile)
.pipe(sourcemap.init())
.pipe(less().on('error', function (error) {
gutil.log(chalk.red('Error compiling ' + locale + error.message));
}))
.pipe(sourcemap.write())
.pipe(gulp.dest(theme.dest + '/' + locale + '/css'))
.pipe(gutil.buffer(function() {
gutil.log(chalk.green('Successfully compiled ' + locale ));
}));
});
});
/**
* Clean Task.
*/
gulp.task('clean', function() {
var theme = themesConfig[options],
createAlias = 'bin/magento dev:source-theme:deploy --theme ' + theme.vendor + '/'+ theme.name + ' --locale ' + theme.locale[0],
staticAssetDeploy = 'bin/magento setup:static-content:deploy',
staticFolder = 'pub/static/' + theme.area + '/' + theme.vendor + '/' + theme.name;
var folderToClean = [
'./' + staticFolder + '/*',
'./var/view_preprocessed/*'
];
return gulp.src(folderToClean, {read: false})
.pipe(clean())
.pipe(gutil.buffer(function() {
gutil.log(chalk.green('Clean ' + staticFolder));
gutil.log(chalk.green('Clean preprocessed files'));
}))
.pipe(run(createAlias))
.pipe(gutil.buffer(function() {
gutil.log(chalk.green('Asset static deployment is starting. Wait...'));
}))
.pipe(run(staticAssetDeploy))
.pipe(gutil.buffer(function() {
gutil.log(chalk.green('Finished! now run "gulp watch --[your theme name]"'));
}));
});
gulp.task('clean-cache', function() {
var folderToClean = [
'./var/page_cache/*',
'./var/cache/*'
];
return gulp.src(folderToClean, {read: false})
.pipe(clean())
.pipe(gutil.buffer(function() {
gutil.log(chalk.green('Cache cleaned'));
}))
});
gulp.task('default', ['watch']);