-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
40 lines (32 loc) · 941 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
36
37
38
39
40
'use strict';
const PluginError = require('plugin-error');
const through = require('through2');
const po2json = require('po2json');
const path = require('path');
const pluginName = 'gulp-po2json';
module.exports = function (config) {
config = Object.assign({
stringify: true
}, config);
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
this.push(file);
return cb();
}
if (file.isStream()) {
this.emit('error', new PluginError(pluginName, 'Streaming not supported'));
return cb();
}
try {
file.contents = Buffer.from(po2json.parse(file.contents, config));
} catch (err) {
this.emit('error', new PluginError(pluginName, err));
return cb();
}
const dirname = path.dirname(file.path);
const basename = path.basename(file.path, '.po');
file.path = path.join(dirname, basename + '.json');
this.push(file);
cb();
});
};