-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
99 lines (82 loc) · 2.39 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
const {series, watch, src, dest, parallel} = require('gulp');
const pump = require('pump');
// gulp plugins and utils
var livereload = require('gulp-livereload');
var less = require('gulp-less');
var zip = require('gulp-zip');
var uglify = require('gulp-uglify');
var beeper = require('beeper');
var LessAutoprefix = require('less-plugin-autoprefix');
var LessPluginCleanCSS = require('less-plugin-clean-css');
// postcss plugins
var autoprefix = new LessAutoprefix({ browsers: ['last 2 versions'] });
var cleanCSSPlugin = new LessPluginCleanCSS({advanced: true});
function serve(done) {
livereload.listen();
done();
}
const handleError = (done) => {
return function (err) {
if (err) {
beeper();
}
return done(err);
};
};
function hbs(done) {
pump([
src(['*.hbs', '**/**/*.hbs', '!node_modules/**/*.hbs']),
livereload()
], handleError(done));
}
function comp_less(done) {
var processors = [
autoprefix,
cleanCSSPlugin
];
pump([
src('assets/less/main.less', {sourcemaps: true}),
less({
plugins: processors
}),
dest('assets/built/', {sourcemaps: true}),
livereload()
], handleError(done));
}
function js(done) {
pump([
src('assets/js/**/!(*.min).js', {sourcemaps: true}),
uglify(),
dest('assets/built/', {sourcemaps: '.'}),
livereload()
], handleError(done));
}
function CopyMinAssets(done) {
pump([
src('assets/*/*.min.*'),
dest('assets/built/vendor/'),
], handleError(done));
}
function zipper(done) {
var targetDir = 'dist/';
var themeName = require('./package.json').name;
var filename = themeName + '.zip';
pump([
src([
'**',
'!node_modules', '!node_modules/**',
'!dist', '!dist/**'
]),
zip(filename),
dest(targetDir)
], handleError(done));
}
const lessWatcher = () => watch('assets/less/**', comp_less);
const hbsWatcher = () => watch(['*.hbs', '**/**/*.hbs', '!node_modules/**/*.hbs'], hbs);
const jsWatcher = () => watch(['assets/js/*.js', '!node_modules/**/*.js'], js);
const watcher = parallel(lessWatcher, hbsWatcher, jsWatcher);
const build = series(comp_less, CopyMinAssets, js);
const dev = series(build, serve, watcher);
exports.build = build;
exports.zip = series(build, zipper);
exports.default = dev;