Skip to content

Commit 005e262

Browse files
committed
Add support for renaming files
Fixes #293.
1 parent 555cfae commit 005e262

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

Gruntfile.js

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ module.exports = function (grunt) {
3333
src: '**/*.{gif,GIF,jpg,JPG,png,PNG}',
3434
dest: 'tmp'
3535
}]
36+
},
37+
rename: {
38+
files: {
39+
'tmp/rename.jpg': 'test/fixtures/test.jpg'
40+
}
3641
}
3742
},
3843
nodeunit: {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dependencies": {
2323
"async": "^0.9.0",
2424
"chalk": "^1.0.0",
25+
"gulp-rename": "^1.2.0",
2526
"imagemin": "^3.1.0",
2627
"pretty-bytes": "^1.0.1"
2728
},

tasks/imagemin.js

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var async = require('async');
66
var chalk = require('chalk');
77
var prettyBytes = require('pretty-bytes');
88
var Imagemin = require('imagemin');
9+
var rename = require('gulp-rename');
910

1011
/*
1112
* grunt-contrib-imagemin
@@ -40,6 +41,10 @@ module.exports = function (grunt) {
4041
options.use.forEach(imagemin.use.bind(imagemin));
4142
}
4243

44+
if (path.basename(file.src[0]) !== path.basename(file.dest)) {
45+
imagemin.use(rename(path.basename(file.dest)));
46+
}
47+
4348
fs.stat(file.src[0], function (err, stats) {
4449
if (err) {
4550
grunt.warn(err + ' in file ' + file.src[0]);

test/test.js

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ exports.imagemin = {
6262

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

65+
test.done();
66+
},
67+
rename: function (test) {
68+
test.expect(1);
69+
70+
test.ok(fs.existsSync('tmp/rename.jpg'), 'should support renaming');
71+
6572
test.done();
6673
}
6774
};

0 commit comments

Comments
 (0)