3 global.util = require("util");
4 var argv = require('optimist').argv,
5 cleanCss = require('cleancss'),
12 var cleanOptions = {};
14 if (argv.o) options.target = argv.o;
15 if (argv._) options.source = argv._[0];
16 if (argv.e) cleanOptions.removeEmpty = true;
18 if (argv.h || argv.help) {
19 global.util.print('Usage: cleancss [-e] -o <output-file> <input-file>\n');
24 fs.readFile(options.source, 'utf8', function(error, text) {
25 if (error) throw error;
26 output(cleanCss.process(text));
29 var stdin = process.openStdin();
30 stdin.setEncoding('utf-8');
32 stdin.on('data', function(chunk) { text += chunk; });
33 stdin.on('end', function() { output(cleanCss.process(text, cleanOptions)); });
36 function output(cleaned) {
38 var out = fs.createWriteStream(options.target, { flags: 'w', encoding: 'utf-8', mode: 0644 });
42 process.stdout.write(cleaned);