Run Gulp 4 task programmatically

It appears that a task can be retrieved with gulp.task getter function and called directly:

gulp.task('sync-task')();
gulp.task('async-or-random-task')(function callbackForAsyncTasks(err) {
  if (err)
    console.error('error', err);
});

Adding to the accepted answer:

Yes you can retrieve a task by calling gulp.task, but rather than calling it directly you can wrap it in a call to gulp.series (presumably gulp.parallel would also work) and call that. This has the benefit of producing the expected "Starting/Finished" output. An example would be:

gulp.series(gulp.task('some-task'))();

with the output:

[09:18:32] Starting 'some-task'...
[09:18:32] Finished 'some-task' after 7.96 ms

This was tested just now on gulp v4.0.2.