grunt icon indicating copy to clipboard operation
grunt copied to clipboard

Execute another task within my task (without queueing the other one)

Open cspotcode opened this issue 10 years ago • 3 comments
trafficstars

Is there an API for executing another task from within my task?

I'd like to execute another task from within my own, then perform some cleanup tasks afterwards even if the other task failed.

Tasks like grunt-newer currently have to resort to tricks where they queue the other task to run immediately after themselves. There are workarounds to ensure that, even if the other, queued task fails, post-task cleanup actions will still occur. This could be avoided with a simple API to execute another task.

Possible API:

grunt.task.runTaskNow(taskName, arguments, /*optional*/ config);

cspotcode avatar Aug 24 '15 15:08 cspotcode

You could use grunt-force. I don't see the real benefit of adding this. It will only add extra complexity to your grunt configuration.

wardpeet avatar Feb 18 '16 06:02 wardpeet

I'm thinking of this as a building block to be used by tasks such as grunt-force and grunt-newer. Currently grunt's core doesn't expose any sort of API for doing this cleanly, and yet grunt-force and grunt-newer demonstrate the need for this API to exist.

EDIT: hit enter too soon; finished my comment.

cspotcode avatar Feb 18 '16 16:02 cspotcode

FWIW, this is an issue I would like to address. I've started working on an RFC related, to make tasks run standalone and will cross post here once I've opened the PR for it here: https://github.com/gruntjs/rfcs

shama avatar Feb 18 '16 16:02 shama