<commit_before>"use strict";

var fs   = require("fs"),
    path = require("path"),
    
    browserify = require("browserify"),
    duration   = require("humanize-duration"),
    
    server   = require("connect")(),
    ecstatic = require("ecstatic")(process.cwd(), {
        cache       : 0,
        handleError : false
    }),
    builder  = browserify("src/index.js", {
        debug : true
    }),
    
    bundling, bytes, time, done;

function bundle() {
    bundling = true;
    
    builder.bundle(function(err, out) {
        if(err) {
            return console.error(err.toString());
        }
        
        fs.writeFileSync("gen/index.js", out);
        
        console.error(bytes.toString(), "bytes written to gen/index.js in", duration(time));
        
        bundling = false;
        done && done();
    });
}

builder.plugin("watchify");
builder.plugin("modular-css", {
    css : "gen/index.css"
});

// Start up watchify
builder.on("update", bundle);
builder.on("bytes", function(b) {
    bytes = b;
});
builder.on("time", function(t) {
    time = t;
});
bundle();

// Log HTTP requests
server.use(require("morgan")("dev"));

// Delay responding to generated file requests until it's done
server.use("/gen/index.js", function(req, res, next) {
    if(!bundling) {<commit_msg>Nicer bundle error handling<commit_after>"use strict";

var fs   = require("fs"),
    path = require("path"),
    
    browserify = require("browserify"),
    duration   = require("humanize-duration"),
    
    server   = require("connect")(),
    ecstatic = require("ecstatic")(process.cwd(), {
        cache       : 0,
        handleError : false
    }),
    builder  = browserify("src/index.js", {
        debug : true
    }),
    
    bundling, bytes, time, done;

function bundle() {
    bundling = true;
    
    builder.bundle(function(err, out) {
        bundling = false;
        
        if(err) {
            console.error(err.toString());
            
            fs.writeFileSync(
                "gen/index.js",
                "document.body.innerHTML = \"<pre style='color: red;'>" + err.toString().replace(/\\/g, "/") + "</pre>\";"
            );
            
            return done && done();
        }

        console.error(bytes.toString(), "bytes written to gen/index.js in", duration(time));
        
        fs.writeFileSync("gen/index.js", out);
        
        done && done();
    });
}

builder.plugin("watchify");
builder.plugin("modular-css", {
    css : "gen/index.css"
});

// Start up watchify
builder.on("update", bundle);

builder.on("bytes", function(b) {
    bytes = b;
});

builder.on("time", function(t) {
    time = t;
});

bundle();

// Log HTTP requests
server.use(require("morgan")("dev"));

// Delay responding to generated file requests until it's done
server.use("/gen/index.js", function(req, res, next) {
    if(!bundling) {
{'fraction_non_alphanumeric': 0.17258176757132915, 'fraction_numerical': 0.0006958942240779402, 'mean_word_length': 2.3084004602991945, 'pattern_counts': {'":': 0, '<': 5, '<?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': '711084', 'n_tokens_mistral': 886, 'n_tokens_neox': 880, 'n_words': 183}