forked from fatso83/gulp-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (39 loc) · 1.03 KB
/
index.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
var kit = require('node-kit');
var through2 = require('through2');
var replaceExt = require('replace-ext');
var PluginError = require('plugin-error');
var path = require('path');
var partialPrefix = '_';
function isPartial(filepath) {
return path.basename(filepath)[0] === partialPrefix;
}
module.exports = function (options) {
options = options || {};
function transform(file, enc, next) {
var self = this;
if (file.isNull()) {
this.push(file); // pass along
return next();
}
if (isPartial(file.path) && !options.compilePartials) {
return next();
}
if (file.isStream()) {
this.emit(
'error',
new PluginError('gulp-kit', 'Streaming not supported')
);
return next();
}
try {
var html = kit(file.path);
file.contents = new Buffer(html);
file.path = replaceExt(file.path, '.html');
self.push(file);
} catch (e) {
self.emit('error', new PluginError('gulp-kit', e));
}
next();
}
return through2.obj(transform);
};