gulpjs / gulp

A toolkit to automate & enhance your workflow
https://gulpjs.com
MIT License
33.01k stars 4.22k forks source link

Question: Gulp 4.0 Conventions For Tasks #771

Closed dman777 closed 9 years ago

dman777 commented 9 years ago

With 4.0, is the intended code flow(gulp convention) no longer calling outside normal javascript functions(non task wrapped) inside a wrapped task?

The reason why I ask is because I see:

gulp.task('default', gulp.parallel('clean', 'all')); where clean and all are also gulp tasks called within task default.

In 3.0, this would be done with

function clean() {}
function all() {}
gulp.task('default', function () {
    Promise.all([clean(), all()]);
})

Reference: https://github.com/gulpjs/gulp/issues/458#issuecomment-62057370 https://github.com/gulpjs/gulp/issues/755#issuecomment-61884019

yocontra commented 9 years ago

You can also do this

function clean() {}
function all() {}
gulp.task('default', gulp.series(clean, all))

series and parallel take strings or functions, strings just look up the function from the task object

yocontra commented 9 years ago

Docs for the underlying lib: https://github.com/phated/bach

For the 4.0 release I really want to consolidate the spiderweb of docs into one place

phated commented 9 years ago

Everything is just function composition in gulp4. There should be no more need to add extra wrappers, etc.

jasonkarns commented 9 years ago

What's the simplest form for task aliasing? (for the default task?)

gulp.task('default', gulp.series('build')) seems a bit verbose for a simple alias

stringparser commented 9 years ago

But is way powerful.

gulp.task('css:pipeline', gulp.series('stylus', 'autoprefixer'));
gulp.task('js:pipeline', gulp.series('jsx', 'lint', 'minify'));
gulp.task('default', gulp.parallel('js:pipeline','css:pipeline'));
jasonkarns commented 9 years ago

Yeah! I certainly don't want to downplay the many-to-one feature. And I don't think an increased api surface area is warranted (e.g. gulp.alias or something). But keeping gulp.task('default', 'other') doesn't seem unreasonable. (Or gulp.task('default', ['other']))

jasonkarns commented 9 years ago

I didn't mean to hijack the thread. Should this be a separate discussion?

phated commented 9 years ago

@jasonkarns I will try to answer here, but if it isn't satisfactory, please open a new issue.

The simplest way to alias a task is as such:

function build(){
  // do your build stuff
}

gulp.task(build);
gulp.task('default', build);

Remember, everything is a function :smile:

yocontra commented 9 years ago

Closing this since it already exists on the 4.0 branch

geirsagberg commented 9 years ago

gulp.task('default', 'build') should be synonymous with gulp.task('default', gulp.series('build')) IMO. When I tried wrapping the build task in a function as suggested, gulp won't log anything from the nested tasks:

function build(){
  return gulp.parallel(buildScripts, buildLess);
}
gulp.task(build);
gulp.task('default', build);