How to call tasks from code in Grunt if helpers are gone

Grunt removes helpers, and this has already happened in grunt-contrib.

However, I have a Grunt file based on some custom tasks that invoke some of these helpers. Without helpers, it breaks. I'm just wondering what the correct way to replace them should be.

I get that this will be by invoking tasks directly somehow, but I'm not sure how to do this. The example will help a lot, since the Grunt documentation has not yet been updated.

Thanks.

+8
javascript gruntjs
source share
1 answer

Well, after some research and help from the grunt-contrib maintainers, I rewrote this task that I have:

grunt.registerMultiTask('multicss', 'Minify CSS files in a folder', function() { grunt.file.expandFiles(this.data).forEach(function(file) { var minified = grunt.helper("mincss", grunt.file.read(file)); grunt.file.write(file, minified); grunt.log.writeln("Minified CSS "+file); }); }); 

In it:

 grunt.registerMultiTask('multicss', 'Minify CSS files in a folder', function() { var count = 0; grunt.file.expandFiles(this.data).forEach(function(file) { var property = 'mincss.css'+count+'.files'; var value = {}; value[file] = file; grunt.config(property, value); grunt.log.writeln("Minifying CSS "+file); count++; }); grunt.task.run('mincss'); }); 

No changes to the configuration file are required. In the new part of the code, the task itself is used, and not the assistant who left.

This may not be the best approach, and Grunt 0.4.0 may change the game again, but now it works with Grunt 0.3.15 and grunt-contrib 0.2.

+9
source share

All Articles