Skip to content

Commit

Permalink
Add support for renaming files
Browse files Browse the repository at this point in the history
  • Loading branch information
kevva committed Mar 22, 2015
1 parent 555cfae commit 005e262
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ module.exports = function (grunt) {
src: '**/*.{gif,GIF,jpg,JPG,png,PNG}',
dest: 'tmp'
}]
},
rename: {
files: {
'tmp/rename.jpg': 'test/fixtures/test.jpg'
}
}
},
nodeunit: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"async": "^0.9.0",
"chalk": "^1.0.0",
"gulp-rename": "^1.2.0",
"imagemin": "^3.1.0",
"pretty-bytes": "^1.0.1"
},
Expand Down
5 changes: 5 additions & 0 deletions tasks/imagemin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var async = require('async');
var chalk = require('chalk');
var prettyBytes = require('pretty-bytes');
var Imagemin = require('imagemin');
var rename = require('gulp-rename');

/*
* grunt-contrib-imagemin
Expand Down Expand Up @@ -40,6 +41,10 @@ module.exports = function (grunt) {
options.use.forEach(imagemin.use.bind(imagemin));
}

if (path.basename(file.src[0]) !== path.basename(file.dest)) {
imagemin.use(rename(path.basename(file.dest)));
}

fs.stat(file.src[0], function (err, stats) {
if (err) {
grunt.warn(err + ' in file ' + file.src[0]);
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ exports.imagemin = {

test.ok(fs.existsSync('tmp/nested/nested/test.png'), 'should support nested dest dir');

test.done();
},
rename: function (test) {
test.expect(1);

test.ok(fs.existsSync('tmp/rename.jpg'), 'should support renaming');

test.done();
}
};

0 comments on commit 005e262

Please sign in to comment.