<commit_before>'use strict'

/*--------- 1) Dependencies ---------*/

var fs = require('fs')
var path = require('path')
var program = require('commander')
var babel = require('babel-core')
var mkdirp = require('mkdirp').sync

/*--------- 2) Options ---------*/

program
  .option('--sourceMaps', 'enable source maps for generated files')
  .option('-c, --compact', 'do not include superfluous whitespace characters and line terminators')
  .option('-m, --minify', 'minifies generated source before writing files')
  .option('--comments', 'preserve comments from source files to generated files')
  .option('-R, --target <dir>', 'select directory in source to build (default: all)', null)
  .parse(process.argv)

var options = {
  babelrc: false,
  presets: [
    "es2015-node4",
    "stage-0"
  ],
  plugins: [
    ["transform-runtime", {
      "polyfill": true,
      "regenerator": false
    }]
  ],
  sourceMaps: !!program.sourceMaps ? "both" : false,
  compact: program.compact ? true : 'auto',
  minified: !!program.minify,
  comments: !!program.comments
}

/*--------- 3) Utils ---------*/

var __cwdname = process.cwd()

var resolve = path.join

var format = function ( filename ) {
  return filename.replace(__cwdname, '').slice(1)
}

function transform ( from, to ) {
  var source = fs.readFileSync(from, 'utf-8')
  options.filename = from
  source = babel.transform(source, options)
  mkdirp(path.dirname(to))
  fs.writeFileSync(to, source.code + '\n')
  if ( options.sourceMaps ) {
    fs.writeFileSync(to + '.map', source.map)
  }
  console.log(format(from) + ' -> ' + format(to))
}

/*--------- 4) Transpile... ---------*/

function transpile ( basename ) {
  var from = resolve(__cwdname, 'src', basename)
  var stat = fs.lstatSync(from)
  if ( stat.isDirectory() )
    fs.readdirSync(from)
      .forEach(function(item){
        transpile(resolve(basename, item))
      })
  else
    if ( path.extname(basename) === '.js' ) {
      transform(from, resolve(__cwdname, basename))
    }
}

if ( program.target && program.target !== 'all' && program.target !== '*' ) {

  transpile(program.target)

} else {

  transpile('benchmark')
  transpile('bin')
  transpile('lib')
  transpile('spec')

}<commit_msg>scripts/transpile: updated '-R, --target <dir>' usage<commit_after>'use strict'

/*--------- 1) Dependencies ---------*/

var fs = require('fs')
var path = require('path')
var program = require('commander')
var babel = require('babel-core')
var mkdirp = require('mkdirp').sync

/*--------- 2) Options ---------*/

program
  .option('--sourceMaps', 'enable source maps for generated files')
  .option('-c, --compact', 'do not include superfluous whitespace characters and line terminators')
  .option('-m, --minify', 'minifies generated source before writing files')
  .option('--comments', 'preserve comments from source files to generated files')
  .option('-R, --target <dir>', 'select directory in source to build (default: all)', 'all')
  .parse(process.argv)

var options = {
  babelrc: false,
  presets: [
    "es2015-node4",
    "stage-0"
  ],
  plugins: [
    ["transform-runtime", {
      "polyfill": true,
      "regenerator": false
    }]
  ],
  sourceMaps: !!program.sourceMaps ? "both" : false,
  compact: program.compact ? true : 'auto',
  minified: !!program.minify,
  comments: !!program.comments
}

/*--------- 3) Utils ---------*/

var __cwdname = process.cwd()

var resolve = path.join

var format = function ( filename ) {
  return filename.replace(__cwdname, '').slice(1)
}

function transform ( from, to ) {
  var source = fs.readFileSync(from, 'utf-8')
  options.filename = from
  source = babel.transform(source, options)
  mkdirp(path.dirname(to))
  fs.writeFileSync(to, source.code + '\n')
  if ( options.sourceMaps ) {
    fs.writeFileSync(to + '.map', source.map)
  }
  console.log(format(from) + ' -> ' + format(to))
}

/*--------- 4) Transpile... ---------*/

function transpile ( basename ) {
  var from = resolve(__cwdname, 'src', basename)
  var stat = fs.lstatSync(from)
  if ( stat.isDirectory() )
    fs.readdirSync(from)
      .forEach(function(item){
        transpile(resolve(basename, item))
      })
  else
    if ( path.extname(basename) === '.js' ) {
      transform(from, resolve(__cwdname, basename))
    }
}

var target = program.target

if ( target && target !== 'all' ) {

  if ( target.indexOf(',') !== -1 )
    target.split(",").map(function(s){ return s.trim() }).forEach(transpile)
  else
    transpile(target)

} else {

  transpile('benchmark')
  transpile('bin')
  transpile('lib')
  transpile('spec')

}
{'fraction_non_alphanumeric': 0.19558566433566432, 'fraction_numerical': 0.005463286713286713, 'mean_word_length': 3.1123090745732256, 'pattern_counts': {'":': 4, '<': 6, '<?xml version=': 0, '>': 8, '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': '6774186', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1493, 'n_words': 357}