From 77aa7c928c895a16bffeabf47ed29167f60328ef Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Wed, 2 Mar 2011 22:03:39 +0100 Subject: [PATCH] Updated to version 0.2.0. Added options parsing via optimist. --- README.md | 6 +++--- bin/cleancss | 23 ++++++++++------------- index.js | 2 +- lib/clean.js | 2 +- package.json | 5 ++++- test/batch-test.js | 7 +++---- test/unit-test.js | 9 ++++----- 7 files changed, 26 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 8a6d038a..175bf2f6 100644 --- 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? ### diff --git a/bin/cleancss b/bin/cleancss index 3d641ac4..1a39ebf1 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -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 \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) { diff --git a/index.js b/index.js index 1103bd38..7e65da3a 100644 --- 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 diff --git a/lib/clean.js b/lib/clean.js index 90c777d3..4527f6b7 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -120,4 +120,4 @@ var CleanCSS = { } }; -exports.CleanCSS = CleanCSS; \ No newline at end of file +module.exports = CleanCSS; \ No newline at end of file diff --git a/package.json b/package.json index 5b303fbd..0ee062a9 100644 --- a/package.json +++ b/package.json @@ -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 diff --git a/test/batch-test.js b/test/batch-test.js index 3e9f3e19..76811c58 100644 --- a/test/batch-test.js +++ b/test/batch-test.js @@ -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) }; }); diff --git a/test/unit-test.js b/test/unit-test.js index 77af20dd..ed9f6847 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -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); } }; -- 2.34.1