-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (34 loc) · 1.12 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
var gutil = require('gulp-util');
var through = require('through2');
var spritesPreprocessor = require('sprites-preprocessor');
var File = require('vinyl');
var extend = require('node.extend');
var path = require('path');
var defaultOptions = {
name: 'sprite.png'
};
var plugin = function(options) {
options = extend(true, {}, defaultOptions, options);
var stream = through.obj(function(file, enc, callback) {
if (file.isNull()) {
stream.push(file);
return callback();
}
if (file.isStream()) {
stream.emit('error', new gutil.PluginError('gulp-sprites-preprocessor', 'Streaming not supported'));
return callback();
}
spritesPreprocessor(options, file.contents.toString(), function(err, css, image) {
if (err) { return stream.emit('error', new gutil.PluginError('gulp-sprites-preprocessor', err)); }
file.contents = new Buffer(css, 'utf-8');
stream.push(file);
stream.push(new File({
path: path.basename(options.name),
contents: new Buffer(image, 'binary')
}));
callback();
});
});
return stream;
};
module.exports = plugin;