Adds minifying remote files directly from CLI.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Thu, 5 Jun 2014 21:43:33 +0000 (22:43 +0100)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Thu, 5 Jun 2014 21:44:47 +0000 (22:44 +0100)
History.md
bin/cleancss
test/binary-test.js

index 2edf670..b33d4c1 100644 (file)
@@ -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.
index f34fa84..413ef39 100755 (executable)
@@ -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);
index ec661ec..68d627d 100644 (file)
@@ -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;