I'd like to construct a gulp task that will conditionally manually invoke some other tasks before running itself. After seeing that gulp.run('task') has been deprecated, I ended up with this basic structure:
const build = {
    server: () => {
        return gulp.src(files.server)
            ...
            .pipe(gulp.dest(files.outDir))
    },
    web: () => {
        return gulp.src(files.web)
            ...
            .pipe(gulp.dest(files.outDir))
    }
}
gulp.task('serve', () => {
    // run the server and if necessary, force it to stop first
    const start = () => expressServer.start('./dist/main.js')
    // don't try to run if build hasn't been run first
    try {
        fs.statSync('./dist/main.js') // throws an exception if the file doesn't exist
        start()
    } catch (err) {
        // ----- TODO in parallel; build server and web
        // afterwards; run server iff there were no errors
        if (failed)
            console.error(err)
        else
            start()
    }
})
It looks like invoking build.server() or build.web() does actually run the gulp tasks, but the function returns straight away - I guess that means the body of these functions is running asynchronously?
Could anyone help me to understand:
- What does the gulp.src(...). ... .gulp.dest(...)chain actually return? Is gulp, as I suspect, running these operations asynchronously?
- Assuming asynchronous operation; how can I wait for these to be completed?
- If not asynchronous, how can I execute them?
 
     
    