#!/usr/bin/env node global.util = require("util"); var argv = require('optimist').argv, cleanCss = require('../index'), fs = require('fs'); var options = { source: null, target: null }; if (argv.o) options.target = argv.o; if (argv._) options.source = argv._[0]; if (argv.h || argv.help) { global.util.print('Usage: cleancss -o \n'); process.exit(0); } if (options.source) { fs.readFile(options.source, 'utf8', function(error, text) { if (error) throw error; output(cleanCss.process(text)); }); } else { var stdin = process.openStdin(); stdin.setEncoding('utf-8'); var text = ''; stdin.on('data', function(chunk) { text += chunk; }); stdin.on('end', function() { output(cleanCss.process(text)); }); } function output(cleaned) { if (options.target) { var out = fs.createWriteStream(options.target, { flags: 'w', encoding: 'utf-8', mode: 0644 }); out.write(cleaned); out.end(); } else { process.stdout.write(cleaned); } };