Comparing version 0.1.0 to 0.1.1
53
index.js
@@ -14,7 +14,8 @@ /** | ||
var win32 = process.platform === 'win32'; | ||
var imagemin = module.exports = function(dir, dest, cb) { | ||
dest = dest || ''; | ||
if (typeof dest === 'function') { | ||
cb = dest; | ||
var png = ['.png', '.bmp', '.gif', '.pnm', '.tiff'], | ||
jpegs = ['.jpg', 'jpeg']; | ||
var imagemin = module.exports = function(dir, destDir, cb) { | ||
destDir = destDir || ''; | ||
if (typeof destDir === 'function') { | ||
cb = destDir; | ||
} | ||
@@ -24,9 +25,8 @@ if (typeof cb !== 'function') { | ||
} | ||
var png = ['.png', '.bmp', '.gif', '.pnm', '.tiff'], | ||
jpegs = ['.jpg', 'jpeg']; | ||
var files = []; | ||
if (Array.isArray(dir)) { | ||
dir.forEach(function(v){ | ||
imagemin(v, dest, cb); | ||
dir.forEach(function(v) { | ||
imagemin(v, destDir, cb); | ||
}); | ||
@@ -55,11 +55,6 @@ return; | ||
if (dest && !/\/$/.test(dest)) { | ||
dest += '/'; | ||
} | ||
var pngConfig = {}; | ||
var jpgConfig = {}; | ||
optipng(pngfiles, pngConfig, dest, function(err) { | ||
optipng(pngfiles, {}, destDir, function(err) { | ||
if (err) log.error(err); | ||
jpegtran(jpgfiles, jpgConfig, dest, function(err) { | ||
jpegtran(jpgfiles, {}, destDir, function(err) { | ||
if (err) log.error(err); | ||
@@ -86,3 +81,13 @@ cb(); | ||
if (output) { | ||
args.push('-dir', output, '-clobber'); | ||
var ext = path.extname(output).toLowerCase(); | ||
if ( !! ~png.indexOf(ext)) { | ||
//文件 | ||
args.push('-out', output, '-clobber'); | ||
} else { | ||
if (!/\/$/.test(output)) { | ||
output += '/'; | ||
} | ||
//目录 | ||
args.push('-dir', output, '-clobber'); | ||
} | ||
} | ||
@@ -115,3 +120,13 @@ | ||
if (output) { | ||
outputPath = output + path.basename(file); | ||
var ext = path.extname(output).toLowerCase(); | ||
if ( !! ~jpegs.indexOf(ext)) { | ||
//文件 | ||
outputPath = output; | ||
} else { | ||
if (!/\/$/.test(output)) { | ||
output += '/'; | ||
} | ||
outputPath = output + path.basename(file); | ||
} | ||
try { | ||
@@ -127,3 +142,2 @@ fs.readFileSync(outputPath); | ||
jpegtran.stdout.pipe(process.stdout); | ||
@@ -149,3 +163,2 @@ jpegtran.stderr.pipe(process.stderr); | ||
// Output some size info about a file, from a stat object. | ||
@@ -152,0 +165,0 @@ |
{ | ||
"name": "imagemin", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A tool to optimize png and jpg images with optipng & jpegtran", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1293437
243
53