<commit_before>var assetBundlerUtil = require( "./lib/util.js" );

module.exports = function( rootDir, staticDir, appPagesDir ) {

	//var bundleMap = assetBundlerUtil.readBundleMap();
	var pageMap = assetBundlerUtil.readPageMap();
	//var bundlerConfig = assetBundlerUtil.readBundlerConfig();

	return function( req, res, next ) {

		var oldRender = res.render;

		res.render = function() {
			var path = arguments[0];

			var pageMetadata = pageMap[ path.replace( appPagesDir, "" ).substring( 1 ) ];

			res.locals.bundler_js = pageMetadata.bundler_js;
			res.locals.bundler_css = pageMetadata.bundler_css;
			res.locals.bundler_tmpl = pageMetadata.bundler_tmpl;

			oldRender.apply( res, arguments );
		};

		next();
	};
};
<commit_msg>throw more useful error if error occurs while reading pageMap file<commit_after>var assetBundlerUtil = require( "./lib/util.js" );

module.exports = function( rootDir, staticDir, appPagesDir ) {

	var pageMap;

	try {
		pageMap = assetBundlerUtil.readPageMap();
	}
	catch( e ) {
		throw new Error( "Error while reading pageMap file.  Please run the grunt assetbundler task before running your application." );
	}

	return function( req, res, next ) {

		var oldRender = res.render;

		res.render = function() {
			var path = arguments[0];

			var pageMetadata = pageMap[ path.replace( appPagesDir, "" ).substring( 1 ) ];

			res.locals.bundler_js = pageMetadata.bundler_js;
			res.locals.bundler_css = pageMetadata.bundler_css;
			res.locals.bundler_tmpl = pageMetadata.bundler_tmpl;

			oldRender.apply( res, arguments );
		};

		next();
	};
};

{'fraction_non_alphanumeric': 0.12381554011370816, 'fraction_numerical': 0.002526847757422615, 'mean_word_length': 4.060702875399361, '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': '7409615', 'n_tokens_mistral': 574, 'n_tokens_neox': 520, 'n_words': 122}