Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a grunt task on one Gruntfile from another

Tags:

I have a Gruntfile in the root of my project. I also have jQuery installed via Bower in an app/components/jquery directory.

As part of my Gruntfile I'd like to run some commands on the jQuery Gruntfile to build a custom version of the library.

How can I get at their Gruntfile from mine?

like image 251
Simon Smith Avatar asked May 23 '13 10:05

Simon Smith


People also ask

Can we configure grunt to run one or more tasks by default by defining a default task?

Custom tasksYou can configure Grunt to run one or more tasks by default by defining a default task. In the following example, running grunt at the command line without specifying a task will run the uglify task. This is functionally the same as explicitly running grunt uglify or even grunt default .

Is grunt a task runner?

Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile). Grunt was created by Ben Alman and is written in Node.

When a task is run grunt looks for its configuration under a?

When a task is run, Grunt looks for its configuration under a property of the same name. Multi-tasks can have multiple configurations, defined using arbitrarily named "targets." In the example below, the concat task has foo and bar targets, while the uglify task only has a bar target.


2 Answers

You can create a simple task that spawns grunt in the folder you want:

grunt.registerTask('run-grunt', function () {     var done = this.async();     grunt.util.spawn({         grunt: true,         args: [''],         opts: {             cwd: 'app/components/jquery'         }     }, function (err, result, code) {         done();     }); }); 
like image 56
Sindre Sorhus Avatar answered Nov 09 '22 22:11

Sindre Sorhus


If you want to get console output, building on @Sindre's answer, all you have to do is console log the result.stdout.

grunt.registerTask('run-grunt', function() {     var cb = this.async();     grunt.util.spawn({         grunt: true,         args: ['clean', 'copy:fonts'],         opts: {             cwd: 'bower_components/bootstrap'         }     }, function(error, result, code) {         console.log(result.stdout);         cb();     }); }); 
like image 45
Stephen James Avatar answered Nov 09 '22 22:11

Stephen James