Grunt log in a registered task?

145 Views Asked by At

I have done some research and have not found a good solution for what I am looking to do. I am needing some more information during a build and wanted to find out if it is possible to have grunt log in a registered task? Here is what I tried that did not work.

grunt.registerTask('build', [
  'handlebars',
  'jshint',
  'cssmin',
  grunt.log.writeln('starting to run html minification),
  'htmlmin'
]);

Is there a way for me to stick these notifications when a task runs?

Thank you for your help.

3

There are 3 best solutions below

0
On BEST ANSWER

One way to do this is to create a custom (function-style) task that runs the others and logs its progress:

grunt.registerTask('build', function(){
  grunt.task.run('handlebars', 'jshint', 'cssmin');
  grunt.log.writeln('starting to run html minification),
  grunt.task.run('htmlmin');
});
0
On

Please try the node package called grunt-header :

https://www.npmjs.com/package/grunt-header

0
On

You can even define your own log task to output its arguments in a more generic way:

grunt.registerTask('build', [
    'handlebars',
    'jshint',
    'cssmin',
    'log:starting to run html minification',
    'htmlmin'
]);

grunt.registerTask('log', function(text) {
    for(var i = 1; i < arguments.length; i++) {
        text += ':' + arguments[i];
    }
    grunt.log.writeln(text);
});