Skip to content

Instantly share code, notes, and snippets.

@jevets

jevets/Gruntfile.js

Last active Dec 26, 2015
Embed
What would you like to do?
Grunt task recurse files async - help needed
/**
* I can't figure out why this doesn't work.
*
* I've tried using async, but there's no way to know when the exif stuff is done.
*
* Please help me understand what I'm doing wrong.
*/
var util = require('util');
var ExifImage = require('exif').ExifImage;
// src/photos contains several photos with exif data
grunt.registerTask('default', function() {
grunt.file.expand('src/photos/*.jpg').forEach(function(el, i, array) {
// this gets output to the console
grunt.log.writeln('Attempt to get exif data for ' + el);
new ExifImage({ image: 'src/photos/' + el }, function(err, exifData) {
// but neither of these do
if (err) grunt.log.writeln('Error: ' + err.message);
grunt.log.writeln(util.inspect(exifData));
// nor does this
grunt.log.writeln('Inside new ExifImage');
});
});
});
@shama

This comment has been minimized.

Copy link

@shama shama commented Oct 29, 2013

grunt.registerTask('default', function() {
  var done = this.async();

  var files = grunt.file.expand('src/photos/*.jpg');
  grunt.util.async.eachSeries(files, function(el, next) {
    grunt.log.writeln('Attempt to get exif data for ' + el);
    new ExifImage({ image: 'src/photos/' + el }, function(err, exifData) {
      // but neither of these do
      if (err) grunt.log.writeln('Error: ' + err.message);
      grunt.log.writeln(util.inspect(exifData));
      // nor does this
      grunt.log.writeln('Inside new ExifImage');

      // Call this to move onto the next image
      next();
    });
  }, done); // done is called when all have completed

});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment