diff --git a/.travis.yml b/.travis.yml index 97bccea..d7183d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,10 @@ language: node_js node_js: + - "4.1" + - "4.0" - "0.12" - "0.11" - "0.10" + - "0.8" + - "0.6" - "iojs" diff --git a/README.md b/README.md index 71e2b42..94bfecd 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,20 @@ Default: `false` Set to true to log errors & messages to the console. Errors are dispatched via events anyway, so plugins like `gulp-plumber` can handle these for you. +#### options.parallel +Type: `Boolean` +Default: `true` + +Enables concurrent uploads to the TinyPNG server to speed up total compression time. + +(thanks [HugoHeneault](https://github.com/HugoHeneault) for this feature suggestion) + +#### options.parallelMax +Type: `Integer` +Default: `5` + +The amount of concurrent uploads allowed at one time, increase if you/your request limits can handle it - very easy to max out your monthly requests, use with caution! + #### options.force Type: `Boolean` / `String` Default: `false` diff --git a/index.js b/index.js index 238255e..29fda36 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ var test = process.env.NODE_ENV == 'test', through = require('through2'), + throughParallel = require('through2-concurrent'), gutil = require('gulp-util'), chalk = gutil.colors, request = require('request'), @@ -28,7 +29,9 @@ function TinyPNG(opt, obj) { log: false, force: false, ignore: false, sameDest: false, - summarize: false + summarize: false, + parallel: true, + parallelMax: 5 } }; @@ -66,7 +69,7 @@ function TinyPNG(opt, obj) { opt = this.conf.options, emitted = false; - return through.obj(function(file, enc, cb) { + return (opt.parallel ? throughParallel : through).obj({maxConcurrency: opt.parallelMax}, function(file, enc, cb) { if(self.utils.glob(file, opt.ignore)) return cb(); if(file.isNull()) { @@ -128,6 +131,7 @@ function TinyPNG(opt, obj) { }) .on('error', function(err) { emitted = true; // surely a method in the stream to handle this? + self.stats.skipped++; self.utils.log(err.message); }) .on('end', function() { diff --git a/package.json b/package.json index f3e6ff7..e3074ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-tinypng-compress", - "version": "1.1.8", + "version": "1.2.0", "description": "TinyPNG API wrapper for compressing PNG & JPG images", "main": "index.js", "repository": "stnvh/gulp-tinypng-compress", @@ -38,7 +38,8 @@ "dependencies": { "gulp-util": "~3.0.0", "request": "~2.55.0", - "through2": "~0.6.0", + "through2": "^2.0.0", + "through2-concurrent": "^1.1.0", "minimatch": "^2.0.0" }, "devDependencies": {