Created
October 2, 2012 13:31
-
-
Save cowboy/3819170 to your computer and use it in GitHub Desktop.
Grunt 0.4.0a (devel) Run a subproject's grunt tasks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
}); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Project configuration. | |
grunt.initConfig({ | |
subgrunt: { | |
foo: { | |
subdir: './foo/', | |
args: ['jshint', 'qunit'], | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this example,
grunt subgrunt:foo
would run grunt in thefoo
subdirectory.Assuming that
npm install
had been run in there first :)