<commit_before>var argv = require('optimist').argv;

if (!argv.entry) {
  console.log('usage: bla --entry index.js');
  process.exit(0);
}

var entryPath = process.cwd() + '/' + argv.entry;

var path = require('path');
var chokidar = require('chokidar');
var combineSourceMap = require('combine-source-map');
var fs = require('fs');

var depsTree = require('./lib/deps-tree');

var watcher = chokidar.watch([], {persistent: true})
  .on('change', buildAll)
  .on('unlink', buildAll)


var watchFileList = [];

var promiseRef = undefined;

var g_ws = undefined;

function buildAll () {
  console.log('Rebuilding...');

  depsTree(entryPath)
    .then(function (deps) {

      watcher.unwatch(watchFileList);
      watcher.add(deps.files);
      watchFileList = deps.files;

      build(deps);

      if (g_ws) {
        g_ws.send('reload');
      }

      console.log('Rebuild complete.');
    })
    .catch(function (err) {
      console.log('Error', err);
    });
}

buildAll();

function build (deps) {


var source = fs.readFileSync(entryPath, 'utf-8');

var sourceMap = combineSourceMap.create();

function lineBreakCount(str){
	/* counts \n */
	try {
		return((str.match(/[^\n]*\n[^\n]*/gi).length));
	} catch(e) {
		return 0;
	}
}

var combinedHtml = '<html><head><script>var modulesInfo = {\n';
<commit_msg>TODOs what to improve for production use<commit_after>// TODO: split functionality to building, completion notifying
// and watching. With support of production builds without watches
// and reload handlers.
// Make all functionality available via API instead of running
// a process. Make possibility to supply resulting bundle
// in memory instead of thru a file.
// Separate index.html bundling from core bundling,
// allow externalize that functionality
// (but support thru specifying source map offset -
// position of JavaScript <script> code in HTML).
// Remove reloading support into example, but make use
// of API.
// Use caching to prevent re-reading of files if nothing changed,
// only track changed files.

var argv = require('optimist').argv;

if (!argv.entry) {
  console.log('usage: bla --entry index.js');
  process.exit(0);
}

var entryPath = process.cwd() + '/' + argv.entry;

var path = require('path');
var chokidar = require('chokidar');
var combineSourceMap = require('combine-source-map');
var fs = require('fs');

var depsTree = require('./lib/deps-tree');

var watcher = chokidar.watch([], {persistent: true})
  .on('change', buildAll)
  .on('unlink', buildAll)


var watchFileList = [];

var promiseRef = undefined;

var g_ws = undefined;

function buildAll () {
  console.log('Rebuilding...');

  depsTree(entryPath)
    .then(function (deps) {

      watcher.unwatch(watchFileList);
      watcher.add(deps.files);
      watchFileList = deps.files;

      build(deps);

      if (g_ws) {
        g_ws.send('reload');
      }

      console.log('Rebuild complete.');
    })
    .catch(function (err) {
      console.log('Error', err);
    });
}

buildAll();

function build (deps) {


var source = fs.readFileSync(entryPath, 'utf-8');

var sourceMap = combineSourceMap.create();

function lineBreakCount (str){
  try {
    return((str.match(/[^\n]*\n[^\n]*/gi).length));
  } catch(e) {
    return 0;
  }
}

var combinedHtml = '<html><head><script>var modulesInfo = {\n';

{'fraction_non_alphanumeric': 0.16173808086904043, 'fraction_numerical': 0.0018105009052504525, 'mean_word_length': 3.516348773841962, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '6448051', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1080, 'n_words': 279}