<commit_before>var fs = require('fs');
var path = require('path');
var assign = require('object-assign');
var browserify = require('browserify');
var babelify = require('babelify');
var glob = require('glob');
var isUrl = require('is-url');
var mkdirp = require('mkdirp');
var mustache = require('mustache');

var TEMPLATE_PATH = path.resolve(__dirname, './fixtures/index.html.mustache');
var SRC_PATHS = [path.resolve(__dirname, '../dist/_sg.css'), path.resolve(__dirname, '../dist/_sg.js')];

/**
 * @param {string} dir
 * @returns {string}
 */
function getRealDir(dir) {
  return path.resolve(process.cwd(), dir.replace(/\/+$/, ''));
}

/**
 * @param {string} root
 * @returns {string}
 */
function normalizeRootPath(root) {
  return path.normalize('/' + root.replace(/\/+$/, ''));
}

/**
 * @param {string} file
 * @returns {Object}
 */
function readFile(file) {
  file = process.cwd() + '/' + file;
  return fs.existsSync(file) && JSON.parse(fs.readFileSync(file, 'utf8'));
}

/**
 * @param {string[]} files
 * @param {string} ext
 * @returns {string[]}
 */
function extractFiles(files, ext) {
  return files
    .filter(function(file) { return path.extname(file) === ext; })
    .map(function(file) { return isUrl(file) ? file : 'src/' + path.basename(file); });
}

/**
 * @param {Object} opts
 * @param {glob} opts.input
 * @param {string=} opts.output
 * @param {string=} opts.title
 * @param {string=} opts.root
 * @param {boolean=} opts.pushstate
 * @param {string[]=} opts.files
 * @param {Object=} opts.babelConfig
 */
function RSG(opts) {
  opts.input = glob.sync(opts.input, { realpath: true });
  opts.output = getRealDir(opts.output || 'styleguide');
  opts.title = opts.title || 'Style Guide';
  opts.root = opts.root ? normalizeRootPath(opts.root) : null;
  opts.pushstate = !!opts.pushstate;
  opts.files = opts.files || null;
  opts.babelConfig = opts.babelConfig || readFile('.babelrc') || {};
  this.opts = opts;
}

/**
 * @param {string} input
 * @returns {promise}
 */
RSG.prototype.copy = function(input) {
  var outFile = this.opts.output + '/src/' + path.basename(input);
  var readStream = fs.createReadStream(input);
  var writeStream = fs.createWriteStream(outFile);

  return new Promise(function(resolve, reject) {
    readStream.on('error', reject);

    writeStream
      .on('error', reject)
      .on('open', function() { readStream.pipe(writeStream); })
      .once('finish', function() { resolve(); });
  });
};

/**
 * @returns {promise}
 */
RSG.prototype.copyFiles = function() {
  var copy = this.copy.bind(this);
  var input = SRC_PATHS<commit_msg>optimize babel config<commit_after>var fs = require('fs');
var path = require('path');
var assign = require('object-assign');
var browserify = require('browserify');
var babelify = require('babelify');
var glob = require('glob');
var isUrl = require('is-url');
var mkdirp = require('mkdirp');
var mustache = require('mustache');

var TEMPLATE_PATH = path.resolve(__dirname, './fixtures/index.html.mustache');
var SRC_PATHS = [path.resolve(__dirname, '../dist/_sg.css'), path.resolve(__dirname, '../dist/_sg.js')];

/**
 * @param {string} dir
 * @returns {string}
 */
function getRealDir(dir) {
  return path.resolve(process.cwd(), dir.replace(/\/+$/, ''));
}

/**
 * @param {string} root
 * @returns {string}
 */
function normalizeRootPath(root) {
  return path.normalize('/' + root.replace(/\/+$/, ''));
}

/**
 * @param {string} file
 * @returns {Object}
 */
function readFile(file) {
  file = process.cwd() + '/' + file;
  return fs.existsSync(file) && JSON.parse(fs.readFileSync(file, 'utf8'));
}

/**
 * @param {string[]} files
 * @param {string} ext
 * @returns {string[]}
 */
function extractFiles(files, ext) {
  return files
    .filter(function(file) { return path.extname(file) === ext; })
    .map(function(file) { return isUrl(file) ? file : 'src/' + path.basename(file); });
}

/**
 * @param {Object} opts
 * @param {glob} opts.input
 * @param {string=} opts.output
 * @param {string=} opts.title
 * @param {string=} opts.root
 * @param {boolean=} opts.pushstate
 * @param {string[]=} opts.files
 * @param {Object=} opts.babelConfig
 */
function RSG(opts) {
  opts.input = glob.sync(opts.input, { realpath: true });
  opts.output = getRealDir(opts.output || 'styleguide');
  opts.title = opts.title || 'Style Guide';
  opts.root = opts.root ? normalizeRootPath(opts.root) : null;
  opts.pushstate = !!opts.pushstate;
  opts.files = opts.files || null;
  opts.babelConfig = opts.babelConfig || {};
  this.opts = opts;
}

/**
 * @param {string} input
 * @returns {promise}
 */
RSG.prototype.copy = function(input) {
  var outFile = this.opts.output + '/src/' + path.basename(input);
  var readStream = fs.createReadStream(input);
  var writeStream = fs.createWriteStream(outFile);

  return new Promise(function(resolve, reject) {
    readStream.on('error', reject);

    writeStream
      .on('error', reject)
      .on('open', function() { readStream.pipe(writeStream); })
      .once('finish', function() { resolve(); });
  });
};

/**
 * @returns {promise}
 */
RSG.prototype.copyFiles = function() {
  var copy = this.copy.bind(this);
  var input = SRC_PATHS
{'fraction_non_alphanumeric': 0.197714949651433, 'fraction_numerical': 0.0003872966692486445, 'mean_word_length': 4.103754940711463, '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': '1713312', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1735, 'n_words': 376}