forked from koding/gulp-kd-pistachio-compiler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
35 lines (25 loc) · 780 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
35
'use strict';
var through = require('through2');
var PistachioCompiler = require('kdf-pistachio/lib/file-compiler')
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
var PLUGIN_NAME = 'gulp-kdf-pistachio';
module.exports = function () {
return through.obj(function (file, enc, cb) {
if (file.isStream()) {
return cb(new PluginError( PLUGIN_NAME, 'Streaming not supported'));
}
if (file.isNull()){
return cb(null, file);
}
var contents;
try {
contents = PistachioCompiler.compile(file.contents.toString('utf8')).toString('utf8');
} catch (err) {
return cb(new PluginError(PLUGIN_NAME, err));
} finally {
file.contents = new Buffer(contents);
return cb(null, file);
}
});
};