From 77155e3f61d213c529a16ea595fc486fdeca28c9 Mon Sep 17 00:00:00 2001 From: Ben Alman Date: Wed, 18 Jun 2014 15:00:32 -0400 Subject: [PATCH] Run Grunt programmatically with the {gruntfile: false} option. Closes gh-1108. --- lib/grunt.js | 2 +- lib/grunt/cli.js | 4 ---- lib/grunt/task.js | 17 ++++++++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/grunt.js b/lib/grunt.js index bcbf00103..6f7bf6821 100644 --- a/lib/grunt.js +++ b/lib/grunt.js @@ -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) { diff --git a/lib/grunt/cli.js b/lib/grunt/cli.js index 52e9b1085..7938cf1c2 100644 --- a/lib/grunt/cli.js +++ b/lib/grunt/cli.js @@ -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: { - 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.', diff --git a/lib/grunt/task.js b/lib/grunt/task.js index a9637944a..bbf1a40c8 100644 --- a/lib/grunt/task.js +++ b/lib/grunt/task.js @@ -425,11 +425,18 @@ 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) { + 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). @@ -437,7 +444,7 @@ task.init = function(tasks, options) { // 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.