Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Grunt 0.4.0a (devel) Run a subproject's grunt tasks.
/*
* grunt-subgrunt
* http://gruntjs.com/
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
*/
'use strict';
module.exports = function(grunt) {
// Nodejs libs.
var path = require('path');
grunt.registerMultiTask('subgrunt', 'Run a sub-project\'s grunt tasks.', function() {
if (!grunt.file.exists(this.data.subdir)) {
grunt.log.error('Directory "' + this.data.subdir + '" not found.');
return false;
}
var done = this.async();
var subdir = path.resolve(this.data.subdir);
grunt.util.spawn({
cmd: path.join(subdir, 'node_modules/.bin/grunt'),
args: this.data.args || [],
opts: {cwd: subdir},
}, function(error, result, code) {
if (code === 127) {
grunt.log.error('Error running sub-grunt. Did you run "npm install" in the sub-project?');
} else {
grunt.log.writeln('\n' + result.stdout);
}
done(code === 0);
});
});
};
// Project configuration.
grunt.initConfig({
subgrunt: {
foo: {
subdir: './foo/',
args: ['jshint', 'qunit'],
},
},
});
@cowboy
Owner

In this example, grunt subgrunt:foo would run grunt in the foo subdirectory.

Assuming that npm install had been run in there first :)

@cowboy
Owner

(Note: untested in Windows)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.