Skip to content

Commit

Permalink
Updated to handle writing multiple files to folder
Browse files Browse the repository at this point in the history
As discovered in issue
[12](bezoerb#12), when trying
to write multiple files to a folder, the write fails because it assumes
that the path is a file and not a folder.

I have updated the code to check first if the destination is a folder
and update accordingly. See [this
issue](http://stackoverflow.com/a/20417119/335567) on SO for more
information.
  • Loading branch information
deanhume committed Jun 5, 2015
1 parent e19731a commit c57ac9a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tasks/critical.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,24 @@ module.exports = function (grunt) {
async.eachSeries(srcFiles,function(src,cb){
var opts = extend({},options);
opts.src = path.resolve(src).replace(basereplace,'');

// check if the destination is a folder and not a file
var destination;
if (grunt.file.isDir(f.dest)) {

destination = path.join(f.dest, src);
} else {
destination = f.dest;
}

try {
critical[command](opts, function (err, output){
if (err) {
return cb(err);
}
grunt.file.write(f.dest, output);
grunt.file.write(destination, output);
// Print a success message.
grunt.log.ok('File "' + f.dest + '" created.');
grunt.log.ok('File "' + destination + '" created.');

cb(null,output);
});
Expand All @@ -71,7 +81,7 @@ module.exports = function (grunt) {
}
},function(e) {
if (e) {
grunt.fail.warn('File "' + f.dest + '" failed.');
grunt.fail.warn('File "' + destination + '" failed.');
grunt.log.warn(e.message || e);

}
Expand Down

0 comments on commit c57ac9a

Please sign in to comment.