<commit_before>'use strict';

var Controllers = require('./modules/controllers/controllers');
var Static = require('./modules/static');
var Workers = require('./modules/workers/workers');
var Models = require('./modules/models/models');
var API = require('./modules/api');
var Bridge = require('./modules/bridge');
var Templates = require('./modules/templates');
var SEO = require('./modules/seo');

var Model = require('./modules/models/model');
var Controller = require('./modules/controllers/controller');

var Bridge = require('./modules/bridge');

var config = require('./helpers/config');
var fire = require('./firestarter');

var util = require('util');
var inflection = require('inflection');
var express = require('express');

var Q = require('q');

var debug = require('debug')('fire:app');

exports = module.exports = App;

function App(name, options) {
	this.name = name || 'app';
	this.options = options || {};

	this.modules = [];

	if(!this.options.disabled) {
		debug('App is not disabled.');

		this.express = express();
		this.express.disable('x-powered-by');
	}
	else {
		debug('App is disabled.');
	}

	this.addModule(SEO);
	this.addModule(Templates);
	this.addModule(Workers);
	this.addModule(Models);
	this.addModule(API);
	this.addModule(Static);
	this.addModule(Controllers);
	this.addModule(Bridge);
}

App.prototype.model = function(modelConstructor) {
	// TODO: Move this to the models module.
	util.inherits(modelConstructor, Model);

	var self = this;
	setImmediate(function() {
		self.addModelConstructor(modelConstructor);
	});
};

App.prototype.controller = function(controllerConstructor) {
	// Move this to the controllers module.
	util.inherits(controllerConstructor, Controller);

	var self = this;
	setImmediate(function() {
		self.addControllerConstructor(controllerConstructor);
	});
};

App.prototype.addModel = function(modelName, model) {
	debug('App#addModel `' + modelName + '`');

	var result = Q.when(true);

	this.modules.forEach(function(module_) {
		if(module_.addModel) {
			result = result.then(function() {
				return Q.when(module_.addModel(modelName, model));
			});
		}
	});

	return result;
};

App.prototype.addControllerConstructor = function(controllerConstructor) {
	debug('App#addControllerConstructor `' + controllerConstructor.name + '`');

	this.modules.forEach(function(module_) {
		if(module_.addControllerConstructor) {
			module_.addControllerConstructor(controllerConstructor);
		}
	});
};

App.prototype.addModelConstructor = function(modelConstructor) {
	debug('App#addModelConstructor `' + modelConstructor.name + '`');

	this.modules.forEach(function(module_) {
		if(module_.addModelConstructor) {
			module_.addModelConstructor(modelConstructor);
		}
	});
};

App.prototype.addModule = function(moduleConstructor) {
	if(this.options.disabled && !moduleConstructor.prototype.ignoreDisabled) {
		debug('Not loading module `' + moduleConstructor.name + '`.');
	}
	else {
		var module_ = new moduleConstructor(this);
		this.modules.push(module_);

		// We get the name of the property based on the name of the constructor
		var propertyName = inflection.camelize(moduleConstructor.name, true);

		Object.defineProperty(this, propertyName, {
			value: module_
		});
	}
};

App.prototype._setup = function() {
	debug('App#_setup');

	var result = Q.when(true);

	var self = this;
	this.modules.forEach(function(module_) {
		result = result.then(function() {
			// TODO: Create a noop.
			return Q.when((module_.setup || function(){}).call(module_, config.basePath));
		});
	});

	return result
		.then(function() {
			return self.configure(process.env.NODE_ENV || 'development');
		});
};

App.prototype.configure = function() {};

App.prototype.stop = function() {
	var defer = Q.defer();
	fire._app = null;

	if(this.server) {
		this.server.close(defer.makeNodeResolver());
	}
	else {
		defer.resolve();
	}

	return defer.promise;
};<commit_msg>implement configure functions during startup<commit_after>'use strict';

var Controllers = require('./modules/controllers/controllers');
var Static = require('./modules/static');
var Workers = require('./modules/workers/workers');
var Models = require('./modules/models/models');
var API = require('./modules/api');
var Bridge = require('./modules/bridge');
var Templates = require('./modules/templates');
var SEO = require('./modules/seo');

var Model = require('./modules/models/model');
var Controller = require('./modules/controllers/controller');

var Bridge = require('./modules/bridge');

var config = require('./helpers/config');
var fire = require('./firestarter');

var util = require('util');
var inflection = require('inflection');
var express = require('express');

var Q = require('q');

var debug = require('debug')('fire:app');

exports = module.exports = App;

function App(name, options) {
	this.name = name || 'app';
	this.options = options || {};
	this.modules = [];
	this._configureFunctions = [];

	if(!this.options.disabled) {
		debug('App is not disabled.');

		this.express = express();
		this.express.disable('x-powered-by');
	}
	else {
		debug('App is disabled.');
	}

	this.addModule(SEO);
	this.addModule(Templates);
	this.addModule(Workers);
	this.addModule(Models);
	this.addModule(API);
	this.addModule(Static);
	this.addModule(Controllers);
	this.addModule(Bridge);
}

App.prototype.model = function(modelConstructor) {
	// TODO: Move this to the models module.
	util.inherits(modelConstructor, Model);

	var self = this;
	setImmediate(function() {
		self.addModelConstructor(modelConstructor);
	});
};

App.prototype.controller = function(controllerConstructor) {
	// Move this to the controllers module.
	util.inherits(controllerConstructor, Controller);

	var self = this;
	setImmediate(function() {
		self.addControllerConstructor(controllerConstructor);
	});
};

App.prototype.addModel = function(modelName, model) {
	debug('App#addModel `' + modelName + '`');

	var result = Q.when(true);

	this.modules.forEach(function(module_) {
		if(module_.addModel) {
			result = result.then(function() {
				return Q.when(module_.addModel(modelName, model));
			});
		}
	});

	return result;
};

App.prototype.addControllerConstructor = function(controllerConstructor) {
	debug('App#addControllerConstructor `' + controllerConstructor.name + '`');

	this.modules.forEach(function(module_) {
		if(module_.addControllerConstructor) {
			module_.addControllerConstructor(controllerConstructor);
		}
	});
};

App.prototype.addModelConstructor = function(modelConstructor) {
	debug('App#addModelConstructor `' + modelConstructor.name + '`');

	this.modules.forEach(function(module_) {
		if(module_.addModelConstructor) {
			module_.addModelConstructor(modelConstructor);
		}
	});
};

App.prototype.addModule = function(moduleConstructor) {
	if(this.options.disabled && !moduleConstructor.prototype.ignoreDisabled) {
		debug('Not loading module `' + moduleConstructor.name + '`.');
	}
	else {
		var module_ = new moduleConstructor(this);
		this.modules.push(module_);

		// We get the name of the property based on the name of the constructor
		var propertyName = inflection.camelize(moduleConstructor.name, true);

		Object.defineProperty(this, propertyName, {
			value: module_
		});
	}
};

App.prototype._setup = function() {
	debug('App#_setup');

	var result = Q.when(true);

	var self = this;
	this.modules.forEach(function(module_) {
		result = result.then(function() {
			// TODO: Create a noop.
			return Q.when((module_.setup || function(){}).call(module_, config.basePath));
		});
	});

	return result
		.then(function() {
			var environment = (process.env.NODE_ENV || 'development');

			result = Q.when(true);
			self._configureFunctions.forEach(function(configureFunction) {
				result = result.then(function() {
					return Q.when(configureFunction(environment));
				});
			});

			return result;
		});
};

App.prototype.configure = function(configureFunction) {
	this._configureFunctions.push(configureFunction);
};

App.prototype.stop = function() {
	var defer = Q.defer();
	fire._app = null;

	if(this.server) {
		this.server.close(defer.makeNodeResolver());
	}
	else {
		defer.resolve();
	}

	return defer.promise;
};
{'fraction_non_alphanumeric': 0.16073394495412843, 'fraction_numerical': 0.0, 'mean_word_length': 4.865136298421808, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6286378', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2446, 'n_words': 470}