lib/runner.js
function runner(options, callback) {
	// call CommonJS module
	var analyzerOpts = {
		'noOffenders': options.noOffenders,
		'preprocessor': false,
	};

	function analyze(css) {
		new analyzer(css, analyzerOpts, callback);
	}

	if (options.url) {
		debug('Fetching remote CSS file: %s', options.url);

		// @see https://www.npmjs.com/package/node-fetch#options
		var agentOptions = {},
			requestOptions = {
				url: options.url,
				headers: {
					'User-Agent': getUserAgent()
				}
			};

		// handle options

		// @see https://github.com/bitinn/node-fetch/issues/15
		// @see https://nodejs.org/api/https.html#https_https_request_options_callback
		if (options.ignoreSslErrors) {
			agentOptions.rejectUnauthorized = false;
		}

		// @see https://gist.github.com/cojohn/1772154
		if (options.authUser && options.authPass) {
			requestOptions.headers.Authorization = "Basic " + new Buffer(options.authUser + ":" + options.authPass, "utf8").toString("base64");
		}

		// @see https://nodejs.org/api/http.html#http_class_http_agent
		var client = require(/^https:/.test(options.url) ? 'https' : 'http');
		requestOptions.agent = new client.Agent(agentOptions);

		// @see http://stackoverflow.com/a/5810547
		options.proxy = options.proxy || process.env.HTTP_PROXY;

		if (options.proxy) {
			debug('Using HTTP proxy: %s', options.proxy);

			requestOptions.agent = new(require('http-proxy-agent'))(options.proxy);
		}

		request(requestOptions, function(err, css) {
			if (err) {
				err.code = analyzer.EXIT_URL_LOADING_FAILED;

				debug(err);
				callback(err);
			} else {
				analyze(css);
			}
		});
	} else if (options.file) {
		// resolve to the full path
		options.file = resolve(process.cwd(), options.file);
		debug('Loading local CSS file: %s', options.file);

		fs.readFile(options.file, {
			encoding: 'utf-8'
		}, function(err, css) {
			if (err) {
				err = new Error('Loading CSS file failed: ' + err.toString());
				err.code = analyzer.EXIT_FILE_LOADING_FAILED;

				debug(err);
				callback(err);
			} else {
				// find the matching preprocessor and use it
				if (analyzerOpts.preprocessor === false) {
					analyzerOpts.preprocessor = preprocessors.findMatchingByFileName(options.file);
				}

				// pass the name of the file being analyzed
				analyzerOpts.file = options.file;

				analyze(css);
			}
		});
	} else if (options.stdin) {
		debug('Reading from stdin');
		cli.withStdin(analyze);
	}
}
function runner(options, callback) {
	// call CommonJS module
	var analyzerOpts = {
		'noOffenders': options.noOffenders,
		'preprocessor': false,
	};

	function analyze(css) {
		new analyzer(css, analyzerOpts, callback);
	}

	if (options.url) {
		debug('Fetching remote CSS file: %s', options.url);

		// @see https://www.npmjs.com/package/node-fetch#options
		var agentOptions = {},
			requestOptions = {
				url: options.url,
				headers: {
					'User-Agent': getUserAgent()
				}
			};

		// handle options

		// @see https://github.com/bitinn/node-fetch/issues/15
		// @see https://nodejs.org/api/https.html#https_https_request_options_callback
		if (options.ignoreSslErrors) {
			agentOptions.rejectUnauthorized = false;
		}

		// @see https://gist.github.com/cojohn/1772154
		if (options.authUser && options.authPass) {
			requestOptions.headers.Authorization = "Basic " + new Buffer(options.authUser + ":" + options.authPass, "utf8").toString("base64");
		}

		// @see https://nodejs.org/api/http.html#http_class_http_agent
		var client = require(/^https:/.test(options.url) ? 'https' : 'http');
		requestOptions.agent = new client.Agent(agentOptions);

		// @see http://stackoverflow.com/a/5810547
		options.proxy = options.proxy || process.env.HTTP_PROXY;

		if (options.proxy) {
			debug('Using HTTP proxy: %s', options.proxy);

			requestOptions.agent = new(require('http-proxy-agent'))(options.proxy);
		}

		request(requestOptions, function(err, css) {
			if (err) {
				err.code = analyzer.EXIT_URL_LOADING_FAILED;

				debug(err);
				callback(err);
			} else {
				analyze(css);
			}
		});
	} else if (options.file) {
		// resolve to the full path
		options.file = resolve(process.cwd(), options.file);
		debug('Loading local CSS file: %s', options.file);

		fs.readFile(options.file, {
			encoding: 'utf-8'
		}, function(err, css) {
			if (err) {
				err = new Error('Loading CSS file failed: ' + err.toString());
				err.code = analyzer.EXIT_FILE_LOADING_FAILED;

				debug(err);
				callback(err);
			} else {
				// find the matching preprocessor and use it
				if (analyzerOpts.preprocessor === false) {
					analyzerOpts.preprocessor = preprocessors.findMatchingByFileName(options.file);
				}

				// pass the name of the file being analyzed
				analyzerOpts.file = options.file;

				analyze(css);
			}
		});
	} else if (options.stdin) {
		debug('Reading from stdin');
		cli.withStdin(analyze);
	}
}
function runner ( options , callback ) { // call CommonJS module var analyzerOpts = { 'noOffenders' : options . noOffenders , 'preprocessor' : false , } ; function analyze ( css ) { new analyzer ( css , analyzerOpts , callback ) ; } if ( options . url ) { debug ( 'Fetching remote CSS file: %s' , options . url ) ; // @see https://www.npmjs.com/package/node-fetch#options var agentOptions = { } , requestOptions = { url : options . url , headers : { 'User-Agent' : getUserAgent ( ) } } ; // handle options // @see https://github.com/bitinn/node-fetch/issues/15 // @see https://nodejs.org/api/https.html#https_https_request_options_callback if ( options . ignoreSslErrors ) { agentOptions . rejectUnauthorized = false ; } // @see https://gist.github.com/cojohn/1772154 if ( options . authUser && options . authPass ) { requestOptions . headers . Authorization = "Basic " + new Buffer ( options . authUser + ":" + options . authPass , "utf8" ) . toString ( "base64" ) ; } // @see https://nodejs.org/api/http.html#http_class_http_agent var client = require ( / ^https: / . test ( options . url ) ? 'https' : 'http' ) ; requestOptions . agent = new client . Agent ( agentOptions ) ; // @see http://stackoverflow.com/a/5810547 options . proxy = options . proxy || process . env . HTTP_PROXY ; if ( options . proxy ) { debug ( 'Using HTTP proxy: %s' , options . proxy ) ; requestOptions . agent = new ( require ( 'http-proxy-agent' ) ) ( options . proxy ) ; } request ( requestOptions , function ( err , css ) { if ( err ) { err . code = analyzer . EXIT_URL_LOADING_FAILED ; debug ( err ) ; callback ( err ) ; } else { analyze ( css ) ; } } ) ; } else if ( options . file ) { // resolve to the full path options . file = resolve ( process . cwd ( ) , options . file ) ; debug ( 'Loading local CSS file: %s' , options . file ) ; fs . readFile ( options . file , { encoding : 'utf-8' } , function ( err , css ) { if ( err ) { err = new Error ( 'Loading CSS file failed: ' + err . toString ( ) ) ; err . code = analyzer . EXIT_FILE_LOADING_FAILED ; debug ( err ) ; callback ( err ) ; } else { // find the matching preprocessor and use it if ( analyzerOpts . preprocessor === false ) { analyzerOpts . preprocessor = preprocessors . findMatchingByFileName ( options . file ) ; } // pass the name of the file being analyzed analyzerOpts . file = options . file ; analyze ( css ) ; } } ) ; } else if ( options . stdin ) { debug ( 'Reading from stdin' ) ; cli . withStdin ( analyze ) ; } }
Module's main function
Module s main function