Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
task definitions
// inside a gruntfile
grunt.registerTask('awesome', {
description: 'The most awesome task ever.',
type: 'multi',
main: function(grunt, arg) {
var files = grunt.file.expandFiles(grunt.util._.pluck(this.files, 'src'));
var success = this.task.listFiles(grunt, files);
grunt.log.writeln('Stuff happened...');
if (success) { grunt.log.ok(); } else { grunt.log.error(); }
},
listFiles: function(grunt, files) {
files.forEach(function(filepath) {
grunt.log.writeln(filepath);
});
return files.length > 0;
},
});
// inside a plugin, initialized with something like...
exports.awesome = {
description: 'The most awesome task ever.',
type: 'multi',
main: function(grunt, arg) {
var files = grunt.file.expandFiles(grunt.util._.pluck(this.files, 'src'));
var success = this.task.listFiles(grunt, files);
grunt.log.writeln('Stuff happened...');
if (success) { grunt.log.ok(); } else { grunt.log.error(); }
},
listFiles: function(grunt, files) {
files.forEach(function(filepath) {
grunt.log.writeln(filepath);
});
return files.length > 0;
},
};
@tkellen

This comment has been minimized.

Copy link

tkellen commented Sep 17, 2012

var task = {
  name: 'awesome',
  description: 'The most awesome task ever.',
  type: 'multi',
  main: function(arg) {
    var files = grunt.file.expandFiles(grunt.util._.pluck(this.files, 'src'));
    var success = exports.listFiles(files); // "exports" instead of "this"
    grunt.log.writeln('Stuff happened...');
    if (success) { grunt.log.ok(); } else { grunt.log.error(); }
  },
  listFiles: function(files) {
    files.forEach(function(filepath) {
      grunt.log.writeln(filepath);
    });
    return files.length > 0;
  }
};
exports.init = function(grunt) { return task; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.