-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Grunt programmatically from JavaScript #1108
Conversation
…ion so tasks can be run programmatically from JavaScript
👍 Yes, please! |
Just to give a little more info: this PR adds a 'nogruntfile' options which bypasses the Gruntfile presence check and resulting exception in task.js PS. Sorry for the confusion regarding the gruntjs/grunt-init#64, this PR is a standalone issue... |
+1 |
Great, I'd love to see this merged! |
Will this do what you want it to? This is the code I used to test (from within the Grunt project root directory): var grunt = require('./lib/grunt');
grunt.initConfig({
pkg: grunt.file.readJSON('./package.json'),
bar: {
options: {a: 1, b: 2},
one: {},
two: {
options: {b: 3, c: 4},
},
},
});
grunt.registerTask('foo', function() {
console.log(grunt.config('pkg.name'), grunt.config('pkg.version'));
});
grunt.registerMultiTask('bar', function() {
console.log(this.options());
});
grunt.tasks(['foo', 'bar'], {gruntfile: false}, function() {
console.log('done');
}); /cc @vladikoff @shama @tkellen because I'm trying to figure out if I haven't accounted for something critical, that will cause backward-compatibility issues. |
FWIW, there may be other things that prevent Grunt from playing nicely when run as a lib, for example, the way it handles |
ping @auscaster |
Thanks @cowboy, your patch works fine for me using your test code and my own. Can't see any obvious issues using the grunt core this way, but as you say some dependencies and other grunt modules may be problematic (haven't found any probs yet though) :) |
This fix allows Grunt to be used programmatically from JavaScript without the need for a Gruntfile, like so: