<commit_before>window.addEventListener("DOMContentLoaded", function(){onload();});
var canvas;
var ctx;
var rotations;
var slicesArr = [];
var edge = 7;//the size of the edges
var amountRotated = 0;
var graphTypeInput;

function onload() {
	canvas = document.getElementById("canvas");
	ctx = canvas.getContext("2d");
	size();
	document.getElementById("rotate").addEventListener("click", function(){start(true);});
	document.getElementById("graph").addEventListener("click", function(){graph(true);});
	graphTypeInput = document.getElementById("typeOfGraph");
}

function start(complete) {
	slicesArr = [];
	var graphType = graphTypeInput.value;
	if(graphType == "exponential") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, Math.pow(2,i/16)*(i+300)/300);
	} else if(graphType == "sine") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, Math.sin(i/16)*(i+300)/8);
	} else if(graphType == "absValue") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, Math.abs(100 - 2*i)*(i+300)/300);
	} else if(graphType == "rational") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, 20*rational(i/10+2.505)*(i+300)/300, i < 20);
	} else if(graphType == "triangle") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, Math.abs(50 - 2*(i%50))*(i+300)/300);
	} else if(graphType == "hyperbola") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, 100*hyperbola(i/200 + 1)*(i+300)/300);
	} else if(graphType == "log") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, 50*Math.log((i + 0.01)/20)*(i+300)/300, i < 20);
	} else if(graphType == "cylinder") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, 100*(i+300)/300);
	}
	if(complete) {
		animate();
		graph(false);
	}
}

function graph(complete) {
	ctx.clearRect(0,0,canvas.width,canvas.height);
	var graphType = graphTypeInput.value;
	if(graphType == "exponential") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 3*Math.pow(2,(i-1)/16),500 + 3*i,300 - 3*Math.pow(2,i/16));
		}
	} else if(graphType == "sine") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 80*Math.sin((i-1)/16),500 + 3*i,300 - 80*Math.sin(i/16));
		}
	} else if(graphType == "absValue") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 1.5*Math.abs(100 - 2*(i-1)),500 + 3*i,300 - 1.5*Math.abs(100 - 2*i));
		}
	} else if(graphType == "rational") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 40*rational((i-1)/10+2.505),500 + 3*i,300 - 40*rational(i/10+2.505));
		}
	} else if(graphType == "triangle") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 1.5*Math.abs(50 - 2*((i-1)%50)),500 + 3*i,300 - 1.5*Math.abs(50 - 2*(i%50)));
		}
	} else if(graphType == "hyperbola") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 100*hyperbola((i - 1)/100 + 1),500 + 3*i,300 - 100*hyperbola(i/100 + 1));
			drawLine(500+(i-1) *3,300 + 100*hyperbola((i - 1)/100 + 1),500 + 3*i,300 + 100*hyperbola(i/100 + 1));
		}
	} else if(graphType == "log") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 50*Math.log((i + 0.01)/20),500 + 3*i,300 - 50*Math.log((i + 1.01)/20));
		}
	} else if(graphType == "cylinder") {
		drawLine(500,200,800,200);
	} else {
		ctx.font="20px Helvetica";
		ctx.fillText("The function has not been developed yet.",275,200);
	}
	drawLine(500,300,800,300);
	if(complete)
		start(false);
	renderSlices(0.1);
}

function drawLine(x,y,z,w) {
	ctx.beginPath();
	ctx.strokeStyle = "#000000";
	ctx.moveTo(x,y);
	ctx.lineTo(z,w);
	ctx.stroke();
}

function animate() {
	renderSlices(amountRotated);
	if(amountRotated > Math.PI*2) {
		requestId = undefined;
		amountRotated = 0;
	} else {
		if(amountRotated == 0) {
			ctx.clearRect(0,0,canvas.width,canvas.height);
		}
		amountRotated += 0.05;
		requestAnimationFrame(animate);
	}
}

function size() {
	canvas.width = "900";
	canvas.height = "556";
}

function addSlice(x,y,radius,fill) {
	var temp = new Slice(x,y,radius,fill);
	slicesArr.push(temp);
}

function Slice(x,y,radius,fill) {
	this.x = x;
	this.y = y;
	this.radius = radius;
	if(this.radius > 200 || this.radius < -200)
		this.radius = false;
	this.fill = fill;
}

Slice.prototype.render = function (arclen) {
	//for the left half
	if(!isNaN(this.radius)) {
		var gradient=ctx.createLinearGradient(0,this.y - this.radius - edge,0,this.y + this.radius + edge);
		ctx.lineWidth = edge;
		if(this.radius > 0){
			ctx.save();
			ctx.beginPath();
			ctx.rect(this.x - this.radius - edge, this.y - this.radius - edge, this.radius + edge, this.radius*2 + edge*2);
			ctx.clip();
			ctx.beginPath();
			ctx.arc(this.x, this.y, this.radius, 3*Math.PI/2, 3*Math.PI/2 - arclen, true);
			gradient.addColorStop("0.05", "#AAAAAA");
			gradient.addColorStop("0.2","#DDDDDD");
			gradient.addColorStop("0.4","#999999");
			gradient.addColorStop("0.6","#666666");
			gradient.addColorStop("0.7","#555555")
			gradient.addColorStop("0.9","#333333");
		} else {
			ctx.save();
			ctx.beginPath();
			ctx.rect(this.x + this.radius - edge, this.y + this.radius - edge, edge - this.radius, edge*2 - this.radius*2);
			ctx.clip();
			ctx.beginPath();
			ctx.arc(this.x, this.y, -this.radius, 5*Math.PI/2, 5*Math.PI/2 - arclen, true);
			gradient.addColorStop("0.95", "#AAAAAA");
			gradient.addColorStop("0.8","#DDDDDD");
			gradient.addColorStop("0.6","#999999");
			gradient.addColorStop("0.4","#666666");
			gradient.addColorStop("0.3","#555555")
			gradient.addColorStop("0.1","#333333");
		}
		ctx.strokeStyle = gradient;
		if(this.radius > 0 || this.radius < -6)
			ctx.stroke();
		ctx.restore();

		//for the right half
		var gradient=ctx.createLinearGradient(0,this.y - this.radius - edge,0,this.y + this.radius + edge);
		if(this.radius > 0){
			ctx.save();
			ctx.beginPath();
			ctx.rect(this.x, this.y - this.radius - edge, this.radius + edge, this.radius*2 + edge*2);
			ctx.clip();
			ctx.beginPath();
			ctx.arc(this.x, this.y, this.radius, 3*Math.PI/2, 3*Math.PI/2 - arclen, true);
			gradient.addColorStop("0.05", "#AAAAAA");
			gradient.addColorStop("0.1","#999999");
			gradient.addColorStop("0.5","#555555");
			gradient.addColorStop("0.85","#292929");
			gradient.addColorStop("0.92","#2D2D2D");
			gradient.addColorStop("0.98","#333333");
		} else {
			ctx.save();
			ctx.beginPath();
			ctx.rect(this.x, this.y + this.radius - edge, edge - this.radius, edge*2 - this.radius*2);
			ctx.clip();
			ctx.beginPath();
			ctx.arc(this.x, this.y, -this.radius, 5*Math.PI/2, 5*Math.PI/2 - arclen, true);
			gradient.addColorStop("0.95", "#AAAAAA");
			gradient.addColorStop("0.9","#999999");
			gradient.addColorStop("0.5","#555555");
			gradient.addColorStop("0.15","#292929");
			gradient.addColorStop("0.08","#2D2D2D");
			gradient.addColorStop("0.02","#333333");
		}
		ctx.strokeStyle = gradient;
		if(this.radius > 0 || this.radius < -6)
			ctx.stroke();
		ctx.restore();

		if(this.fill) {
			if(this.radius > 0) {
				var gradient = ctx.createLinearGradient(0,this.y - this.radius - edge,0,this.y + this.radius + edge);
				gradient.addColorStop("0","#A0A0A0");
				gradient.addColorStop("1","#333333");
			} else {
				var gradient = ctx.createLinearGradient(0,this.y - this.radius - edge,0,this.y + this.radius + edge);
				gradient.addColorStop("1","#A0A0A0");
				gradient.addColorStop("0","#333333");
			}
			ctx.fillStyle = gradient;
			ctx.fill();
		}
	}
}

function renderSlices(arclen) {
	ctx.save();
	ctx.scale(0.5, 1);
	for(i = 0; i < slicesArr.length;i++)
		slicesArr[i].render(arclen);
	ctx.restore();
}

function Equation(op, num){
	this.ops = [op];
	this.nums = [num];
	this.valueOf = function(x){
		for(var i=0;i<this.ops.length;i++){
			x = execute(x,this.ops[i],this.nums[i]);
		}
		return x;
	}
	this.addOperator = function(operator,number){
		this.ops.push(operator);
		this.nums.push(number);
	}
}

function execute(x,operator,number){
	 if(operator == "+"){
		return x+number;
	}if(operator == "-"){
		return x-number;
	}if(operator == "*"){
		return x*number;
	}if(operator == "/"){
		return x/number;
	}if(operator == "^"){
		return Math.pow(x,number);
	}
}

function rational(x) {
	return (x*x*x - 2*x)/(2*(x*x - 5));
}

function hyperbola(x) {
	return Math.sqrt(x*x - 1);
}

function renderCircle () {
	ctx.save();
	ctx.scale(0.5, 1);
	ctx.beginPath();
	ctx.arc(200,300,100,0,2*Math.PI,true);
	ctx.stroke();
	ctx.restore();
}<commit_msg>Corrected the fill<commit_after>window.addEventListener("DOMContentLoaded", function(){onload();});
var canvas;
var ctx;
var rotations;
var slicesArr = [];
var edge = 7;//the size of the edges
var amountRotated = 0;
var graphTypeInput;
var fill = false;

function onload() {
	canvas = document.getElementById("canvas");
	ctx = canvas.getContext("2d");
	size();
	document.getElementById("rotate").addEventListener("click", function(){start(true);});
	document.getElementById("graph").addEventListener("click", function(){graph(true);});
	graphTypeInput = document.getElementById("typeOfGraph");
}

function start(complete) {
	slicesArr = [];
	var graphType = graphTypeInput.value;
	if(graphType == "exponential") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, Math.pow(2,i/16)*(i+300)/300);
	} else if(graphType == "sine") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, Math.sin(i/16)*(i+300)/8);
	} else if(graphType == "absValue") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, Math.abs(100 - 2*i)*(i+300)/300);
	} else if(graphType == "rational") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, 20*rational(i/10+2.505)*(i+300)/300, i < 2);
	} else if(graphType == "triangle") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, Math.abs(50 - 2*(i%50))*(i+300)/300);
	} else if(graphType == "hyperbola") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, 100*hyperbola(i/200 + 1)*(i+300)/300);
	} else if(graphType == "log") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, 50*Math.log((i + 0.01)/20)*(i+300)/300, i < 20);
	} else if(graphType == "cylinder") {
		for(i = 0; i <= 100; i++)
			addSlice(200 + i * 5, i/-5 + 300, 100*(i+300)/300);
	}
	if(complete) {
		animate();
		graph(false);
	}
}

function graph(complete) {
	ctx.clearRect(0,0,canvas.width,canvas.height);
	var graphType = graphTypeInput.value;
	if(graphType == "exponential") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 3*Math.pow(2,(i-1)/16),500 + 3*i,300 - 3*Math.pow(2,i/16));
		}
	} else if(graphType == "sine") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 80*Math.sin((i-1)/16),500 + 3*i,300 - 80*Math.sin(i/16));
		}
	} else if(graphType == "absValue") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 1.5*Math.abs(100 - 2*(i-1)),500 + 3*i,300 - 1.5*Math.abs(100 - 2*i));
		}
	} else if(graphType == "rational") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 40*rational((i-1)/10+2.505),500 + 3*i,300 - 40*rational(i/10+2.505));
		}
	} else if(graphType == "triangle") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 1.5*Math.abs(50 - 2*((i-1)%50)),500 + 3*i,300 - 1.5*Math.abs(50 - 2*(i%50)));
		}
	} else if(graphType == "hyperbola") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 100*hyperbola((i - 1)/100 + 1),500 + 3*i,300 - 100*hyperbola(i/100 + 1));
			drawLine(500+(i-1) *3,300 + 100*hyperbola((i - 1)/100 + 1),500 + 3*i,300 + 100*hyperbola(i/100 + 1));
		}
	} else if(graphType == "log") {
		for(i = 1; i <= 100; i++) {
			drawLine(500+(i-1) *3,300 - 50*Math.log((i + 0.01)/20),500 + 3*i,300 - 50*Math.log((i + 1.01)/20));
		}
	} else if(graphType == "cylinder") {
		drawLine(500,200,800,200);
	} else {
		ctx.font="20px Helvetica";
		ctx.fillText("The function has not been developed yet.",275,200);
	}
	drawLine(500,300,800,300);
	if(complete)
		start(false);
	fill = false;
	renderSlices(0.1);
}

function drawLine(x,y,z,w) {
	ctx.beginPath();
	ctx.strokeStyle = "#000000";
	ctx.moveTo(x,y);
	ctx.lineTo(z,w);
	ctx.stroke();
}

function animate() {
	fill = true;
	renderSlices(amountRotated);
	if(amountRotated > Math.PI*2) {
		requestId = undefined;
		amountRotated = 0;
	} else {
		if(amountRotated == 0) {
			ctx.clearRect(0,0,canvas.width,canvas.height);
		}
		amountRotated += 0.05;
		requestAnimationFrame(animate);
	}
}

function size() {
	canvas.width = "900";
	canvas.height = "556";
}

function addSlice(x,y,radius,fill) {
	var temp = new Slice(x,y,radius,fill);
	slicesArr.push(temp);
}

function Slice(x,y,radius,fill) {
	this.x = x;
	this.y = y;
	this.radius = radius;
	if(this.radius < 0 && this.radius > -7)
		this.radius = -7;
	if(this.radius > 200 || this.radius < -200)
		this.radius = false;
	this.fill = fill;
}

Slice.prototype.render = function (arclen) {
	//for the left half
	if(!isNaN(this.radius)) {
		var gradient=ctx.createLinearGradient(0,this.y - this.radius - edge,0,this.y + this.radius + edge);
		ctx.lineWidth = edge;
		if(this.radius > 0){
			ctx.save();
			ctx.beginPath();
			ctx.rect(this.x - this.radius - edge, this.y - this.radius - edge, this.radius + edge, this.radius*2 + edge*2);
			ctx.clip();
			ctx.beginPath();
			ctx.arc(this.x, this.y, this.radius, 3*Math.PI/2, 3*Math.PI/2 - arclen, true);
			gradient.addColorStop("0.05", "#AAAAAA");
			gradient.addColorStop("0.2","#DDDDDD");
			gradient.addColorStop("0.4","#999999");
			gradient.addColorStop("0.6","#666666");
			gradient.addColorStop("0.7","#555555")
			gradient.addColorStop("0.9","#333333");
		} else {
			ctx.save();
			ctx.beginPath();
			ctx.rect(this.x + this.radius - edge, this.y + this.radius - edge, edge - this.radius, edge*2 - this.radius*2);
			ctx.clip();
			ctx.beginPath();
			ctx.arc(this.x, this.y, -this.radius, 5*Math.PI/2, 5*Math.PI/2 - arclen, true);
			gradient.addColorStop("0.95", "#AAAAAA");
			gradient.addColorStop("0.8","#DDDDDD");
			gradient.addColorStop("0.6","#999999");
			gradient.addColorStop("0.4","#666666");
			gradient.addColorStop("0.3","#555555")
			gradient.addColorStop("0.1","#333333");
		}
		ctx.strokeStyle = gradient;
		ctx.stroke();
		ctx.restore();

		//for the right half
		var gradient=ctx.createLinearGradient(0,this.y - this.radius - edge,0,this.y + this.radius + edge);
		if(this.radius > 0){
			ctx.save();
			ctx.beginPath();
			ctx.rect(this.x, this.y - this.radius - edge, this.radius + edge, this.radius*2 + edge*2);
			ctx.clip();
			ctx.beginPath();
			ctx.arc(this.x, this.y, this.radius, 3*Math.PI/2, 3*Math.PI/2 - arclen, true);
			gradient.addColorStop("0.05", "#AAAAAA");
			gradient.addColorStop("0.1","#999999");
			gradient.addColorStop("0.5","#555555");
			gradient.addColorStop("0.85","#292929");
			gradient.addColorStop("0.92","#2D2D2D");
			gradient.addColorStop("0.98","#333333");
		} else {
			ctx.save();
			ctx.beginPath();
			ctx.rect(this.x, this.y + this.radius - edge, edge - this.radius, edge*2 - this.radius*2);
			ctx.clip();
			ctx.beginPath();
			ctx.arc(this.x, this.y, -this.radius, 5*Math.PI/2, 5*Math.PI/2 - arclen, true);
			gradient.addColorStop("0.95", "#AAAAAA");
			gradient.addColorStop("0.9","#999999");
			gradient.addColorStop("0.5","#555555");
			gradient.addColorStop("0.15","#292929");
			gradient.addColorStop("0.08","#2D2D2D");
			gradient.addColorStop("0.02","#333333");
		}
		ctx.strokeStyle = gradient;
		ctx.stroke();
		ctx.restore();

		if(this.fill && fill) {
			if(this.radius > 0) {
				var gradient = ctx.createLinearGradient(0,this.y - this.radius - edge,0,this.y + this.radius + edge);
				gradient.addColorStop("0","#BBBBBB");
				gradient.addColorStop("1","#333333");
			} else {
				var gradient = ctx.createLinearGradient(0,this.y - this.radius - edge,0,this.y + this.radius + edge);
				gradient.addColorStop("1","#BBBBBB");
				gradient.addColorStop("0","#333333");
			}
			ctx.lineTo(this.x,this.y);
			ctx.closePath();
			ctx.fillStyle = gradient;
			ctx.fill();
		}
	}
}

function renderSlices(arclen) {
	ctx.save();
	ctx.scale(0.5, 1);
	for(i = 0; i < slicesArr.length;i++)
		slicesArr[i].render(arclen);
	ctx.restore();
}

function Equation(op, num){
	this.ops = [op];
	this.nums = [num];
	this.valueOf = function(x){
		for(var i=0;i<this.ops.length;i++){
			x = execute(x,this.ops[i],this.nums[i]);
		}
		return x;
	}
	this.addOperator = function(operator,number){
		this.ops.push(operator);
		this.nums.push(number);
	}
}

function execute(x,operator,number){
	 if(operator == "+"){
		return x+number;
	}if(operator == "-"){
		return x-number;
	}if(operator == "*"){
		return x*number;
	}if(operator == "/"){
		return x/number;
	}if(operator == "^"){
		return Math.pow(x,number);
	}
}

function rational(x) {
	return (x*x*x - 2*x)/(2*(x*x - 5));
}

function hyperbola(x) {
	return Math.sqrt(x*x - 1);
}

function renderCircle () {
	ctx.save();
	ctx.scale(0.5, 1);
	ctx.beginPath();
	ctx.arc(200,300,100,0,2*Math.PI,true);
	ctx.stroke();
	ctx.restore();
}<|endoftext|>


<commit_before>'use strict';
const express = require('express');
const Controller = require('./lib/controllers/');
const addon = require('./addons');

class Router extends express.Router {
    constructor (passport, options) {
        addon.callAddons('Router', 'setRouter', {parentRouter: this}, {sync: true});

        this.all('/api/*', Controller.Api.notFound);
        this.all('*', Controller.Index.notFound);
        this.use(Controller.Index.internalServerError);
    }
}

module.exports = Router;
<commit_msg>remove router (gomi)<commit_after><|endoftext|>


<commit_before>var express = require('express');
var vhost = require('vhost');

var web = require('./website/server.js');

var app = express();
app.use(vhost('labeli.org',                 require('../website/server.js')));
app.use(vhost('www.labeli.org',             require('../website/server.js')));
app.use(vhost('api.labeli.org',             require('../api/api.js')));
app.use(vhost('hook.labeli.org',			require('./hook.js')));
app.listen(80);<commit_msg>Remove uneeded line<commit_after>var express = require('express');
var vhost = require('vhost');

var app = express();
app.use(vhost('labeli.org',                 require('../website/server.js')));
app.use(vhost('www.labeli.org',             require('../website/server.js')));
app.use(vhost('api.labeli.org',             require('../api/api.js')));
app.use(vhost('hook.labeli.org',			require('./hook.js')));
app.listen(80);<|endoftext|>


<commit_before>'use strict';

function ensureAuthenticated(req, res, next) {
  if (req.isAuthenticated()) {
    return next();
  }
  res.set('X-Auth-Required', 'true');
  req.session.returnUrl = req.originalUrl;
  res.redirect('/login/');
}

function ensureAdmin(req, res, next) {
  if (req.user.canPlayRoleOf('admin')) {
    return next();
  }
  res.redirect('/admin/');

}

function ensureAccount(req, res, next) {
  if (req.user.canPlayRoleOf('account')) {
    if (req.app.get('require-account-verification')) {
      if (req.user.roles.account.isVerified !== 'yes' && !/^\/account\/verification\//.test(req.url)) {
        return res.redirect('/account/verification/');
      }
    }
    return next();
  }
  res.redirect('/');
}

exports = module.exports = function(app, passport) {
  //front end
  app.get('/', require('./views/login/index').init);
  app.get('/about/', require('./views/about/index').init);
  app.get('/contact/', require('./views/contact/index').init);
  app.post('/contact/', require('./views/contact/index').sendMessage);

  //sign up
  app.get('/signup/', require('./views/signup/index').init);
  app.post('/signup/', require('./views/signup/index').signup);

  //social sign up
  app.post('/signup/social/', require('./views/signup/index').signupSocial);
  app.get('/signup/twitter/', passport.authenticate('twitter', { callbackURL: '/signup/twitter/callback/' }));
  app.get('/signup/twitter/callback/', require('./views/signup/index').signupTwitter);
  app.get('/signup/github/', passport.authenticate('github', { callbackURL: '/signup/github/callback/', scope: ['user:email'] }));
  app.get('/signup/github/callback/', require('./views/signup/index').signupGitHub);
  app.get('/signup/facebook/', passport.authenticate('facebook', { callbackURL: '/signup/facebook/callback/', scope: ['email'] }));
  app.get('/signup/facebook/callback/', require('./views/signup/index').signupFacebook);
  app.get('/signup/google/', passport.authenticate('google', { callbackURL: '/signup/google/callback/', scope: ['profile email'] }));
  app.get('/signup/google/callback/', require('./views/signup/index').signupGoogle);

  //login/out
  app.get('/login/', require('./views/login/index').init);
  app.post('/login/', require('./views/login/index').login);
  app.get('/login/forgot/', require('./views/login/forgot/index').init);
  app.post('/login/forgot/', require('./views/login/forgot/index').send);
  app.get('/login/reset/', require('./views/login/reset/index').init);
  app.get('/login/reset/:email/:token/', require('./views/login/reset/index').init);
  app.put('/login/reset/:email/:token/', require('./views/login/reset/index').set);
  app.get('/logout/', require('./views/logout/index').init);

  //social login
  app.get('/login/twitter/', passport.authenticate('twitter', { callbackURL: '/login/twitter/callback/' }));
  app.get('/login/twitter/callback/', require('./views/login/index').loginTwitter);
  app.get('/login/github/', passport.authenticate('github', { callbackURL: '/login/github/callback/' }));
  app.get('/login/github/callback/', require('./views/login/index').loginGitHub);
  app.get('/login/facebook/', passport.authenticate('facebook', { callbackURL: '/login/facebook/callback/' }));
  app.get('/login/facebook/callback/', require('./views/login/index').loginFacebook);
  app.get('/login/google/', passport.authenticate('google', { callbackURL: '/login/google/callback/', scope: ['profile email'] }));
  app.get('/login/google/callback/', require('./views/login/index').loginGoogle);

  //admin
  app.all('/admin*', ensureAuthenticated);
  app.all('/admin*', ensureAdmin);
  app.get('/admin/', require('./views/admin/index').init);

  //admin > users
  app.get('/admin/users/', require('./views/admin/users/index').find);
  app.post('/admin/users/', require('./views/admin/users/index').create);
  app.get('/admin/users/:id/', require('./views/admin/users/index').read);
  app.put('/admin/users/:id/', require('./views/admin/users/index').update);
  app.put('/admin/users/:id/password/', require('./views/admin/users/index').password);
  app.put('/admin/users/:id/role-admin/', require('./views/admin/users/index').linkAdmin);
  app.delete('/admin/users/:id/role-admin/', require('./views/admin/users/index').unlinkAdmin);
  app.put('/admin/users/:id/role-account/', require('./views/admin/users/index').linkAccount);
  app.delete('/admin/users/:id/role-account/', require('./views/admin/users/index').unlinkAccount);
  app.delete('/admin/users/:id/', require('./views/admin/users/index').delete);

  //admin > administrators
  app.get('/admin/administrators/', require('./views/admin/administrators/index').find);
  app.post('/admin/administrators/', require('./views/admin/administrators/index').create);
  app.get('/admin/administrators/:id/', require('./views/admin/administrators/index').read);
  app.put('/admin/administrators/:id/', require('./views/admin/administrators/index').update);
  app.put('/admin/administrators/:id/permissions/', require('./views/admin/administrators/index').permissions);
  app.put('/admin/administrators/:id/groups/', require('./views/admin/administrators/index').groups);
  app.put('/admin/administrators/:id/user/', require('./views/admin/administrators/index').linkUser);
  app.delete('/admin/administrators/:id/user/', require('./views/admin/administrators/index').unlinkUser);
  app.delete('/admin/administrators/:id/', require('./views/admin/administrators/index').delete);

  //admin > admin groups
  app.get('/admin/admin-groups/', require('./views/admin/admin-groups/index').find);
  app.post('/admin/admin-groups/', require('./views/admin/admin-groups/index').create);
  app.get('/admin/admin-groups/:id/', require('./views/admin/admin-groups/index').read);
  app.put('/admin/admin-groups/:id/', require('./views/admin/admin-groups/index').update);
  app.put('/admin/admin-groups/:id/permissions/', require('./views/admin/admin-groups/index').permissions);
  app.delete('/admin/admin-groups/:id/', require('./views/admin/admin-groups/index').delete);

  //admin > accounts
  app.get('/admin/accounts/', require('./views/admin/accounts/index').find);
  app.post('/admin/accounts/', require('./views/admin/accounts/index').create);
  app.get('/admin/accounts/:id/', require('./views/admin/accounts/index').read);
  app.put('/admin/accounts/:id/', require('./views/admin/accounts/index').update);
  app.put('/admin/accounts/:id/user/', require('./views/admin/accounts/index').linkUser);
  app.delete('/admin/accounts/:id/user/', require('./views/admin/accounts/index').unlinkUser);
  app.post('/admin/accounts/:id/notes/', require('./views/admin/accounts/index').newNote);
  app.post('/admin/accounts/:id/status/', require('./views/admin/accounts/index').newStatus);
  app.delete('/admin/accounts/:id/', require('./views/admin/accounts/index').delete);

  //admin > statuses
  app.get('/admin/statuses/', require('./views/admin/statuses/index').find);
  app.post('/admin/statuses/', require('./views/admin/statuses/index').create);
  app.get('/admin/statuses/:id/', require('./views/admin/statuses/index').read);
  app.put('/admin/statuses/:id/', require('./views/admin/statuses/index').update);
  app.delete('/admin/statuses/:id/', require('./views/admin/statuses/index').delete);

  //admin > categories
  app.get('/admin/categories/', require('./views/admin/categories/index').find);
  app.post('/admin/categories/', require('./views/admin/categories/index').create);
  app.get('/admin/categories/:id/', require('./views/admin/categories/index').read);
  app.put('/admin/categories/:id/', require('./views/admin/categories/index').update);
  app.delete('/admin/categories/:id/', require('./views/admin/categories/index').delete);

  //admin > search
  app.get('/admin/search/', require('./views/admin/search/index').find);

  //account
  app.all('/account*', ensureAuthenticated);
  app.all('/account*', ensureAccount);
  app.get('/account/', require('./views/account/index').init);

  //account > verification
  app.get('/account/verification/', require('./views/account/verification/index').init);
  app.post('/account/verification/', require('./views/account/verification/index').resendVerification);
  app.get('/account/verification/:token/', require('./views/account/verification/index').verify);

  //account > settings
  app.get('/account/settings/', require('./views/account/settings/index').init);
  app.put('/account/settings/', require('./views/account/settings/index').update);
  app.put('/account/settings/identity/', require('./views/account/settings/index').identity);
  app.put('/account/settings/password/', require('./views/account/settings/index').password);

  //account > settings > social
  app.get('/account/settings/twitter/', passport.authenticate('twitter', { callbackURL: '/account/settings/twitter/callback/' }));
  app.get('/account/settings/twitter/callback/', require('./views/account/settings/index').connectTwitter);
  app.get('/account/settings/twitter/disconnect/', require('./views/account/settings/index').disconnectTwitter);
  app.get('/account/settings/github/', passport.authenticate('github', { callbackURL: '/account/settings/github/callback/' }));
  app.get('/account/settings/github/callback/', require('./views/account/settings/index').connectGitHub);
  app.get('/account/settings/github/disconnect/', require('./views/account/settings/index').disconnectGitHub);
  app.get('/account/settings/facebook/', passport.authenticate('facebook', { callbackURL: '/account/settings/facebook/callback/' }));
  app.get('/account/settings/facebook/callback/', require('./views/account/settings/index').connectFacebook);
  app.get('/account/settings/facebook/disconnect/', require('./views/account/settings/index').disconnectFacebook);
  app.get('/account/settings/google/', passport.authenticate('google', { callbackURL: '/account/settings/google/callback/', scope: ['profile email'] }));
  app.get('/account/settings/google/callback/', require('./views/account/settings/index').connectGoogle);
  app.get('/account/settings/google/disconnect/', require('./views/account/settings/index').disconnectGoogle);

  app.all('/crud/*',ensureAdmin);
    //crud > params
  app.get('/crud/params/', require('./views/crud/params/index').find);
  app.post('/crud/params/', require('./views/crud/params/index').create);
  app.get('/crud/params/:id/', require('./views/crud/params/index').read);
  app.put('/crud/params/:id/', require('./views/crud/params/index').update);
  app.delete('/crud/params/:id/', require('./views/crud/params/index').delete);

  //crud > spreadsheets
  app.get('/crud/spreadsheets/', require('./views/crud/spreadsheets/index').find);
  app.post('/crud/spreadsheets/', require('./views/crud/spreadsheets/index').create);
  app.get('/crud/spreadsheets/:id/', require('./views/crud/spreadsheets/index').read);
  app.put('/crud/spreadsheets/:id/', require('./views/crud/spreadsheets/index').update);
  app.delete('/crud/spreadsheets/:id/', require('./views/crud/spreadsheets/index').delete);

  //crud > sheets
  app.get('/crud/sheets/', require('./views/crud/sheets/index').find);
  app.post('/crud/sheets/', require('./views/crud/sheets/index').create);
  app.get('/crud/sheets/:id/', require('./views/crud/sheets/index').read);
  app.put('/crud/sheets/:id/', require('./views/crud/sheets/index').update);
  app.delete('/crud/sheets/:id/', require('./views/crud/sheets/index').delete);

   //show > sheets
  app.all('/spreadsheets*',ensureAuthenticated);
  app.get('/spreadsheets/',require('./views/spreadsheets/index').init);
  app.get('/spreadsheets',require('./views/spreadsheets/index').init);
  app.get('/spreadsheets/:id/',require('./views/spreadsheets/index').readPopulateActiveSheet);
  app.post('/spreadsheets/:id/:sheetId/params',require('./views/spreadsheets/index').updateParams);
  app.post('/spreadsheets/:id/s/simulation',require('./views/spreadsheets/index').saveSimulationOnDb);
  app.post('/spreadsheets/:id/g/simulations',require('./views/spreadsheets/index').getSimulations);
  app.post('/spreadsheets/:id/l/simulation/:simulationId',require('./views/spreadsheets/index').getSimulation);

  app.post('/spreadsheets/activesheet/g/:sheetId',require('./views/spreadsheets/index').getActiveSheet);
  app.post('/spreadsheets/activesheet/:sheetId',require('./views/spreadsheets/index').setActiveSheet);
  app.post('/spreadsheets/activesheet/r/:sheetId',require('./views/spreadsheets/index').resetActiveSheet);

  app.get('/spreadsheets/:id/printable',require('./views/spreadsheets/index').getPrintablePage);

   //show > sheets
  app.all('/spreadsheets_v2*',ensureAuthenticated);
  app.get('/spreadsheets_v2/',require('./views/spreadsheets_v2/index').init);
  app.get('/spreadsheets_v2',require('./views/spreadsheets_v2/index').init);
  app.get('/spreadsheets_v2/:id/',require('./views/spreadsheets_v2/index').readPopulateActiveSheet);
  app.post('/spreadsheets_v2/:id/:sheetId/params',require('./views/spreadsheets_v2/index').updateParams);
  app.post('/spreadsheets_v2/:id/s/simulation',require('./views/spreadsheets_v2/index').saveSimulationOnDb);
  app.post('/spreadsheets_v2/:id/g/simulations',require('./views/spreadsheets_v2/index').getSimulations);
  app.post('/spreadsheets_v2/:id/l/simulation/:simulationId',require('./views/spreadsheets_v2/index').getSimulation);

  app.post('/spreadsheets_v2/activesheet/g/:sheetId',require('./views/spreadsheets_v2/index').getActiveSheet);
  app.post('/spreadsheets_v2/activesheet/:sheetId',require('./views/spreadsheets_v2/index').setActiveSheet);
  app.post('/spreadsheets_v2/activesheet/r/:sheetId',require('./views/spreadsheets_v2/index').resetActiveSheet);

  app.get('/spreadsheets_v2/:id/printable',require('./views/spreadsheets_v2/index').getPrintablePage);

//route not found
  app.all('*', require('./views/http/index').http404);
};
<commit_msg>routes<commit_after>'use strict';

function ensureAuthenticated(req, res, next) {
  if (req.isAuthenticated()) {
    return next();
  }
  res.set('X-Auth-Required', 'true');
  req.session.returnUrl = req.originalUrl;
  res.redirect('/login/');
}

function ensureAdmin(req, res, next) {
  if (req.user.canPlayRoleOf('admin')) {
    return next();
  }
  //res.redirect('/');

}

function ensureAccount(req, res, next) {
  if (req.user.canPlayRoleOf('account')) {
    if (req.app.get('require-account-verification')) {
      if (req.user.roles.account.isVerified !== 'yes' && !/^\/account\/verification\//.test(req.url)) {
        return res.redirect('/account/verification/');
      }
    }
    return next();
  }
  res.redirect('/');
}

exports = module.exports = function(app, passport) {
  //front end
  app.get('/', require('./views/login/index').init);
  app.get('/about/', require('./views/about/index').init);
  app.get('/contact/', require('./views/contact/index').init);
  app.post('/contact/', require('./views/contact/index').sendMessage);

  //sign up
  app.get('/signup/', require('./views/signup/index').init);
  app.post('/signup/', require('./views/signup/index').signup);

  //social sign up
  app.post('/signup/social/', require('./views/signup/index').signupSocial);
  app.get('/signup/twitter/', passport.authenticate('twitter', { callbackURL: '/signup/twitter/callback/' }));
  app.get('/signup/twitter/callback/', require('./views/signup/index').signupTwitter);
  app.get('/signup/github/', passport.authenticate('github', { callbackURL: '/signup/github/callback/', scope: ['user:email'] }));
  app.get('/signup/github/callback/', require('./views/signup/index').signupGitHub);
  app.get('/signup/facebook/', passport.authenticate('facebook', { callbackURL: '/signup/facebook/callback/', scope: ['email'] }));
  app.get('/signup/facebook/callback/', require('./views/signup/index').signupFacebook);
  app.get('/signup/google/', passport.authenticate('google', { callbackURL: '/signup/google/callback/', scope: ['profile email'] }));
  app.get('/signup/google/callback/', require('./views/signup/index').signupGoogle);

  //login/out
  app.get('/login/', require('./views/login/index').init);
  app.post('/login/', require('./views/login/index').login);
  app.get('/login/forgot/', require('./views/login/forgot/index').init);
  app.post('/login/forgot/', require('./views/login/forgot/index').send);
  app.get('/login/reset/', require('./views/login/reset/index').init);
  app.get('/login/reset/:email/:token/', require('./views/login/reset/index').init);
  app.put('/login/reset/:email/:token/', require('./views/login/reset/index').set);
  app.get('/logout/', require('./views/logout/index').init);

  //social login
  app.get('/login/twitter/', passport.authenticate('twitter', { callbackURL: '/login/twitter/callback/' }));
  app.get('/login/twitter/callback/', require('./views/login/index').loginTwitter);
  app.get('/login/github/', passport.authenticate('github', { callbackURL: '/login/github/callback/' }));
  app.get('/login/github/callback/', require('./views/login/index').loginGitHub);
  app.get('/login/facebook/', passport.authenticate('facebook', { callbackURL: '/login/facebook/callback/' }));
  app.get('/login/facebook/callback/', require('./views/login/index').loginFacebook);
  app.get('/login/google/', passport.authenticate('google', { callbackURL: '/login/google/callback/', scope: ['profile email'] }));
  app.get('/login/google/callback/', require('./views/login/index').loginGoogle);

  //admin
  app.all('/admin*', ensureAuthenticated);
  app.all('/admin*', ensureAdmin);
  app.get('/admin/', require('./views/admin/index').init);

  //admin > users
  app.get('/admin/users/', require('./views/admin/users/index').find);
  app.post('/admin/users/', require('./views/admin/users/index').create);
  app.get('/admin/users/:id/', require('./views/admin/users/index').read);
  app.put('/admin/users/:id/', require('./views/admin/users/index').update);
  app.put('/admin/users/:id/password/', require('./views/admin/users/index').password);
  app.put('/admin/users/:id/role-admin/', require('./views/admin/users/index').linkAdmin);
  app.delete('/admin/users/:id/role-admin/', require('./views/admin/users/index').unlinkAdmin);
  app.put('/admin/users/:id/role-account/', require('./views/admin/users/index').linkAccount);
  app.delete('/admin/users/:id/role-account/', require('./views/admin/users/index').unlinkAccount);
  app.delete('/admin/users/:id/', require('./views/admin/users/index').delete);

  //admin > administrators
  app.get('/admin/administrators/', require('./views/admin/administrators/index').find);
  app.post('/admin/administrators/', require('./views/admin/administrators/index').create);
  app.get('/admin/administrators/:id/', require('./views/admin/administrators/index').read);
  app.put('/admin/administrators/:id/', require('./views/admin/administrators/index').update);
  app.put('/admin/administrators/:id/permissions/', require('./views/admin/administrators/index').permissions);
  app.put('/admin/administrators/:id/groups/', require('./views/admin/administrators/index').groups);
  app.put('/admin/administrators/:id/user/', require('./views/admin/administrators/index').linkUser);
  app.delete('/admin/administrators/:id/user/', require('./views/admin/administrators/index').unlinkUser);
  app.delete('/admin/administrators/:id/', require('./views/admin/administrators/index').delete);

  //admin > admin groups
  app.get('/admin/admin-groups/', require('./views/admin/admin-groups/index').find);
  app.post('/admin/admin-groups/', require('./views/admin/admin-groups/index').create);
  app.get('/admin/admin-groups/:id/', require('./views/admin/admin-groups/index').read);
  app.put('/admin/admin-groups/:id/', require('./views/admin/admin-groups/index').update);
  app.put('/admin/admin-groups/:id/permissions/', require('./views/admin/admin-groups/index').permissions);
  app.delete('/admin/admin-groups/:id/', require('./views/admin/admin-groups/index').delete);

  //admin > accounts
  app.get('/admin/accounts/', require('./views/admin/accounts/index').find);
  app.post('/admin/accounts/', require('./views/admin/accounts/index').create);
  app.get('/admin/accounts/:id/', require('./views/admin/accounts/index').read);
  app.put('/admin/accounts/:id/', require('./views/admin/accounts/index').update);
  app.put('/admin/accounts/:id/user/', require('./views/admin/accounts/index').linkUser);
  app.delete('/admin/accounts/:id/user/', require('./views/admin/accounts/index').unlinkUser);
  app.post('/admin/accounts/:id/notes/', require('./views/admin/accounts/index').newNote);
  app.post('/admin/accounts/:id/status/', require('./views/admin/accounts/index').newStatus);
  app.delete('/admin/accounts/:id/', require('./views/admin/accounts/index').delete);

  //admin > statuses
  app.get('/admin/statuses/', require('./views/admin/statuses/index').find);
  app.post('/admin/statuses/', require('./views/admin/statuses/index').create);
  app.get('/admin/statuses/:id/', require('./views/admin/statuses/index').read);
  app.put('/admin/statuses/:id/', require('./views/admin/statuses/index').update);
  app.delete('/admin/statuses/:id/', require('./views/admin/statuses/index').delete);

  //admin > categories
  app.get('/admin/categories/', require('./views/admin/categories/index').find);
  app.post('/admin/categories/', require('./views/admin/categories/index').create);
  app.get('/admin/categories/:id/', require('./views/admin/categories/index').read);
  app.put('/admin/categories/:id/', require('./views/admin/categories/index').update);
  app.delete('/admin/categories/:id/', require('./views/admin/categories/index').delete);

  //admin > search
  app.get('/admin/search/', require('./views/admin/search/index').find);

  //account
  app.all('/account*', ensureAuthenticated);
  app.all('/account*', ensureAccount);
  app.get('/account/', require('./views/account/index').init);

  //account > verification
  app.get('/account/verification/', require('./views/account/verification/index').init);
  app.post('/account/verification/', require('./views/account/verification/index').resendVerification);
  app.get('/account/verification/:token/', require('./views/account/verification/index').verify);

  //account > settings
  app.get('/account/settings/', require('./views/account/settings/index').init);
  app.put('/account/settings/', require('./views/account/settings/index').update);
  app.put('/account/settings/identity/', require('./views/account/settings/index').identity);
  app.put('/account/settings/password/', require('./views/account/settings/index').password);

  //account > settings > social
  app.get('/account/settings/twitter/', passport.authenticate('twitter', { callbackURL: '/account/settings/twitter/callback/' }));
  app.get('/account/settings/twitter/callback/', require('./views/account/settings/index').connectTwitter);
  app.get('/account/settings/twitter/disconnect/', require('./views/account/settings/index').disconnectTwitter);
  app.get('/account/settings/github/', passport.authenticate('github', { callbackURL: '/account/settings/github/callback/' }));
  app.get('/account/settings/github/callback/', require('./views/account/settings/index').connectGitHub);
  app.get('/account/settings/github/disconnect/', require('./views/account/settings/index').disconnectGitHub);
  app.get('/account/settings/facebook/', passport.authenticate('facebook', { callbackURL: '/account/settings/facebook/callback/' }));
  app.get('/account/settings/facebook/callback/', require('./views/account/settings/index').connectFacebook);
  app.get('/account/settings/facebook/disconnect/', require('./views/account/settings/index').disconnectFacebook);
  app.get('/account/settings/google/', passport.authenticate('google', { callbackURL: '/account/settings/google/callback/', scope: ['profile email'] }));
  app.get('/account/settings/google/callback/', require('./views/account/settings/index').connectGoogle);
  app.get('/account/settings/google/disconnect/', require('./views/account/settings/index').disconnectGoogle);

  app.all('/crud/*',ensureAdmin);
    //crud > params
  app.get('/crud/params/', require('./views/crud/params/index').find);
  app.post('/crud/params/', require('./views/crud/params/index').create);
  app.get('/crud/params/:id/', require('./views/crud/params/index').read);
  app.put('/crud/params/:id/', require('./views/crud/params/index').update);
  app.delete('/crud/params/:id/', require('./views/crud/params/index').delete);

  //crud > spreadsheets
  app.get('/crud/spreadsheets/', require('./views/crud/spreadsheets/index').find);
  app.post('/crud/spreadsheets/', require('./views/crud/spreadsheets/index').create);
  app.get('/crud/spreadsheets/:id/', require('./views/crud/spreadsheets/index').read);
  app.put('/crud/spreadsheets/:id/', require('./views/crud/spreadsheets/index').update);
  app.delete('/crud/spreadsheets/:id/', require('./views/crud/spreadsheets/index').delete);

  //crud > sheets
  app.get('/crud/sheets/', require('./views/crud/sheets/index').find);
  app.post('/crud/sheets/', require('./views/crud/sheets/index').create);
  app.get('/crud/sheets/:id/', require('./views/crud/sheets/index').read);
  app.put('/crud/sheets/:id/', require('./views/crud/sheets/index').update);
  app.delete('/crud/sheets/:id/', require('./views/crud/sheets/index').delete);

   //show > sheets
  app.all('/spreadsheets*',ensureAuthenticated);
  app.get('/spreadsheets/',require('./views/spreadsheets/index').init);
  app.get('/spreadsheets',require('./views/spreadsheets/index').init);
  app.get('/spreadsheets/:id/',require('./views/spreadsheets/index').readPopulateActiveSheet);
  app.post('/spreadsheets/:id/:sheetId/params',require('./views/spreadsheets/index').updateParams);
  app.post('/spreadsheets/:id/s/simulation',require('./views/spreadsheets/index').saveSimulationOnDb);
  app.post('/spreadsheets/:id/g/simulations',require('./views/spreadsheets/index').getSimulations);
  app.post('/spreadsheets/:id/l/simulation/:simulationId',require('./views/spreadsheets/index').getSimulation);

  app.post('/spreadsheets/activesheet/g/:sheetId',require('./views/spreadsheets/index').getActiveSheet);
  app.post('/spreadsheets/activesheet/:sheetId',require('./views/spreadsheets/index').setActiveSheet);
  app.post('/spreadsheets/activesheet/r/:sheetId',require('./views/spreadsheets/index').resetActiveSheet);

  app.get('/spreadsheets/:id/printable',require('./views/spreadsheets/index').getPrintablePage);

   //show > sheets
  app.all('/spreadsheets_v2*',ensureAuthenticated);
  app.get('/spreadsheets_v2/',require('./views/spreadsheets_v2/index').init);
  app.get('/spreadsheets_v2',require('./views/spreadsheets_v2/index').init);
  app.get('/spreadsheets_v2/:id/',require('./views/spreadsheets_v2/index').readPopulateActiveSheet);
  app.post('/spreadsheets_v2/:id/:sheetId/params',require('./views/spreadsheets_v2/index').updateParams);
  app.post('/spreadsheets_v2/:id/s/simulation',require('./views/spreadsheets_v2/index').saveSimulationOnDb);
  app.post('/spreadsheets_v2/:id/g/simulations',require('./views/spreadsheets_v2/index').getSimulations);
  app.post('/spreadsheets_v2/:id/l/simulation/:simulationId',require('./views/spreadsheets_v2/index').getSimulation);

  app.post('/spreadsheets_v2/activesheet/g/:sheetId',require('./views/spreadsheets_v2/index').getActiveSheet);
  app.post('/spreadsheets_v2/activesheet/:sheetId',require('./views/spreadsheets_v2/index').setActiveSheet);
  app.post('/spreadsheets_v2/activesheet/r/:sheetId',require('./views/spreadsheets_v2/index').resetActiveSheet);

  app.get('/spreadsheets_v2/:id/printable',require('./views/spreadsheets_v2/index').getPrintablePage);

//route not found
  app.all('*', require('./views/http/index').http404);
};
<|endoftext|>


<commit_before>(function (rquery) {
  // Module systems magic dance.
  if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
    // NodeJS
    module.exports = rquery;
  } else if (typeof define === "function" && define.amd) {
    // AMD
    define(['react', 'lodash'], function (React, _) {
      return rquery(_, React);
    });
  } else {
    // Other environment (usually <script> tag): assume React is already loaded.
    window.$R = rquery(window._, React);
  }
}(function (_, React) {
  'use strict';

  var TestUtils = React.addons.TestUtils;

  function isArray (arr) {
    return Object.prototype.toString.call(arr) === '[object Array]';
  }

  function getDescendents (components, includeSelf) {
    return _(components)
      .map(function (component) {
        var components = TestUtils.findAllInRenderedTree(component, function () {
          return true;
        });

        if (!includeSelf) {
          components.shift();
        }

        return components;
      })
      .flatten()
      .uniq()
      .value();
  }

  function includeCompositeComponents (component) {
    if (component._renderedComponent) {
      return [component, component._renderedComponent];
    }

    return [component];
  }

  var STEP_DEFINITIONS = [
    // scope modifiers
    {
      matcher: /^\s*>\s*/,
      runStep: function (context, match) {
        var newScope = _(context.currentScope)
            .map(function (component) {
              var depth = component._reactInternalInstance._rootNodeID.split('.').length;

              return TestUtils.findAllInRenderedTree(component, function (descendent) {
                var descendentDepth = descendent._reactInternalInstance._rootNodeID.split('.').length;
                return depth + 1 === descendentDepth;
              });
            })
            .compact()
            .flatten()
            .map(includeCompositeComponents)
            .flatten()
            .value();

        context.setScope(newScope);
      }
    },
    {
      matcher: /^,\s*/,
      runStep: function (context, match) {
        context.saveResults();
        context.resetScope();
      }
    },
    {
      matcher: /^\s+/,
      runStep: function (context, match) {
        var newScope = getDescendents(context.currentScope, false);
        context.setScope(newScope);
      }
    },

    // selectors
    {
      matcher: /^([A-Z]\w*)/,
      runStep: function (context, match) {
        context.filterScope(function (component) {
          if (TestUtils.isCompositeComponent(component)) {
            return component._reactInternalInstance
                && component._reactInternalInstance._currentElement
                && component._reactInternalInstance._currentElement.type
                && component._reactInternalInstance._currentElement.type.displayName === match[1];
          }

          return false;
        });
      }
    },
    {
      matcher: /^([a-z]\w*)/,
      runStep: function (context, match) {
        context.filterScope(function (component) {
          if (TestUtils.isDOMComponent(component)) {
            return component.getDOMNode().tagName === match[1].toUpperCase();
          }

          return false;
        });
      }
    },
    {
      matcher: /^\.([^\s]+)/,
      runStep: function (context, match) {
        context.filterScope(function (component) {
          if (TestUtils.isDOMComponent(component)
              && component.props.className) {
            var classes = component.props.className.split(' ');
            return classes.indexOf(match[1]) !== -1;
          }

          return false;
        });
      }
    },
    {
      matcher: /^\[([^\s~|^$*=]+)(?:([~|^$*]?=)"((?:\\"|.)*)")?\]/,
      runStep: function (context, match) {
        context.filterScope(function (component) {
          var propName = match[1] === 'class' ? 'className' : match[1],
              hasProp = TestUtils.isDOMComponent(component)
                        && propName in component.props;

          if (match[2]) {
            var value = match[3].replace('\\"', '"'),
                prop = String(component.props[propName]);

            switch (match[2]) {
              case '=':
                return prop === value;

              case '~=':
                return prop.split(/\s+/).indexOf(value) !== -1;

              case '|=':
                return prop === value || prop.indexOf(value + '-') === 0;

              case '^=':
                return prop.indexOf(value) === 0;

              case '$=':
                return prop.indexOf(value) === prop.length - value.length;

              case '*=':
                return prop.indexOf(value) !== -1;

              default:
                throw new Error('Unknown attribute operator: ' + operator);
                break;
            }
          }

          return hasProp;
        });
      }
    },
    {
      matcher: /^:contains\(((?:\\\)|.)*)\)/,
      runStep: function (context, match) {
        context.filterScope(function (component) {
          return $R(component).text().indexOf(match[1]) !== -1;
        });
      }
    }
  ];

  function isEmptyString (str) {
    return /^\s*$/.test(str);
  }

  function parseNextStep (selector) {
    var match, step;

    for (var i = 0; i < STEP_DEFINITIONS.length; i++) {
      step = STEP_DEFINITIONS[i];
      match = selector.match(step.matcher);
      if (match) {
        return {
          match: match,
          step: step
        };
      }
    }
  }

  function buildSteps (selector) {
    var step,
        steps = [];

    while (!isEmptyString(selector)) {
      step = parseNextStep(selector);

      if (step) {
        steps.push(step);
        selector = selector.substr(step.match[0].length);
      } else {
        throw new Error('Failed to parse selector at: ' + selector);
      }
    }

    return steps;
  }

  function Context (rootComponents) {
    this.rootComponents = rootComponents;
    this.results = [];
    this.defaultScope = getDescendents(rootComponents, true);
    this.resetScope();
  }

  Context.prototype.setScope = function (scope) {
    this.currentScope = _(scope)
      .map(includeCompositeComponents)
      .flatten()
      .value();
  };

  Context.prototype.resetScope = function () {
    this.setScope(this.defaultScope);
  };

  Context.prototype.filterScope = function (predicate) {
    this.currentScope = this.currentScope.filter(predicate);
  };

  Context.prototype.saveResults = function () {
    this.results = _.union(this.results, this.currentScope);
  };

  function rquery (components) {
    if (!isArray(components)) {
      if (components) {
        components = [components];
      } else {
        components = [];
      }
    }

    this.components = components;
    this.length = components.length;

    for (var i = 0; i < components.length; i++) {
      this[i] = components[i];
    }
  }

  rquery.prototype.find = function (selector) {
    var steps = buildSteps(selector),
        context = new Context(this.components);

    steps.forEach(function (step) {
      step.step.runStep(context, step.match);
    });

    context.saveResults();

    return new rquery(context.results);
  };

  rquery.prototype.findComponent = function (type) {
    return this._generate(function (component) {
      return TestUtils.isCompositeComponentWithType(component, type);
    });
  };

  rquery.prototype.get = function (index) {
    return this.components[index];
  };

  rquery.prototype.at = function (index) {
    return new rquery(this.components[index]);
  };

  rquery.prototype._generate = function (predicate) {
    var matches = [].concat.apply([], this.components.map(function (component) {
      return TestUtils.findAllInRenderedTree(component, predicate);
    }));

    return new rquery(matches);
  };

  rquery.prototype.simulateEvent = function (eventName, eventData) {
    for (var i = 0; i < this.components.length; i++) {
      TestUtils.Simulate[eventName](this.components[i].getDOMNode(), eventData);
    }

    return this;
  };

  rquery.prototype.text = function () {
    return _.map(this.components, function(component) {
      return component.getDOMNode().innerText || component.getDOMNode().textContent;
    }).join('');
  };

  var EVENT_NAMES = [
    // clipboard events
    'copy', 'cut', 'paste',
    // keyboard events
    'keyDown', 'keyPress', 'keyUp',
    // focus events
    'focus', 'blur',
    // form events
    'change', 'input', 'submit',
    // mouse events
    'click', 'mouseDown', 'mouseEnter', 'mouseLeave', 'mouseMove', 'mouseOut', 'mouseOver', 'mouseUp',
    'doubleClick', 'drag', 'dragEnd', 'dragEnter', 'dragExit', 'dragLeave', 'dragOver', 'dragStart', 'drop',
    // touch events
    'touchCancel', 'touchEnd', 'touchMove', 'touchStart',
    // UI events
    'scroll',
    // wheel events
    'wheel'
  ];

  EVENT_NAMES.forEach(function (eventName) {
    rquery.prototype[eventName] = function (eventData) {
      return this.simulateEvent(eventName, eventData);
    };
  });

  var $R = function (components, selector) {
    var $r = new rquery(components);

    if (selector) {
      return $r.find(selector);
    }

    return $r;
  };

  $R.isRQuery = function (obj) {
    return obj instanceof rquery;
  };

  return $R;
}));
<commit_msg>Don't match : in class selector<commit_after>(function (rquery) {
  // Module systems magic dance.
  if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
    // NodeJS
    module.exports = rquery;
  } else if (typeof define === "function" && define.amd) {
    // AMD
    define(['react', 'lodash'], function (React, _) {
      return rquery(_, React);
    });
  } else {
    // Other environment (usually <script> tag): assume React is already loaded.
    window.$R = rquery(window._, React);
  }
}(function (_, React) {
  'use strict';

  var TestUtils = React.addons.TestUtils;

  function isArray (arr) {
    return Object.prototype.toString.call(arr) === '[object Array]';
  }

  function getDescendents (components, includeSelf) {
    return _(components)
      .map(function (component) {
        var components = TestUtils.findAllInRenderedTree(component, function () {
          return true;
        });

        if (!includeSelf) {
          components.shift();
        }

        return components;
      })
      .flatten()
      .uniq()
      .value();
  }

  function includeCompositeComponents (component) {
    if (component._renderedComponent) {
      return [component, component._renderedComponent];
    }

    return [component];
  }

  var STEP_DEFINITIONS = [
    // scope modifiers
    {
      matcher: /^\s*>\s*/,
      runStep: function (context, match) {
        var newScope = _(context.currentScope)
            .map(function (component) {
              var depth = component._reactInternalInstance._rootNodeID.split('.').length;

              return TestUtils.findAllInRenderedTree(component, function (descendent) {
                var descendentDepth = descendent._reactInternalInstance._rootNodeID.split('.').length;
                return depth + 1 === descendentDepth;
              });
            })
            .compact()
            .flatten()
            .map(includeCompositeComponents)
            .flatten()
            .value();

        context.setScope(newScope);
      }
    },
    {
      matcher: /^,\s*/,
      runStep: function (context, match) {
        context.saveResults();
        context.resetScope();
      }
    },
    {
      matcher: /^\s+/,
      runStep: function (context, match) {
        var newScope = getDescendents(context.currentScope, false);
        context.setScope(newScope);
      }
    },

    // selectors
    {
      matcher: /^([A-Z]\w*)/,
      runStep: function (context, match) {
        context.filterScope(function (component) {
          if (TestUtils.isCompositeComponent(component)) {
            return component._reactInternalInstance
                && component._reactInternalInstance._currentElement
                && component._reactInternalInstance._currentElement.type
                && component._reactInternalInstance._currentElement.type.displayName === match[1];
          }

          return false;
        });
      }
    },
    {
      matcher: /^([a-z]\w*)/,
      runStep: function (context, match) {
        context.filterScope(function (component) {
          if (TestUtils.isDOMComponent(component)) {
            return component.getDOMNode().tagName === match[1].toUpperCase();
          }

          return false;
        });
      }
    },
    {
      matcher: /^\.([^\s:]+)/,
      runStep: function (context, match) {
        context.filterScope(function (component) {
          if (TestUtils.isDOMComponent(component)
              && component.props.className) {
            var classes = component.props.className.split(' ');
            return classes.indexOf(match[1]) !== -1;
          }

          return false;
        });
      }
    },
    {
      matcher: /^\[([^\s~|^$*=]+)(?:([~|^$*]?=)"((?:\\"|.)*)")?\]/,
      runStep: function (context, match) {
        context.filterScope(function (component) {
          var propName = match[1] === 'class' ? 'className' : match[1],
              hasProp = TestUtils.isDOMComponent(component)
                        && propName in component.props;

          if (match[2]) {
            var value = match[3].replace('\\"', '"'),
                prop = String(component.props[propName]);

            switch (match[2]) {
              case '=':
                return prop === value;

              case '~=':
                return prop.split(/\s+/).indexOf(value) !== -1;

              case '|=':
                return prop === value || prop.indexOf(value + '-') === 0;

              case '^=':
                return prop.indexOf(value) === 0;

              case '$=':
                return prop.indexOf(value) === prop.length - value.length;

              case '*=':
                return prop.indexOf(value) !== -1;

              default:
                throw new Error('Unknown attribute operator: ' + operator);
                break;
            }
          }

          return hasProp;
        });
      }
    },
    {
      matcher: /^:contains\(((?:\\\)|.)*)\)/,
      runStep: function (context, match) {
        context.filterScope(function (component) {
          return $R(component).text().indexOf(match[1]) !== -1;
        });
      }
    }
  ];

  function isEmptyString (str) {
    return /^\s*$/.test(str);
  }

  function parseNextStep (selector) {
    var match, step;

    for (var i = 0; i < STEP_DEFINITIONS.length; i++) {
      step = STEP_DEFINITIONS[i];
      match = selector.match(step.matcher);
      if (match) {
        return {
          match: match,
          step: step
        };
      }
    }
  }

  function buildSteps (selector) {
    var step,
        steps = [];

    while (!isEmptyString(selector)) {
      step = parseNextStep(selector);

      if (step) {
        steps.push(step);
        selector = selector.substr(step.match[0].length);
      } else {
        throw new Error('Failed to parse selector at: ' + selector);
      }
    }

    return steps;
  }

  function Context (rootComponents) {
    this.rootComponents = rootComponents;
    this.results = [];
    this.defaultScope = getDescendents(rootComponents, true);
    this.resetScope();
  }

  Context.prototype.setScope = function (scope) {
    this.currentScope = _(scope)
      .map(includeCompositeComponents)
      .flatten()
      .value();
  };

  Context.prototype.resetScope = function () {
    this.setScope(this.defaultScope);
  };

  Context.prototype.filterScope = function (predicate) {
    this.currentScope = this.currentScope.filter(predicate);
  };

  Context.prototype.saveResults = function () {
    this.results = _.union(this.results, this.currentScope);
  };

  function rquery (components) {
    if (!isArray(components)) {
      if (components) {
        components = [components];
      } else {
        components = [];
      }
    }

    this.components = components;
    this.length = components.length;

    for (var i = 0; i < components.length; i++) {
      this[i] = components[i];
    }
  }

  rquery.prototype.find = function (selector) {
    var steps = buildSteps(selector),
        context = new Context(this.components);

    steps.forEach(function (step) {
      step.step.runStep(context, step.match);
    });

    context.saveResults();

    return new rquery(context.results);
  };

  rquery.prototype.findComponent = function (type) {
    return this._generate(function (component) {
      return TestUtils.isCompositeComponentWithType(component, type);
    });
  };

  rquery.prototype.get = function (index) {
    return this.components[index];
  };

  rquery.prototype.at = function (index) {
    return new rquery(this.components[index]);
  };

  rquery.prototype._generate = function (predicate) {
    var matches = [].concat.apply([], this.components.map(function (component) {
      return TestUtils.findAllInRenderedTree(component, predicate);
    }));

    return new rquery(matches);
  };

  rquery.prototype.simulateEvent = function (eventName, eventData) {
    for (var i = 0; i < this.components.length; i++) {
      TestUtils.Simulate[eventName](this.components[i].getDOMNode(), eventData);
    }

    return this;
  };

  rquery.prototype.text = function () {
    return _.map(this.components, function(component) {
      return component.getDOMNode().innerText || component.getDOMNode().textContent;
    }).join('');
  };

  var EVENT_NAMES = [
    // clipboard events
    'copy', 'cut', 'paste',
    // keyboard events
    'keyDown', 'keyPress', 'keyUp',
    // focus events
    'focus', 'blur',
    // form events
    'change', 'input', 'submit',
    // mouse events
    'click', 'mouseDown', 'mouseEnter', 'mouseLeave', 'mouseMove', 'mouseOut', 'mouseOver', 'mouseUp',
    'doubleClick', 'drag', 'dragEnd', 'dragEnter', 'dragExit', 'dragLeave', 'dragOver', 'dragStart', 'drop',
    // touch events
    'touchCancel', 'touchEnd', 'touchMove', 'touchStart',
    // UI events
    'scroll',
    // wheel events
    'wheel'
  ];

  EVENT_NAMES.forEach(function (eventName) {
    rquery.prototype[eventName] = function (eventData) {
      return this.simulateEvent(eventName, eventData);
    };
  });

  var $R = function (components, selector) {
    var $r = new rquery(components);

    if (selector) {
      return $r.find(selector);
    }

    return $r;
  };

  $R.isRQuery = function (obj) {
    return obj instanceof rquery;
  };

  return $R;
}));
<|endoftext|>


<commit_before>var checkForSyntaxError = require('syntax-error');
var vm = require("vm");

/**
 * http://nodejs.org/api/vm.html
 * http://izs.me/v8-docs/classv8_1_1Context.html#_details
 * https://github.com/substack/node-syntax-error
 * See also:
 * 	https://github.com/substack/node-burrito
 * 	https://npmjs.org/package/funex
 *
 */
exports.run = function($api, api, script) {
	"use strict";

	var result = '';
//	var error = checkForSyntaxError(jsCode);
	var error = null;

	if (error) {
		result = 'JAVASCRIPT SYNTAX ERROR[' + api +']: ' + error;
	} else {
		try {
			if ('127.0.0.1' == $api.host) {
				result = eval(script);
			} else {
				result = vm.runInNewContext(jsCode, {"$api": $api}).toString();
			}
		} catch (error) {
			$api.end(result = 'JAVASCRIPT RUNTIME ERROR[' + api +']: ' + error.type);
		}
	}
	return result;
}
<commit_msg>Changed $api.end() to $api.out() - there was no end().<commit_after>var checkForSyntaxError = require('syntax-error');
var vm = require("vm");

/**
 * http://nodejs.org/api/vm.html
 * http://izs.me/v8-docs/classv8_1_1Context.html#_details
 * https://github.com/substack/node-syntax-error
 * See also:
 * 	https://github.com/substack/node-burrito
 * 	https://npmjs.org/package/funex
 *
 */
exports.run = function($api, api, script) {
	"use strict";

	var result = '';
//	var error = checkForSyntaxError(jsCode);
	var error = null;

	if (error) {
		result = 'JAVASCRIPT SYNTAX ERROR[' + api +']: ' + error;
	} else {
		try {
			if ('127.0.0.1' == $api.host) {
				result = eval(script);
			} else {
				result = vm.runInNewContext(jsCode, {"$api": $api}).toString();
			}
		} catch (error) {
			$api.out(result = 'JAVASCRIPT RUNTIME ERROR[' + api +']: ' + error.type);
		}
	}
	return result;
}
<|endoftext|>


<commit_before>module.exports = Runner

var fs = require("fs")
  , child_process = require("child_process")
  , path = require("path")
  , chain = require("slide").chain
  , TapProducer = require("tap-producer")
  , TapConsumer = require("tap-consumer")
  , assert = require("tap-assert")
  , inherits = require("inherits")

inherits(Runner, TapProducer)

function Runner (dir, diag, cb) {
  Runner.super.call(this, diag)

  if (dir) this.run(dir, cb)
}

Runner.prototype.run = function () {
  var self = this
    , args = Array.prototype.slice.call(arguments)
    , cb = args.pop() || function (er) {
        if (er) self.emit("error", er)
        self.end()
      }
  if (Array.isArray(args[0])) args = args[0]
  self.runFiles(args, "", cb)
}

Runner.prototype.runDir = function (dir, cb) {
  var self = this
  fs.readdir(dir, function (er, files) {
    if (er) {
      self.write(assert.fail("failed to readdir "+dir,
                           { error: er }))
      self.end()
      return
    }
    files = files.sort(function (a,b) {return a>b ? 1 : -1})
    files = files.filter(function (f) {return !f.match(/^\./)})
    files = files.map(path.resolve.bind(path, dir))

    self.runFiles(files, path.resolve(dir), cb)
  })
}

Runner.prototype.runFiles = function (files, dir, cb) {

  var self = this
  chain(files.map(function (f) { return function (cb) {
    var relDir = dir || path.dirname(f)
      , fileName = relDir === "." ? f : f.substr(relDir.length + 1)

    self.write(fileName)
    fs.lstat(f, function (er, st) {
      if (er) {
        self.write(assert.fail("failed to stat "+f,
                               {error: er}))
        return cb()
      }

      var cmd = f
        , args = []

      if (path.extname(f) === ".js") {
        cmd = "node"
        args = [f]
      } else if (path.extname(f) === ".coffee") {
        cmd = "coffee"
        args = [f]
      }
      if (st.isDirectory()) {
        return self.runDir(f, cb)
      }

      var env = {}
      for (var i in process.env) env[i] = process.env[i]
      env.TAP = 1

      var cp = child_process.spawn(cmd, args, { env: env, cwd: relDir })
        , out = ""
        , err = ""
        , tc = new TapConsumer
        , childTests = [f]

      tc.on("data", function (c) {
        self.emit("result", c)
        self.write(c)
      })

      cp.stdout.pipe(tc)
      cp.stdout.on("data", function (c) { out += c })
      cp.stderr.on("data", function (c) { err += c })

      cp.on("exit", function (code) {
        //childTests.forEach(function (c) { self.write(c) })
        var res = { name: fileName
                  , ok: !code }
        if (err) {
          res.stderr = err
          if (tc.results.ok && tc.results.tests === 0) {
            // perhaps a compilation error or something else failed...
            console.error(err)
          }
        }
        res.command = [cmd].concat(args).map(JSON.stringify).join(" ")
        self.emit("result", res)
        self.emit("file", f, res, tc.results)
        self.write(res)
        self.write("\n")
        cb()
      })
    })
  }}), cb)

  return self
}
<commit_msg>Pass the proper relative filename to node when running tests<commit_after>module.exports = Runner

var fs = require("fs")
  , child_process = require("child_process")
  , path = require("path")
  , chain = require("slide").chain
  , TapProducer = require("tap-producer")
  , TapConsumer = require("tap-consumer")
  , assert = require("tap-assert")
  , inherits = require("inherits")

inherits(Runner, TapProducer)

function Runner (dir, diag, cb) {
  Runner.super.call(this, diag)

  if (dir) this.run(dir, cb)
}

Runner.prototype.run = function () {
  var self = this
    , args = Array.prototype.slice.call(arguments)
    , cb = args.pop() || function (er) {
        if (er) self.emit("error", er)
        self.end()
      }
  if (Array.isArray(args[0])) args = args[0]
  self.runFiles(args, "", cb)
}

Runner.prototype.runDir = function (dir, cb) {
  var self = this
  fs.readdir(dir, function (er, files) {
    if (er) {
      self.write(assert.fail("failed to readdir "+dir,
                           { error: er }))
      self.end()
      return
    }
    files = files.sort(function (a,b) {return a>b ? 1 : -1})
    files = files.filter(function (f) {return !f.match(/^\./)})
    files = files.map(path.resolve.bind(path, dir))

    self.runFiles(files, path.resolve(dir), cb)
  })
}

Runner.prototype.runFiles = function (files, dir, cb) {

  var self = this
  chain(files.map(function (f) { return function (cb) {
    var relDir = dir || path.dirname(f)
      , fileName = relDir === "." ? f : f.substr(relDir.length + 1)

    self.write(fileName)
    fs.lstat(f, function (er, st) {
      if (er) {
        self.write(assert.fail("failed to stat "+f,
                               {error: er}))
        return cb()
      }

      var cmd = f
        , args = []

      if (path.extname(f) === ".js") {
        cmd = "node"
        args = [fileName]
      } else if (path.extname(f) === ".coffee") {
        cmd = "coffee"
        args = [fileName]
      }
      if (st.isDirectory()) {
        return self.runDir(f, cb)
      }

      var env = {}
      for (var i in process.env) env[i] = process.env[i]
      env.TAP = 1

      var cp = child_process.spawn(cmd, args, { env: env, cwd: relDir })
        , out = ""
        , err = ""
        , tc = new TapConsumer
        , childTests = [f]

      tc.on("data", function (c) {
        self.emit("result", c)
        self.write(c)
      })

      cp.stdout.pipe(tc)
      cp.stdout.on("data", function (c) { out += c })
      cp.stderr.on("data", function (c) { err += c })

      cp.on("exit", function (code) {
        //childTests.forEach(function (c) { self.write(c) })
        var res = { name: fileName
                  , ok: !code }
        if (err) {
          res.stderr = err
          if (tc.results.ok && tc.results.tests === 0) {
            // perhaps a compilation error or something else failed...
            console.error(err)
          }
        }
        res.command = [cmd].concat(args).map(JSON.stringify).join(" ")
        self.emit("result", res)
        self.emit("file", f, res, tc.results)
        self.write(res)
        self.write("\n")
        cb()
      })
    })
  }}), cb)

  return self
}
<|endoftext|>