Skip to content

Commit

Permalink
Run Grunt programmatically with the {gruntfile: false} option. Closes g…
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboy committed Jul 10, 2014
1 parent 4ca015b commit 77155e3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ grunt.tasks = function(tasks, options, done) {
tasks = task.parseArgs([tasksSpecified ? tasks : 'default']);

// Initialize tasks.
task.init(tasks, {nogruntfile: !!options.nogruntfile});
task.init(tasks, options);

verbose.writeln();
if (!tasksSpecified) {
Expand Down
4 changes: 0 additions & 4 deletions lib/grunt/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ var optlist = cli.optlist = {
info: 'Specify an alternate Gruntfile. By default, grunt looks in the current or parent directories for the nearest Gruntfile.js or Gruntfile.coffee file.',
type: path
},
nogruntfile: {

This comment has been minimized.

Copy link
@dnozay

dnozay Nov 14, 2014

may be better to leave it and deprecate it, then remove it in a later release.

info: 'Disable the Gruntfile.js or Gruntfile.coffee file. Useful when using Grunt programmatically from JavaScript.',
type: path
},
debug: {
short: 'd',
info: 'Enable debugging mode for tasks that support it.',
Expand Down
17 changes: 12 additions & 5 deletions lib/grunt/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,19 +425,26 @@ task.init = function(tasks, options) {

// Get any local Gruntfile or tasks that might exist. Use --gruntfile override
// if specified, otherwise search the current directory or any parent.
var gruntfile = allInit ? null : grunt.option('gruntfile') ||
grunt.file.findup('Gruntfile.{js,coffee}', {nocase: true});
var gruntfile, msg;
if (allInit || options.gruntfile === false) {

This comment has been minimized.

Copy link
@dnozay

dnozay Nov 14, 2014

|| options.nogruntfile === true ?

gruntfile = null;
} else {
gruntfile = grunt.option('gruntfile') ||
grunt.file.findup('Gruntfile.{js,coffee}', {nocase: true});
msg = 'Reading "' + (gruntfile ? path.basename(gruntfile) : '???') + '" Gruntfile...';
}

var msg = 'Reading "' + (gruntfile ? path.basename(gruntfile) : '???') + '" Gruntfile...';
if (gruntfile && grunt.file.exists(gruntfile)) {
if (options.gruntfile === false) {
// Grunt was run as a lib with {gruntfile: false}.
} else if (gruntfile && grunt.file.exists(gruntfile)) {
grunt.verbose.writeln().write(msg).ok();
// Change working directory so that all paths are relative to the
// Gruntfile's location (or the --base option, if specified).
process.chdir(grunt.option('base') || path.dirname(gruntfile));
// Load local tasks, if the file exists.
loadTasksMessage('Gruntfile');
loadTask(gruntfile);
} else if (options.help || options.nogruntfile || allInit) {
} else if (options.help || allInit) {
// Don't complain about missing Gruntfile.
} else if (grunt.option('gruntfile')) {
// If --config override was specified and it doesn't exist, complain.
Expand Down

0 comments on commit 77155e3

Please sign in to comment.