<commit_before>var _ = require('underscore'),
    config = require('./config'),
    deps = require('./deps'),
    fs = require('fs'),
    child_process = require('child_process');

if (config.DAEMON)
	throw "Can't run dev server in daemon mode.";

var server;
var start_server = _.debounce(function () {
	rebuildClient(function() {
		if (server)
			server.kill('SIGTERM');
		server = child_process.spawn('node', ['server/server.js']);
		server.stdout.pipe(process.stdout);
		server.stderr.pipe(process.stderr);
	});
}, 2000);

function rebuildClient(cb) {
	var make = child_process.spawn('make', ['client']);
	make.stdout.pipe(process.stdout);
	make.stderr.pipe(process.stderr);
	make.on('error', function(err) {
		console.error(err);
	});
	make.on('exit', cb);
}

var reload_state = _.debounce(function () {
	rebuildClient(function() {
		if (server)
			server.kill('SIGHUP');
	});
}, 2000);

deps.SERVER_DEPS.forEach(monitor.bind(null, start_server));
deps.SERVER_STATE.forEach(monitor.bind(null, reload_state));
deps.CLIENT_DEPS.forEach(monitor.bind(null, reload_state));

function monitor(func, dep) {
	var mtime = new Date;
	fs.watchFile(dep, {interval: 500, persistent: true}, function (event) {
		if (event.mtime > mtime) {
			func();
			mtime = event.mtime;
		}
	});
}

start_server();<commit_msg>Only rebuild the client on first sever start<commit_after>var _ = require('underscore'),
    config = require('./config'),
    deps = require('./deps'),
    fs = require('fs'),
    child_process = require('child_process');

if (config.DAEMON)
	throw "Can't run dev server in daemon mode.";

var server;
var start_server = _.debounce(function () {
	if (server)
		server.kill('SIGTERM');
	server = child_process.spawn('node', ['server/server.js']);
	server.stdout.pipe(process.stdout);
	server.stderr.pipe(process.stderr);
}, 2000);

function rebuildClient(cb) {
	var make = child_process.spawn('make', ['client']);
	make.stdout.pipe(process.stdout);
	make.stderr.pipe(process.stderr);
	make.on('error', function(err) {
		console.error(err);
	});
	make.on('exit', cb);
}

var reload_state = _.debounce(function () {
	rebuildClient(function() {
		if (server)
			server.kill('SIGHUP');
	});
}, 2000);

deps.SERVER_DEPS.forEach(monitor.bind(null, start_server));
deps.SERVER_STATE.forEach(monitor.bind(null, reload_state));
deps.CLIENT_DEPS.forEach(monitor.bind(null, reload_state));

function monitor(func, dep) {
	var mtime = new Date;
	fs.watchFile(dep, {interval: 500, persistent: true}, function (event) {
		if (event.mtime > mtime) {
			func();
			mtime = event.mtime;
		}
	});
}

rebuildClient(start_server);
{'fraction_non_alphanumeric': 0.17788829380260138, 'fraction_numerical': 0.008416220351951033, 'mean_word_length': 4.943181818181818, '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': '3036942', 'n_tokens_mistral': 966, 'n_tokens_neox': 901, 'n_words': 171}