From c850ef38ffe4a9b0e50d1869d5c0c0d1400fb463 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Thu, 5 Jun 2014 22:43:33 +0100 Subject: [PATCH] Adds minifying remote files directly from CLI. --- History.md | 1 + bin/cleancss | 17 ++++++++++++----- test/binary-test.js | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/History.md b/History.md index 2edf670b..b33d4c17 100644 --- a/History.md +++ b/History.md @@ -3,6 +3,7 @@ * Adds a better algorithm for quotation marks' removal. * Adds a better non-adjacent optimizer compatible with the upcoming new property optimizer. +* Adds minifying remote files directly from CLI. * Moves quotation matching into a `QuoteScanner` class. * Fixed issue [#134](https://github.com/GoalSmashers/clean-css/issues/134) - merges properties into shorthand form. * Fixed issue [#164](https://github.com/GoalSmashers/clean-css/issues/164) - removes default values if not needed. diff --git a/bin/cleancss b/bin/cleancss index f34fa84f..413ef394 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -82,18 +82,25 @@ if (commands.timeout) cleanOptions.inliner = { timeout: parseFloat(commands.timeout) * 1000 }; if (commands.args.length > 0) { var relativeTo = (cleanOptions.noRebase ? false : cleanOptions.root) || commands.args[0]; - options.sources = commands.args; cleanOptions.relativeTo = path.dirname(path.resolve(relativeTo)); + + options.sources = commands.args.map(function(source) { + var isRemote = /^https?:\/\//.test(source); + + if (cleanOptions.processImport === false) + source += '@shallow'; + + return isRemote ? + source : + path.relative(cleanOptions.relativeTo, path.resolve(source)); + }); } // ... and do the magic! if (options.sources) { var data = options.sources .map(function(source) { - if (cleanOptions.processImport === false) - source += '@shallow'; - - return '@import url(' + path.relative(cleanOptions.relativeTo, path.resolve(source)) + ');'; + return '@import url(' + source + ');'; }) .join(''); minify(data); diff --git a/test/binary-test.js b/test/binary-test.js index ec661ec6..68d627d2 100644 --- a/test/binary-test.js +++ b/test/binary-test.js @@ -240,6 +240,25 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({ } }) }, + 'remote import': { + topic: function() { + this.server = http.createServer(function (req, res) { + res.writeHead(200); + res.end('p{font-size:13px}'); + }).listen(31991, '127.0.0.1'); + + this.callback(null); + }, + 'of a file': binaryContext('http://127.0.0.1:31991/present.css', { + succeeds: function(error, stdout) { + assert.equal(error, null); + assert.equal(stdout, 'p{font-size:13px}'); + } + }), + teardown: function() { + this.server.close(); + } + }, 'timeout': unixOnlyContext({ topic: function() { var self = this; -- 2.34.1