All files / tasks rename.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 3/3
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1742x 42x     42x 42x 1x 2x 1x   2x 2x   1x      
import * as fs from 'fs';
import * as path from 'path';
import IMultiTask = grunt.task.IMultiTask;
 
export = function (grunt: IGrunt) {
	grunt.registerMultiTask('rename', function (this: IMultiTask<void>) {
		this.files.forEach(function (file) {
			if (grunt.file.isFile(file.src![0])) {
				grunt.file.mkdir(path.dirname(file.dest!));
			}
			fs.renameSync(file.src![0], file.dest!);
			(<any> grunt)['verbose'].writeln('Renamed ' + file.src![0] + ' to ' + file.dest);
		});
		grunt.log.writeln('Moved ' + this.files.length + ' files');
	});
};