fix arm build issue
[framework/web/web-ui-fw.git] / build-tools / bin / cleancss
1 #!/usr/bin/env node
2
3 global.util = require("util");
4 var argv = require('optimist').argv,
5   cleanCss = require('cleancss'),
6   fs = require('fs');
7
8 var options = {
9   source: null,
10   target: null
11 };
12 var cleanOptions = {};
13
14 if (argv.o) options.target = argv.o;
15 if (argv._) options.source = argv._[0];
16 if (argv.e) cleanOptions.removeEmpty = true;
17
18 if (argv.h || argv.help) {
19   global.util.print('Usage: cleancss [-e] -o <output-file> <input-file>\n');
20   process.exit(0);
21 }
22
23 if (options.source) {
24   fs.readFile(options.source, 'utf8', function(error, text) {
25     if (error) throw error;
26     output(cleanCss.process(text));
27   });
28 } else {
29   var stdin = process.openStdin();
30   stdin.setEncoding('utf-8');
31   var text = '';
32   stdin.on('data', function(chunk) { text += chunk; });
33   stdin.on('end', function() { output(cleanCss.process(text, cleanOptions)); });
34 }
35
36 function output(cleaned) {
37   if (options.target) {
38     var out = fs.createWriteStream(options.target, { flags: 'w', encoding: 'utf-8', mode: 0644 });
39     out.write(cleaned);
40     out.end();
41   } else {
42     process.stdout.write(cleaned);
43   }
44 };