gulp-propertext
Version:
Gulp plugin to parse propertext files
31 lines (26 loc) • 734 B
JavaScript
var Vinyl = require('vinyl')
var map = require('map-stream')
var parse = require('propertext')
module.exports = function (config = {}) {
return map(function (file, cb) {
try {
var v = new Vinyl(file)
if (v.isStream())
cb(new TypeError('Streaming files not supported'))
else if (v.isNull())
cb(new TypeError('Cannot parse null contents'))
else
ptext(v, cb)
} catch (err) {
cb(err)
}
})
function ptext (file, done) {
var { replacer, space, ...opts } = config
var props = parse(String(file.contents), opts)
var json = JSON.stringify(props, replacer, space)
file.contents = Buffer.from(json)
file.extname = '.json'
done(null, file)
}
}