How can I run a grumbling task from a task?

I created a new grunt task, and in it I want to use grunt-contrib-concat to merge several files together.

I looked through the documents, but I did not find anything that hinted at the possibility of doing this. This seems like a trivial precedent, so I was probably just looking for something.

Update 1:

I also want to be able to customize this task from my custom task.

For example, I create a list of files in my custom task. After I have this list, I want to pass them to the concat task. How can i do this?

I would like to be able to do something like this.

grunt.task.run('concat', { src: ['file1','file2'], dest: 'out.js'}) 

Update 2:

In order to achieve what I want, I need to manually configure the grunt task. Here is an example that showed me what I wanted.

https://github.com/gruntjs/grunt-contrib/issues/118#issuecomment-8482130

+47
javascript gruntjs
Mar 08 '13 at 0:25
source share
4 answers

Here is an example of manually setting a task in a task and then launching it.

https://github.com/gruntjs/grunt-contrib/issues/118#issuecomment-8482130

  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'); }); 
+34
Mar 08 '13 at 17:47
source share

From https://github.com/gruntjs/grunt/wiki/Creating-tasks

 grunt.registerTask('foo', 'My "foo" task.', function() { // Enqueue "bar" and "baz" tasks, to run after "foo" finishes, in-order. grunt.task.run('bar', 'baz'); // Or: grunt.task.run(['bar', 'baz']); }); 
+25
Mar 08 '13 at 0:36
source share

Thanks to Arron, who pointed us in the right direction to his own question. The grunt.config file is the key from the example above. This task will override the src property of the browser task.

Task definition:

  grunt.registerTask('tests', function (spec) { if (spec) { grunt.config('browserify.tests.src', spec); } grunt.task.run(['jshint', 'browserify:tests', 'jasmine']); }); 

Task assignment:

 grunt tests 

or

 grunt tests:somewhere/specPath.js 
+10
Mar 18 '14 at 10:42
source share

If you feel lazy, I ended up publishing the npm module, which redirects configs from your task to the subtask that you want to run:

https://www.npmjs.org/package/extend-grunt-plugin

0
Jul 25 '14 at 17:45
source share



All Articles