-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (25 loc) · 797 Bytes
/
index.js
File metadata and controls
35 lines (25 loc) · 797 Bytes
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
var through = require('through2');
var path = require('path');
var gutil = require('gulp-util');
var utf8 = require('utf8');
var Jsonnet = require('jsonnet');
var jsonnet = new Jsonnet();
var PluginError = gutil.PluginError;
module.exports = function () {
function transform(file, enc, cb) {
if (file.isNull()) return cb(null, file);
if (file.isStream()) return cb(new PluginError('gulp-jsonnet', 'Streaming not supported'));
var dest = gutil.replaceExtension(file.path, '.json');
var code = file.contents;
var result;
try {
result = jsonnet.eval(code);
} catch(ex) {
return cb(new PluginError('gulp-jsonnet', ex));
}
file.path = dest;
file.contents = new Buffer(utf8.decode(JSON.stringify(result)));
cb(null, file);
}
return through.obj(transform);
};