Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 46 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
{
"name": "grunt-rename",
"description": "Move and/or rename files.",
"version": "0.1.4",
"homepage": "https://github.com/jdavis/grunt-rename",

"author": {
"name": "Josh Davis",
"email": "josh@joshldavis.com",
"url": "http://joshldavis.com"
},

"repository": {
"type": "git",
"url": "git://github.com/jdavis/grunt-rename.git"
},

"bugs": {
"url": "https://github.com/jdavis/grunt-rename/issues"
},

"licenses": [{
"type": "MIT",
"url": "https://github.com/jdavis/grunt-rename/blob/master/LICENSE-MIT"
}],

"main": "Gruntfile.js",

"engines": {
"node": ">= 0.8.0"
},

"scripts": {
"test": "grunt test"
},

"dependencies": {},

"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt": "~0.4.1"
},

"peerDependencies": {
"grunt": "~0.4.1"
},

"keywords": [
"gruntplugin",
"move",
"rename"
]
"name": "grunt-rename",
"description": "Move and/or rename files.",
"version": "0.1.4",
"homepage": "https://github.com/jdavis/grunt-rename",
"author": {
"name": "Josh Davis",
"email": "josh@joshldavis.com",
"url": "http://joshldavis.com"
},
"repository": {
"type": "git",
"url": "git://github.com/jdavis/grunt-rename.git"
},
"bugs": {
"url": "https://github.com/jdavis/grunt-rename/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/jdavis/grunt-rename/blob/master/LICENSE-MIT"
}
],
"main": "Gruntfile.js",
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "grunt test"
},
"dependencies": {
"async": "^1.4.2"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt": "~0.4.1"
},
"peerDependencies": {
"grunt": "~0.4.1"
},
"keywords": [
"gruntplugin",
"move",
"rename"
]
}
22 changes: 13 additions & 9 deletions tasks/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
'use strict';

var fs = require('fs'),
path = require('path');
path = require('path'),
async = require('async');

module.exports = function(grunt) {
grunt.registerMultiTask('rename', 'Move and/or rename files.', function() {
Expand All @@ -25,18 +26,18 @@ module.exports = function(grunt) {
return done();
}

this.files.forEach(function (f) {
async.eachLimit(this.files, 5, function (f, cb) {
var dest = f.dest,
dir = path.dirname(dest);

// Check if no source files were found
if (f.src.length === 0) {
// Continue if ignore is set
if (options.ignore) {
return done();
return cb();
} else {
grunt.fail.warn('Could not move file to ' + f.dest + ' it did not exist.');
return done();
return cb();
}
}

Expand All @@ -55,7 +56,7 @@ module.exports = function(grunt) {
// Easy peasy
if (!err) {
grunt.verbose.writeln('Moved ' + file + ' to ' + dest);
return done();
return cb();
}

// Now fallback to copying/unlinking
Expand All @@ -64,25 +65,28 @@ module.exports = function(grunt) {

read.on('error', function (err) {
grunt.fail.warn('Failed to read ' + file);
return done();
cb && cb();
cb = null;
});

write.on('error', function (err) {
grunt.fail.warn('Failed to write to ' + dest);
return done();
cb && cb();
cb = null;
});

write.on('close', function () {
// Now remove original file
grunt.file.delete(file);

grunt.verbose.writeln('Moved ' + file + ' to ' + dest);
return done();
cb && cb();
cb = null;
});

read.pipe(write);
});
});
});
}, done);
});
};