{"size": 1187, "ext": "js", "max_stars_repo_path": "server/bindStylusMiddleware.js", "max_stars_repo_name": "scgowda/keystone-with-s3-image", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/bindStylusMiddleware.js", "max_issues_repo_name": "scgowda/keystone-with-s3-image", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/bindStylusMiddleware.js", "max_forks_repo_name": "scgowda/keystone-with-s3-image", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.4358974359, "max_line_length": 70, "alphanum_fraction": 0.6343723673}
module.exports = function bindStylusMiddleware (keystone, app) {
	// the stylus option can be a single path, or array of paths
	// when set, we configure the stylus middleware
	var stylusPaths = keystone.get('stylus');
	var stylusOptions = keystone.get('stylus options') || {};
	var debug = require('debug')('keystone:core:bindStylusMiddleware');
	var _ = require('lodash');

	if (typeof stylusPaths === 'string') {
		stylusPaths = [stylusPaths];
	}

	if (Array.isArray(stylusPaths)) {
		var stylusMiddleware;
		try {
			debug('adding stylus');
			stylusMiddleware = require('stylus').middleware;
		} catch (e) {
			if (e.code === 'MODULE_NOT_FOUND') {
				console.error(
					'\nERROR: stylus not found.\n'
					+ '\nPlease install stylus from npm to use the `stylus` option.'
					+ '\nYou can do this by running "npm install stylus --save".\n'
				);
				process.exit(1);
			} else {
				throw e;
			}
		}
		stylusPaths.forEach(function (path) {
			app.use(stylusMiddleware(_.extend({
				src: keystone.expandPath(path),
				dest: keystone.expandPath(path),
				compress: keystone.get('env') === 'production',
			}, stylusOptions)));
		});
	}
};
