Updated to version 0.2.0. Added options parsing via optimist.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Wed, 2 Mar 2011 21:03:39 +0000 (22:03 +0100)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Wed, 2 Mar 2011 21:03:39 +0000 (22:03 +0100)
README.md
bin/cleancss
index.js
lib/clean.js
package.json
test/batch-test.js
test/unit-test.js

index 8a6d038..175bf2f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -29,10 +29,10 @@ Or even gzip it at once:
 
 ### How to use clean-css programatically ###
 
-    var CleanCSS = require('clean-css').CleanCSS;
+    var cleanCSS = require('clean-css');
     
-    var source = "a{font-weight:bold}";
-    var minimized = CleanCSS.process(source);
+    var source = "a{font-weight:bold;}";
+    var minimized = cleanCSS.process(source);
 
 ### How to run clean-css tests? ###
 
index 3d641ac..1a39ebf 100755 (executable)
@@ -1,7 +1,8 @@
 #!/usr/bin/env node
 
 global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
-var CleanCSS = require('clean-css').CleanCSS,
+var argv = require('optimist').argv,
+  cleanCss = require('clean-css'),
   fs = require('fs');
 
 var options = {
@@ -9,29 +10,25 @@ var options = {
   target: null
 };
 
-var args = process.argv.slice(2);
-out: while (args.length > 0) {
-  var p = args.shift();
-  switch(p) {
-    case '-o':
-      options.target = args.shift();
-      break;
-    default:
-      options.source = args.shift();
-  }
+if (argv.o) options.target = argv.o;
+if (argv._) options.source = argv._[0];
+
+if (argv.h || argv.help) {
+  global.sys.print('Usage: cleancss -o <output-file> <input-file>\n');
+  process.exit(0);
 }
 
 if (options.source) {
   fs.readFile(options.source, 'utf8', function(error, text) {
     if (error) throw error;
-    output(CleanCSS.process(text));
+    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)); });
+  stdin.on('end', function() { output(cleanCss.process(text)); });
 }
 
 function output(cleaned) {
index 1103bd3..7e65da3 100644 (file)
--- a/index.js
+++ b/index.js
@@ -1 +1 @@
-exports.CleanCSS = require("./lib/clean");
\ No newline at end of file
+module.exports = require("./lib/clean");
\ No newline at end of file
index 90c777d..4527f6b 100644 (file)
@@ -120,4 +120,4 @@ var CleanCSS = {
   }
 };
 
-exports.CleanCSS = CleanCSS;
\ No newline at end of file
+module.exports = CleanCSS;
\ No newline at end of file
index 5b303fb..0ee062a 100644 (file)
@@ -8,9 +8,12 @@
     "type" : "git",
     "url" : "http://github.com/jakubpawlowicz/clean-css.git"
   },
-  "version": "0.1.0",
+  "version": "0.2.0",
   "main": "index.js",
   "bin": {
     "cleancss": "./bin/cleancss"
+  },
+  "dependencies": {
+    "optimist": "0.1.x"
   }
 }
\ No newline at end of file
index 3e9f3e1..76811c5 100644 (file)
@@ -1,8 +1,7 @@
 var vows = require('vows'),
   fs = require('fs'),
-  assert = require('assert');
-
-var CleanCSS = require('../lib/clean').CleanCSS;
+  assert = require('assert'),
+  cleanCSS = require('../index');
 
 var batchContexts = function() {
   var context = {};
@@ -19,7 +18,7 @@ var batchContexts = function() {
       }
     }
     context[testName]['minimizing ' + testName + '.css'] = function(data) {
-      assert.equal(CleanCSS.process(data.plain), data.minimized)
+      assert.equal(cleanCSS.process(data.plain), data.minimized)
     };
   });
 
index 77af20d..ed9f684 100644 (file)
@@ -1,13 +1,12 @@
 var vows = require('vows'),
-  assert = require('assert');
-
-var CleanCSS = require('../lib/clean').CleanCSS;
+  assert = require('assert'),
+  cleanCSS = require('../index');
 
 var cssContext = function(groups) {
   var context = {};
-  var clean = function(cleanCss) {
+  var clean = function(cleanedCSS) {
     return function(css) {
-      assert.equal(CleanCSS.process(css), cleanCss);
+      assert.equal(cleanCSS.process(css), cleanedCSS);
     }
   };