--- /dev/null
+#!/usr/bin/env node
+
+'use strict';
+
+(function () {
+ process.title = 'uncss';
+
+ var uncss = require('../src/uncss.js'),
+ data = require('../package.json'),
+ program = require('commander');
+
+ var buffer = '',
+ options;
+
+ function listArg(val) {
+ return val.split(',');
+ }
+
+ program
+ .version(data.version)
+ .usage('[options] <file or URL, ...>\n\t e.g. uncss http://getbootstrap.com/examples/jumbotron/ > stylesheet.css')
+ .option('-i, --ignore <selector, ...>', 'Do not remove given selectors', listArg)
+ .option('-m, --media <media_query, ...>', 'Process additional media queries', listArg)
+ .option('-C, --csspath <path>', 'Relative path where the CSS files are located')
+ .option('-s, --stylesheets <file, ...>', 'Specify additional stylesheets to process', listArg)
+ .option('-S, --ignoreSheets <selector, ...>', 'Do not include specified stylesheets', listArg)
+ .option('-r, --raw <string>', 'Pass in a raw string of CSS')
+ .option('-t, --timeout <milliseconds>', 'Wait for JS evaluation')
+ .option('-H, --htmlroot <folder>', 'Absolute paths\' root location')
+ .option('-u, --uncssrc <file>', 'Load these options from <file>')
+ .parse(process.argv);
+
+ options = {
+ ignore: program.ignore,
+ ignoreSheets: program.ignoreSheets,
+ media: program.media,
+ csspath: program.csspath,
+ stylesheets: program.stylesheets,
+ raw: program.raw,
+ timeout: program.timeout,
+ htmlroot: program.htmlroot,
+ uncssrc: program.uncssrc
+ };
+
+ if (!program.args.length) {
+ /* No files were specified, read HTML from stdin */
+ process.stdin.resume();
+ process.stdin.setEncoding('utf8');
+
+ process.stdin.on('data', function (chunk) {
+ buffer += chunk;
+ });
+
+ process.stdin.on('end', function () {
+ uncss(buffer, options, function (err, css) {
+ if (err) {
+ throw err;
+ }
+ console.log(css);
+ });
+ });
+ } else {
+ if (options.ignore) {
+ options.ignore = options.ignore.map(function (ign) {
+ /* Create RegExes */
+ if (ign[0] === '/') {
+ /* Remove starting and trailing '/' */
+ return new RegExp(ign.slice(1, -1));
+ }
+ return ign;
+ });
+ }
+
+ if (options.ignoreSheets) {
+ options.ignoreSheets = options.ignoreSheets.map(function (ign) {
+ /* Create RegExes */
+ if (ign[0] === '/') {
+ /* Remove starting and trailing '/' */
+ return new RegExp(ign.slice(1, -1));
+ }
+ return ign;
+ });
+ }
+
+ /* If used from the command line, concatenate the output */
+ uncss(program.args, options, function (err, css) {
+ if (err) {
+ throw err;
+ }
+ console.log(css);
+ });
+ }
+
+}());