<commit_before>#!/usr/bin/env node
//
// Use in CLI:
//
//   Type "riot" for help.
//
// Use in Node:
//
//   var riot = require('riot/compiler')
//   riot.make({ from: 'foo', to: 'bar', compact: true })
//   riot.watch({ from: 'foo.tag', to: 'bar.js' })
//

var ph = require('path'),
  sh = require('shelljs'),
  chokidar = require('chokidar'),
  chalk = require('chalk'),
  compiler = require('./compiler'),
  analyzer = require('./analyzer'),
  TEMP_FILE_NAME = /\/[^.~][^~/]+$/ // skip temporary files (created by editors), e.g. /.name.tag, /~name.tag, /name~.tag

var ext

function find(from) {
  return sh.find(from).filter(function(f) {
    return ext.test(f) && TEMP_FILE_NAME.test(f)
  })
}
function remap(from, to, base) {
  return from.map(function(from) {
    return ph.join(to, ph.relative(base, from).replace(ext, '.js'))
  })
}

var methods = {

  help: function() {
    log([
      '',
      'Builds .tag files to .js',
      '',
      'Options:',
      '',
      '  -h, --help      You\'re reading it',
      '  -v, --version   Print Riot\'s version',
      '  -w, --watch     Watch for changes',
      '  -c, --compact   Minify </p> <p> to </p><p>',
      '  -t, --type      JavaScript pre-processor. Built-in support for: es6, coffeescript, typescript, livescript, none',
      '  -m, --modular   AMD and CommonJS',
      '  --template      HTML pre-processor. Built-in support for: jade',
      '  --whitespace    Preserve newlines and whitepace',
      '  --brackets      Change brackets used for expressions. Defaults to { }',
      '  --expr          Run expressions trough parser defined with --type',
      '  --ext           Change tag file extension. Defaults to .tag',
      '',
      'Build a single .tag file:',
      '',
      '  riot foo.tag           To a same named file (foo.js)',
      '  riot foo.tag bar.js    To a different named file (bar.js)',
      '  riot foo.tag bar       To a different dir (bar/foo.js)',
      '',
      'Build all .tag files in a directory:',
      '',
      '  riot foo/bar           To a same directory (foo/**/*.js)',
      '  riot foo/bar baz       To a different directory (baz/**/*.js)',
      '  riot foo/bar baz.js    To a single concatenated file (baz.js)',
      '',
      'Examples for options:',
      '',
      '  riot foo bar',
      '  riot --w foo bar',
      '  riot --watch foo bar',
      '  riot --compact foo bar',
      '  riot foo bar --compact',
      '  riot test.tag --type coffeescript --expr',
      ''
    ].join('\n'))
  },


  version: function() {
    log(require('../../package.json').version)
  },


  make: function(opt) {
    init(opt)

    // Generate a list of input/output files

    var from = opt.flow[0] == 'f' ? [opt.from] : find(opt.from),
      base = opt.flow[0] == 'f' ? ph.dirname(opt.from) : opt.from,
      to = opt.flow[1] == 'f' ? [opt.to] : remap(from, opt.to, base)

    // Create any necessary dirs

    var dirs = {}
    to.map(function(f) { dirs[ph.dirname(f)] = 0 })
    sh.mkdir('-p', Object.keys(dirs))

    // Process files

    function encapsulate(from) {
      if (!opt.compiler.modular) {
        return from
      }

      var out = ''
      out += '(function(tagger) {\n'
      out += '  if (typeof define === \'function\' && define.amd) {\n'
      out += '    define(function(require, exports, module) { tagger(require(\'riot\'), require, exports, module)});\n'
      out += '  } else if (typeof module !== \'undefined\' && typeof module.exports !== \'undefined\') {\n'
      out += '    tagger(require(\'riot\'), require, exports, module);\n'
      out += '  } else {\n'
      out += '    tagger(window.riot);\n'
      out += '  }\n'
      out += '})(function(riot, require, exports, module) {\n'
      out += from
      out += '\n});'
      return out
    }

    function parse(from) { return compiler.compile(sh.cat(from).replace(/^\uFEFF/g, /* strips BOM */''), opt.compiler) }
    function toFile(from, to) { encapsulate(from.map(function (path, i) { return parse(path) }).join('\n')).to(to[0]) }
    function toDir(from, to) { from.map(function(from, i) { encapsulate(parse(from)).to(to[i]) }) }
    ;(opt.flow[1] == 'f' ? toFile : toDir)(from, to)

    // Print what's been done

    from.map(function(src, i) {
      log(toRelative(src) + ' -> ' + toRelative(to[i] || to[0]))
    })

  },


  watch: function(opt) {
    init(opt)

    methods.make(opt)

    var glob = opt.flow[0] == 'f' ? opt.from : ph.join(opt.from, '**/*.'+opt.ext)<commit_msg>removed: semicolon from the modular export string<commit_after>#!/usr/bin/env node
//
// Use in CLI:
//
//   Type "riot" for help.
//
// Use in Node:
//
//   var riot = require('riot/compiler')
//   riot.make({ from: 'foo', to: 'bar', compact: true })
//   riot.watch({ from: 'foo.tag', to: 'bar.js' })
//

var ph = require('path'),
  sh = require('shelljs'),
  chokidar = require('chokidar'),
  chalk = require('chalk'),
  compiler = require('./compiler'),
  analyzer = require('./analyzer'),
  TEMP_FILE_NAME = /\/[^.~][^~/]+$/ // skip temporary files (created by editors), e.g. /.name.tag, /~name.tag, /name~.tag

var ext

function find(from) {
  return sh.find(from).filter(function(f) {
    return ext.test(f) && TEMP_FILE_NAME.test(f)
  })
}
function remap(from, to, base) {
  return from.map(function(from) {
    return ph.join(to, ph.relative(base, from).replace(ext, '.js'))
  })
}

var methods = {

  help: function() {
    log([
      '',
      'Builds .tag files to .js',
      '',
      'Options:',
      '',
      '  -h, --help      You\'re reading it',
      '  -v, --version   Print Riot\'s version',
      '  -w, --watch     Watch for changes',
      '  -c, --compact   Minify </p> <p> to </p><p>',
      '  -t, --type      JavaScript pre-processor. Built-in support for: es6, coffeescript, typescript, livescript, none',
      '  -m, --modular   AMD and CommonJS',
      '  --template      HTML pre-processor. Built-in support for: jade',
      '  --whitespace    Preserve newlines and whitepace',
      '  --brackets      Change brackets used for expressions. Defaults to { }',
      '  --expr          Run expressions trough parser defined with --type',
      '  --ext           Change tag file extension. Defaults to .tag',
      '',
      'Build a single .tag file:',
      '',
      '  riot foo.tag           To a same named file (foo.js)',
      '  riot foo.tag bar.js    To a different named file (bar.js)',
      '  riot foo.tag bar       To a different dir (bar/foo.js)',
      '',
      'Build all .tag files in a directory:',
      '',
      '  riot foo/bar           To a same directory (foo/**/*.js)',
      '  riot foo/bar baz       To a different directory (baz/**/*.js)',
      '  riot foo/bar baz.js    To a single concatenated file (baz.js)',
      '',
      'Examples for options:',
      '',
      '  riot foo bar',
      '  riot --w foo bar',
      '  riot --watch foo bar',
      '  riot --compact foo bar',
      '  riot foo bar --compact',
      '  riot test.tag --type coffeescript --expr',
      ''
    ].join('\n'))
  },


  version: function() {
    log(require('../../package.json').version)
  },


  make: function(opt) {
    init(opt)

    // Generate a list of input/output files

    var from = opt.flow[0] == 'f' ? [opt.from] : find(opt.from),
      base = opt.flow[0] == 'f' ? ph.dirname(opt.from) : opt.from,
      to = opt.flow[1] == 'f' ? [opt.to] : remap(from, opt.to, base)

    // Create any necessary dirs

    var dirs = {}
    to.map(function(f) { dirs[ph.dirname(f)] = 0 })
    sh.mkdir('-p', Object.keys(dirs))

    // Process files

    function encapsulate(from) {
      if (!opt.compiler.modular) {
        return from
      }

      var out = ''
      out += '(function(tagger) {\n'
      out += '  if (typeof define === \'function\' && define.amd) {\n'
      out += '    define(function(require, exports, module) { tagger(require(\'riot\'), require, exports, module)})\n'
      out += '  } else if (typeof module !== \'undefined\' && typeof module.exports !== \'undefined\') {\n'
      out += '    tagger(require(\'riot\'), require, exports, module)\n'
      out += '  } else {\n'
      out += '    tagger(window.riot)\n'
      out += '  }\n'
      out += '})(function(riot, require, exports, module) {\n'
      out += from
      out += '\n});'
      return out
    }

    function parse(from) { return compiler.compile(sh.cat(from).replace(/^\uFEFF/g, /* strips BOM */''), opt.compiler) }
    function toFile(from, to) { encapsulate(from.map(function (path, i) { return parse(path) }).join('\n')).to(to[0]) }
    function toDir(from, to) { from.map(function(from, i) { encapsulate(parse(from)).to(to[i]) }) }
    ;(opt.flow[1] == 'f' ? toFile : toDir)(from, to)

    // Print what's been done

    from.map(function(src, i) {
      log(toRelative(src) + ' -> ' + toRelative(to[i] || to[0]))
    })

  },


  watch: function(opt) {
    init(opt)

    methods.make(opt)

    var glob = opt.flow[0] == 'f' ? opt.from : ph.join(opt.from, '**/*.'+opt.ext)
{'fraction_non_alphanumeric': 0.19318307982680138, 'fraction_numerical': 0.001998445653380704, 'mean_word_length': 2.184164015553199, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '7202603', 'n_tokens_mistral': 3184, 'n_tokens_neox': 3071, 'n_words': 797}