json.js 462 B

123456789101112
  1. const gutil = require('gulp-util');
  2. const through = require('through2');
  3. module.exports = function (handle) {
  4. return through.obj(function (file, enc, cb) {
  5. if (file.isNull()) return cb();
  6. if (file.isStream()) return this.emit('error', new gutil.PluginError('VM-json', 'Stream is not supported.'));
  7. handle = handle || (i => i);
  8. file.contents = new Buffer(JSON.stringify(handle(JSON.parse(String(file.contents)))));
  9. cb(null, file);
  10. });
  11. };