From 6cc0e6384a0657d29407b3f9242e1ade79c75a25 Mon Sep 17 00:00:00 2001 From: Ishraq Ibne Ashraf Date: Wed, 24 Jan 2018 23:35:51 +0100 Subject: [PATCH] grunt-cli-issue-107: Add registered task listing ability --- lib/grunt.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/grunt.js b/lib/grunt.js index 072ca24b3..f537af861 100644 --- a/lib/grunt.js +++ b/lib/grunt.js @@ -111,10 +111,16 @@ grunt.tasks = function(tasks, options, done) { task.init(tasks, options); verbose.writeln(); - if (!tasksSpecified) { - verbose.writeln('No tasks specified, running default tasks.'); + + if (!grunt.cli.options.tasklist) { + if (!tasksSpecified) { + verbose.writeln('No tasks specified, running default tasks.'); + } + verbose.writeflags(tasks, 'Running tasks'); + } + else { + verbose.writeln('Listing registered tasks...\n'); } - verbose.writeflags(tasks, 'Running tasks'); // Handle otherwise unhandleable (probably asynchronous) exceptions. var uncaughtHandler = function(e) { @@ -147,10 +153,16 @@ grunt.tasks = function(tasks, options, done) { } }); - // Execute all tasks, in order. Passing each task individually in a forEach - // allows the error callback to execute multiple times. - tasks.forEach(function(name) { task.run(name); }); - // Run tasks async internally to reduce call-stack, per: - // https://github.com/gruntjs/grunt/pull/1026 - task.start({asyncDone: true}); + if (!grunt.cli.options.tasklist) { + // Execute all tasks, in order. Passing each task individually in a forEach + // allows the error callback to execute multiple times. + tasks.forEach(function(name) { task.run(name); }); + // Run tasks async internally to reduce call-stack, per: + // https://github.com/gruntjs/grunt/pull/1026 + task.start({asyncDone: true}); + } + else { + // Do not run the registered tasks but just output them as JSON. + console.log(grunt.task._tasks); + } };