-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
35 lines (33 loc) · 1.04 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
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
const PluginError = require('plugin-error');
const theo = require('theo');
const through = require('through2');
module.exports = function(options) {
return through.obj(function(file, enc, callback) {
if (file.isStream()) {
const err = this.emit(
'error',
new PluginError('gulp-theo', 'Streaming not supported')
);
return callback(err);
}
const opts = Object.assign({}, options, {
transform: Object.assign({}, options.transform, {
file: file.path,
data: file.contents.toString('utf8')
})
});
theo
.convert(opts)
.then(res => {
file.path = file.path.replace(/(json|yml)$/, options.format.type);
file.contents = Buffer.from(res);
callback(null, file);
})
.catch(e => {
const err = new PluginError('gulp-theo', e, { trace: true });
callback(err, file);
});
});
};