Socket
Socket
Sign inDemoInstall

imagemin

Package Overview
Dependencies
139
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

52

cli.js

@@ -7,2 +7,3 @@ #!/usr/bin/env node

var nopt = require('nopt');
var path = require('path');
var pkg = require('./package.json');

@@ -37,2 +38,3 @@ var stdin = require('get-stdin');

console.log('Usage');
console.log(' $ imagemin <file> <directory>');
console.log(' $ imagemin <file> > <output>');

@@ -42,2 +44,3 @@ console.log(' $ cat <file> | imagemin > <output>');

console.log('Example');
console.log(' $ imagemin *.{gif,jpg,png} build');
console.log(' $ imagemin foo.png > foo-optimized.png');

@@ -71,6 +74,21 @@ console.log(' $ cat foo.png | imagemin > foo-optimized.png');

/**
* Check if path is a file
*
* @param {String} path
* @api private
*/
function isFile(path) {
return path && path.indexOf('.') !== -1;
}
/**
* Run
*
* @param {Buffer} input
* @param {Object} opts
* @api private
*/
function run(input) {
function run(input, opt) {
var imagemin = new Imagemin()

@@ -83,2 +101,9 @@ .src(input)

if (process.stdout.isTTY) {
var name = path.basename(opt.input);
var out = path.join(opt.output ? opt.output : 'build', name);
imagemin.dest(path.join(out));
}
imagemin.optimize(function (err, file) {

@@ -90,3 +115,5 @@ if (err) {

process.stdout.write(file.contents);
if (!process.stdout.isTTY) {
process.stdout.write(file.contents);
}
});

@@ -101,2 +128,3 @@ }

var input = opts.argv.remain;
var output;

@@ -108,14 +136,16 @@ if (input.length === 0) {

if (input.length > 1) {
console.error('Only one input file allowed');
process.exit(1);
if (input[input.length - 1] && !isFile(input[input.length - 1])) {
output = input[input.length - 1];
input.pop();
}
fs.readFile(input[0], function (err, data) {
if (err) {
console.error(err);
process.exit(1);
}
input.forEach(function (file) {
fs.readFile(file, function (err, data) {
if (err) {
console.error(err);
process.exit(1);
}
run(data);
run(data, { input: file, output: output });
});
});

@@ -122,0 +152,0 @@ } else {

@@ -96,3 +96,8 @@ 'use strict';

self.write(file, function (err) {
cb(err, file);
if (err) {
cb(err);
return;
}
cb(null, file);
});

@@ -169,3 +174,8 @@ });

fs.outputFile(dest, file.contents, function (err) {
cb(err);
if (err) {
cb(err);
return;
}
cb();
});

@@ -172,0 +182,0 @@ };

{
"name": "imagemin",
"version": "1.0.0",
"version": "1.0.1",
"description": "Minify images",

@@ -19,3 +19,3 @@ "license": "MIT",

"scripts": {
"test": "mocha --reporter list --timeout 50000"
"test": "node test/test.js"
},

@@ -36,13 +36,11 @@ "files": [

"dependencies": {
"fs-extra": "^0.10.0",
"fs-extra": "^0.11.0",
"get-stdin": "^2.0.0",
"image-type": "^0.1.4",
"nopt": "^3.0.1",
"rimraf": "^2.2.6",
"stat-mode": "^0.2.0",
"tempfile": "^0.1.3",
"tempfile": "^1.0.0",
"ware": "^0.3.0"
},
"devDependencies": {
"mocha": "^1.18.2"
"ava": "0.0.3"
},

@@ -49,0 +47,0 @@ "optionalDependencies": {

@@ -24,2 +24,6 @@ # imagemin [![Build Status](https://travis-ci.org/kevva/imagemin.svg?branch=master)](https://travis-ci.org/kevva/imagemin)

imagemin.optimize(function (err, file) {
if (err) {
throw err;
}
console.log(file);

@@ -26,0 +30,0 @@ // => { contents: <Buffer 89 50 4e ...>, mode: '0644' }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc