Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
leidottw committed Jul 5, 2016
1 parent 6d48c11 commit c77ed33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const through = require('through2');
const gutil = require('gulp-util');
const PluginError = gutil.PluginError;
const pngquant = require('pngquant-bin');
const fs = require('fs');
const execFileSync = require('child_process').execFileSync;
const spawnSync = require('child_process').spawnSync;

const chalk = require('chalk');

// consts
Expand All @@ -24,13 +25,11 @@ function gulpPngquant(options) {
}

if (file.isBuffer()) {
fs.writeFileSync('in.png', file.contents);
execFileSync(pngquant, opts);

file.contents = fs.readFileSync('out.png');
console.log(chalk.blue('pngquant compressing: ') + file.relative);

fs.unlinkSync('in.png');
fs.unlinkSync('out.png');
file.contents = spawnSync(pngquant, ['-'], {
input: file.contents
}).stdout;
}

// make sure the file goes through the next gulp plugin
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-pngquant",
"version": "1.0.6",
"version": "1.0.7",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit c77ed33

Please sign in to comment.