-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (28 loc) · 925 Bytes
/
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
'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var assign = require('object-assign');
var customProps = require('custom-props');
module.exports = function (opts) {
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-custom-props', 'Streaming not supported'));
return;
}
var options = assign({}, opts);
var filePath = file.path;
try {
options.name = typeof options.name === 'function' && options.name(file) || file.relative;
file.contents = new Buffer(customProps(file.contents.toString(), options));
file.path = gutil.replaceExtension(file.path, '.css');
this.push(file);
} catch (err) {
this.emit('error', new gutil.PluginError('gulp-nunjucks', err, {fileName: filePath}));
}
cb();
});
};