#!/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] \n\t e.g. uncss http://getbootstrap.com/examples/jumbotron/ > stylesheet.css') .option('-i, --ignore ', 'Do not remove given selectors', listArg) .option('-m, --media ', 'Process additional media queries', listArg) .option('-C, --csspath ', 'Relative path where the CSS files are located') .option('-s, --stylesheets ', 'Specify additional stylesheets to process', listArg) .option('-S, --ignoreSheets ', 'Do not include specified stylesheets', listArg) .option('-r, --raw ', 'Pass in a raw string of CSS') .option('-t, --timeout ', 'Wait for JS evaluation') .option('-H, --htmlroot ', 'Absolute paths\' root location') .option('-u, --uncssrc ', 'Load these options from ') .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); }); } }());