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?
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 .
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 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.
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();     }); }); 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();     }); }); If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With