<commit_before>'use strict';

var bemxjst = require('bem-xjst');
var fs = require('fs');
var gutil = require('gulp-util');
var path = require('path');
var through = require('through2');

var PluginError = gutil.PluginError;

var pluginName = path.basename(__dirname);

/**
 * bemhtml templates compiler.
 * @return {stream}
 */
module.exports = function (options) {
  var syntax = fs.readFileSync(path.resolve('./syntax/i-bem.bemhtml'), {encoding: 'utf8'});

  return through.obj(function (file, encoding, callback) {
    if (file.isNull()) {
      return callback(null, file);
    }

    if (file.isStream()) {
      return callback(new PluginError(pluginName, 'Streaming not supported'));
    }

    var bemhtml;

    try {
      bemhtml = bemxjst.generate(syntax + file.contents.toString(), options);
    } catch (err) {
      return callback(new PluginError(pluginName, err, {
        fileName: file.path
      }));
    }

    file.contents = new Buffer(bemhtml);
    file.path = gutil.replaceExtension(file.path, '.bemhtml.js');

    callback(null, file);
  });
};<commit_msg>async file reading<commit_after>'use strict';

var bemxjst = require('bem-xjst');
var fs = require('fs');
var gutil = require('gulp-util');
var path = require('path');
var through = require('through2');

var PluginError = gutil.PluginError;

var pluginName = path.basename(__dirname);
var syntaxPath = path.resolve('./syntax/i-bem.bemhtml');

/**
 * bemhtml templates compiler.
 * @param {object} options
 * @param {boolean} options.cache
 * @param {string} options.exportName
 * @param {boolean} options.no-opt
 * @param {boolean} options.optimize
 * @param {boolean} options.wrap
 * @return {stream}
 */
module.exports = function (options) {
  return through.obj(function (file, encoding, callback) {
    if (file.isNull()) {
      return callback(null, file);
    }

    if (file.isStream()) {
      return callback(new PluginError(pluginName, 'Streaming not supported'));
    }

    fs.readFile(syntaxPath, {encoding: 'utf8'}, function (err, syntax) {
      if (err) {
        return callback(new PluginError(pluginName, 'Syntax file not found', {
          fileName: syntaxPath
        }));
      }

      var code;

      try {
        code = bemxjst.generate(syntax + file.contents.toString(), options);
      } catch (e) {
        err = e;
      }

      if (err) {
        return callback(new PluginError(pluginName, err, {
          fileName: file.path
        }));
      }

      file.contents = code;
      file.path = gutil.replaceExtension(file.path, '.bemhtml.js');

      callback(null, file);
    });
  });
};
{'fraction_non_alphanumeric': 0.15304948216340622, 'fraction_numerical': 0.0015343306482546988, 'mean_word_length': 3.1728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2662517', 'n_tokens_mistral': 828, 'n_tokens_neox': 809, 'n_words': 192}