<commit_before>var fs = require('fs'),
	less = require('less'),
	spawn = require('child_process').spawn;

exports.setup = function(socket, path){
	lessCompiler(socket, path);
};
exports.file = function(socket, path){
	compileFile(socket, path);
};

var lessCompiler = function(socket, path){
	console.log('path: ' + path);
	try {
		fs.exists(path, function(exists){
			if(exists){
				if(path.substr(-5) == '.less'){
					fs.watchFile(path, { persistent:true, interval:500 }, function(c,p){
						if(p.mtime < c.mtime){
							compileFile(socket, path);
						};
					});
					compileFile(socket, path);
				}else{
					compErr(socket, 'file not .less');
				}
			}else{
				compErr(socket, 'file null');
			}
		});
	}catch(err){
		compErr(socket, err);
	};
	socket.on('disconnect',function(){
		fs.unwatchFile(path);
	});
};

var compErr = function(socket, err){
	console.log("COMP ERR: " + err);
	socket.emit('css-pcw-err', err);
};

var compileFile = function(socket, path){
	var cssFile = path.substring(0,path.length - 4) + 'css',
		logCount = 0,
		logObj = {},
		errCount = 0;
		lessc = spawn('lessc', ['--no-color', '--compress', path, cssFile]);
	lessc.stderr.setEncoding('utf8');
	lessc.stderr.on('data', function(data){
		if(errCount === 0){
			logObj.error = data;
		}else{
			logObj.lines = data;
		}
		errCount += 1;
		console.log("err: " + data);
	});
	lessc.stdout.on('data', function(data){
		console.log("data: " + data);
		logObj.out = data;
	});
	lessc.stdout.on('end', function(data){
		console.log("end: " + data);
		results(socket, logObj);
	});
};

var results = function(socket, logObj){
	if(logObj.hasOwnProperty('error')){
		if(logObj.lines){
			socket.emit('css-pcw-compile-error', logObj);<commit_msg>css-pcw<commit_after>var fs = require('fs'),
	less = require('less'),
	spawn = require('child_process').spawn;

exports.setup = function(socket, path){
	lessCompiler(socket, path);
};
exports.file = function(socket, path){
	compileFile(socket, path);
};

var lessCompiler = function(socket, path){
	console.log('path: ' + path);
	try {
		fs.exists(path, function(exists){
			if(exists){
				if(path.substr(-5) == '.less'){
					fs.watchFile(path, { persistent:true, interval:500 }, function(c,p){
						if(p.mtime < c.mtime){
							compileFile(socket, path);
						};
					});
					compileFile(socket, path);
				}else{
					compErr(socket, 'file not .less');
				}
			}else{
				compErr(socket, 'file null');
			}
		});
	}catch(err){
		compErr(socket, err);
	};
	socket.on('disconnect',function(){
		fs.unwatchFile(path);
	});
};

var compErr = function(socket, err){
	console.log("COMP ERR: " + err);
	socket.emit('css-pcw-err', err);
};

var compileFile = function(socket, path){
	var cssFile = path.substring(0,path.length - 4) + 'css',
		logCount = 0,
		logObj = {},
		errCount = 0;
		lessc = spawn('lessc', ['--no-color', '--yui-compress', path, cssFile]);
	lessc.stderr.setEncoding('utf8');
	lessc.stderr.on('data', function(data){
		if(errCount === 0){
			logObj.error = data;
		}else{
			logObj.lines = data;
		}
		errCount += 1;
		console.log("err: " + data);
	});
	lessc.stdout.on('data', function(data){
		console.log("data: " + data);
		logObj.out = data;
	});
	lessc.stdout.on('end', function(data){
		console.log("end: " + data);
		results(socket, logObj);
	});
};

var results = function(socket, logObj){
	if(logObj.hasOwnProperty('error')){
		if(logObj.lines){
			socket.emit('css-pcw-compile-error', logObj);
{'fraction_non_alphanumeric': 0.2042824074074074, 'fraction_numerical': 0.00636574074074074, 'mean_word_length': 3.9315263908701854, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7211866', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1270, 'n_words': 231}