-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulp.js
55 lines (45 loc) · 1.34 KB
/
gulp.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
const gulp = require('gulp');
const gulpIf = require('gulp-if');
const through2 = require('through2');
const debug = require('gulp-debug');
const emitty = require('@emitty/core').configure();
emitty.language({
extensions: ['.pug'],
parser: require('@emitty/language-pug').parse
});
const state = {
isWatchMode: false,
// Changed files are written by the name of the task that will process them.
// This is necessary to support more than one language in @emitty.
watch: {
templates: undefined
}
};
function getFilter(taskName) {
return through2.obj(function (file, _encoding, callback) {
emitty.filter(file.path, state.watch[taskName]).then((result) => {
if (result) {
this.push(file);
}
callback();
});
});
}
gulp.task('templates', () =>
gulp.src('./fixtures/*.pug')
.pipe(gulpIf(state.isWatchMode, getFilter('templates'))) // Enables filtering only in watch mode
.pipe(debug()) // Simulates compilation
);
gulp.task('watch:templates', () =>
gulp.watch('./fixtures/**/*.pug', gulp.series('templates'))
.on('all', (event, changed) => {
// Logs the changed file for the templates task
state.watch.templates = changed;
})
);
gulp.task('watch:init', (done) => {
// Enables the watch mode for conditions
state.isWatchMode = true;
done();
});
gulp.task('watch', gulp.series('watch:init', 'templates', 'watch:templates'));