<commit_before>#!/usr/bin/env node

/**
 * Build static/.
 */

require(__dirname + '/../app/modules/mainevent');

var _ = require('underscore'),
    fs = require('fs'),
    program = require('commander');

program
  .option('-p, --prod')
  .parse(process.argv);

var exec = require('child_process').exec,
    APP = __dirname + '/..',
    SOURCE = APP + '/public',
    BUILD = APP + '/static',
    BUILD_OLD = APP + '/static-old',
    BUILD_TMP = APP + '/static-tmp';

exec('pgrep -f "node.*public/build.js" | wc -w', null, function(code, stdout) {
  if (stdout.toString().trim() != '2') {
    console.log('Another instance is already running.');
    process.exit(0);
  }

  var commands = [];
  _.each(steps, function(step) {
    commands = commands.concat(step());
  });

  mainevent.shared.Async.runSync(
    commands,
    function(command, onCommandDone) {
      exec(command, null, function(code, stdout, stderr) {
        onCommandDone();
      });
    }
  );
});

var steps = [
  // Clean prior build.
  function() {
    return ['rm -rf ' + BUILD_TMP, 'mkdir ' + BUILD_TMP];
  },

  // Compile templates.
  function() {
    return [SOURCE + '/js/templates.build.js'];
  },

  // Compress JS.
  function() {
    var commands = ['cp -a ' + SOURCE + '/js ' + BUILD_TMP + '/js-compressed'];

    if (program.prod) {
      commands.push('find ' + BUILD_TMP + '/js-compressed -regex ".*\\(index\\|\\(backbone\\|collections\\|controllers\\|helpers\\|models\\|observers\\|shared\\|views\\)\\/\\).*js" -exec java -jar ' + SOURCE + '/yuicompressor.jar -o {} {} \\;');
    }

    return commands;
  },

  // Combine Js
  function() {
    return [
      'r.js -o ' + BUILD_TMP + '/js-compressed/app.build.js',
      'rm -rf ' + BUILD_TMP + '/js-compressed'
    ];
  },

  // Combine and compress CSS.
  function() {
    var commands = ['mkdir ' + BUILD_TMP + '/css'];
        files = [
          SOURCE + '/css/bootstrap.css',
          SOURCE + '/css/jquery-ui.css',
          SOURCE + '/css/jquery-ui-timepicker-addon.css',
          SOURCE + '/css/jquery.jqplot.css',
          SOURCE + '/css/index.css'
        ];

    commands.push('cat ' + files.join(' ') + ' > ' + BUILD_TMP + '/css/all.css');<commit_msg>Add parser-specific CSS to all.css.<commit_after>#!/usr/bin/env node

/**
 * Build static/.
 */

require(__dirname + '/../app/modules/mainevent');

var _ = require('underscore'),
    fs = require('fs'),
    program = require('commander');

program
  .option('-p, --prod')
  .parse(process.argv);

var exec = require('child_process').exec,
    APP = __dirname + '/..',
    SOURCE = APP + '/public',
    BUILD = APP + '/static',
    BUILD_OLD = APP + '/static-old',
    BUILD_TMP = APP + '/static-tmp';

exec('pgrep -f "node.*public/build.js" | wc -w', null, function(code, stdout) {
  if (stdout.toString().trim() != '2') {
    console.log('Another instance is already running.');
    process.exit(0);
  }

  var commands = [];
  _.each(steps, function(step) {
    commands = commands.concat(step());
  });

  mainevent.shared.Async.runSync(
    commands,
    function(command, onCommandDone) {
      exec(command, null, function(code, stdout, stderr) {
        onCommandDone();
      });
    }
  );
});

var steps = [
  // Clean prior build.
  function() {
    return ['rm -rf ' + BUILD_TMP, 'mkdir ' + BUILD_TMP];
  },

  // Compile templates.
  function() {
    return [SOURCE + '/js/templates.build.js'];
  },

  // Compress JS.
  function() {
    var commands = ['cp -a ' + SOURCE + '/js ' + BUILD_TMP + '/js-compressed'];

    if (program.prod) {
      commands.push('find ' + BUILD_TMP + '/js-compressed -regex ".*\\(index\\|\\(backbone\\|collections\\|controllers\\|helpers\\|models\\|observers\\|shared\\|views\\)\\/\\).*js" -exec java -jar ' + SOURCE + '/yuicompressor.jar -o {} {} \\;');
    }

    return commands;
  },

  // Combine Js
  function() {
    return [
      'r.js -o ' + BUILD_TMP + '/js-compressed/app.build.js',
      'rm -rf ' + BUILD_TMP + '/js-compressed'
    ];
  },

  // Combine and compress CSS.
  function() {
    var commands = ['mkdir ' + BUILD_TMP + '/css'];
        files = [
          SOURCE + '/css/bootstrap.css',
          SOURCE + '/css/jquery-ui.css',
          SOURCE + '/css/jquery-ui-timepicker-addon.css',
          SOURCE + '/css/jquery.jqplot.css',
          SOURCE + '/css/index.css'
        ];


    // Add files from each parser directory.
    var baseDir = __dirname + '/../app/parsers';
    _.each(fs.readdirSync(baseDir), function(parser) {
      if (!fs.statSync(baseDir + '/' + parser).isDirectory()) {
        return;
      }

      // Ex. 'app/parsers/Json/css'.
      var cssDir = baseDir + '/' + parser + '/css';

      _.each(fs.readdirSync(cssDir), function(template) {
        files.push(cssDir + '/' + template);
      });
    });

    commands.push('cat ' + files.join(' ') + ' > ' + BUILD_TMP + '/css/all.css');
{'fraction_non_alphanumeric': 0.20348004094165814, 'fraction_numerical': 0.0008188331627430911, 'mean_word_length': 2.341997264021888, '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': '456687', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1678, 'n_words': 324}