<commit_before>'use strict';

const PluginError = require('plugin-error');
const through = require('through2');
const ejs = require('ejs');
const fs = require('fs');

module.exports = function (options) {
	return through.obj(function (file, enc, cb) {
		if (file.isNull()) {
	      next(null, file);
	      return;
	    }

		if (file.isStream()) {
			file.contents = file.contents.pipe(through(minify));
		} else {
			try {
				var data = JSON.parse(file.contents.toString());
	        	var str = fs.readFileSync(options.filename,'utf-8');
				file.contents = new Buffer(ejs.render(str, data, options));
				file.path = gutil.replaceExtension(file.path, ".html");
				this.push(file);
			} catch (err) {
				let opts = Object.assign({}, options, { fileName: file.path });
		        let error = new PluginError('gulp-ejs-json', err, opts);
		        if (next !== cb) {
		          next(error);
		          return;
		        }
		        cb(error);
			}

			cb();
		}
	});
};<commit_msg>fix bug<commit_after>'use strict';

const PluginError = require('plugin-error');
const through = require('through2');
const ejs = require('ejs');
const fs = require('fs');

module.exports = options => {
  return through.obj(function(file, enc, next) {
    if (file.isNull()) {
      next(null, file);
      return;
    }

    const convert = (buf, _, cb) => {
    	try {
				var data = JSON.parse(file.contents.toString());
	        	var str = fs.readFileSync(options.filename,'utf-8');
				file.contents = new Buffer(ejs.render(str, data, options));
				file.path = gutil.replaceExtension(file.path, ".html");
				this.push(file);
			} catch (err) {
				let opts = Object.assign({}, options, { fileName: file.path });
		        let error = new PluginError('gulp-ejs-json', err, opts);
		        if (next !== cb) {
		          next(error);
		          return;
		        }
		        cb(error);
			}
    };

    if (file.isStream()) {
      file.contents = file.contents.pipe(through(convert));
    } else {
      convert(file.contents, null, next);
    }
  });
};
{'fraction_non_alphanumeric': 0.1705767350928641, 'fraction_numerical': 0.0019550342130987292, 'mean_word_length': 2.6038732394366195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3556383', 'n_tokens_mistral': 731, 'n_tokens_neox': 647, 'n_words': 143}