Add "Pre/Post task" hooks for gulp build rig
When running a gulp task, I frequently have tasks I want to perform BEFORE the task runs. Considering there are now hooks to add sub-tasks before/after the build, the bundle, typescript, and you can hook into the webpack configuration, it would make sense to me to add a hook so you can add a "pre (or post) task" hook. A subtask that runs BEFORE/AFTER everything else does.
I use this especially when running 'gulp serve', to start a proxy service that allows me to use live sharepoint data while using the local workbench. However, I frequently want to use different site contexts in different builds, so I like to pick the context from a list. For this purpose, I have a task that prompts the user to select from a list of options, then starts the server based on their selection. Because it is waiting for input, I need to block the rest of the build chain until the selections have been made.
Because the task needs to block, I can't run it as a concurrent npm script. I also want it to run FIRST, instead of in the middle of a build, so using the existing "addPost/addPre" hooks aren't what I'm looking for. I have been able to get it to work by creating my own task, but I also want it to run the originally desired task, without having to reverse engineer and completely redesign that task (which I was able to do, but it is fragile).
The solutions I've managed to get to work reliably so far are pretty hacky. I either create my own task, and run some serial sub-tasks, starting with collecting the user input and starting the proxy server, then use gulp.start() to start the task I originally wanted to run. Or, I listen for gulp.on('start'), overwrite the task sequence with my starting task, then run gulp.start() on the original sequence. So, either way, I am hacking into the gulp chain, or trying to re-engineer the whole build chain...