Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gulp 4: gulp.single or at least hide <series/parallel> with single task #1411

Closed
glen-84 opened this issue Nov 25, 2015 · 15 comments
Closed

Comments

@glen-84
Copy link

glen-84 commented Nov 25, 2015

I have a default task, and I want it to invoke the watch task when run. watch is in a separate file, so I can't just reference the same function (assuming I had declared it separately).

The obvious answer would be to use gulp.series or gulp.parallel, but this is a bit strange, as it's only a single task, and you end up with:

[21:42:37] +-- default
[21:42:37]   +-- <parallel>
[21:42:37]     +-- watch

Would you consider one of these options?

  1. Add the ability to do something like: gulp.task("default", gulp.single("watch")).
  2. At least hide <series/parallel> when it's only a single task.

This is actually another issue that could be solved using dependencies (gulp.task("default", ["watch"]) -- same as Gulp 3).

@phated
Copy link
Member

phated commented Nov 25, 2015

We aren't going to add an API just to reduce noise in this scenario and showing the series or parallel will allow for better traceability in complex compositions.

@phated phated closed this as completed Nov 25, 2015
@glen-84
Copy link
Author

glen-84 commented Nov 25, 2015

That's a pity.

Now I have to find a way to pass task functions around (maybe a function arg or import/export).

Otherwise I see this type of thing:

[23:06:49] Starting 'watch'...
[23:06:55] Starting 'parallel'...                           <-- Yuck.
(change) src\tasks\build\javascript.ts
[23:06:55] Starting 'build'...
[23:06:57] Finished 'build' after 1.55 s
[23:06:57] Finished 'parallel' after 1.55 s                 <-- Yuck.

@adamreisnz
Copy link

I have to agree that more often than not, I find seeing the parallel and series tasks in the console annoying and detracting focus from the important information, which is the actual tasks that were run.

I disagree that there should be an API for silencing them, but it would be nice if you could suppress them via a CLI parameter. Or better, enable them when you do need to debug your tasks flow.

@phated
Copy link
Member

phated commented Dec 1, 2015

@adambuczynski we might be able to move them to a different log level now that we have a real logging system.

@glen-84
Copy link
Author

glen-84 commented Dec 1, 2015

@adambuczynski,

In one case I was able to do this:

// Watch.
gulp.task("watch", () => {
    gulp.watch("src/**/*.ts", gulp.registry().get("build"));
});

However, this was within the context of a custom registry, so I'm not sure if it works outside of that.

@adamreisnz
Copy link

@phated that's be a good idea I think

@phated
Copy link
Member

phated commented Dec 1, 2015

@adambuczynski I opened an issue on Undertaker to discuss the branch flag that I'd be using and created a branch with an implementation. I also created a branch of the CLI at https://github.com/gulpjs/gulp-cli/tree/branches-debug-log that would use the Undertaker branch. Those branches also solve #1330 but I'm not sure if it is correct to debug log those errors or hide the top level tasks. If you want to try out those branches and provide feedback on the best way to handle everything, we could move all issues forward. Thanks.

@adamreisnz
Copy link

I haven't used undertaker yet to define my tasks, just using regular functions in the gulpfile with gulp.task and gulp.series etc. Is there a way for me to test it without using undertaker? I've installed the CLI from your new branch, but that still logs the same way.

@phated
Copy link
Member

phated commented Dec 1, 2015

@adambuczynski you have to install that undertaker branch inside your gulp dependency. Gulp is just a tiny facade over undertaker (you could also do some npm linking magic but that is probably a pain)

@adamreisnz
Copy link

Alright, did that. Seems to work great. I am no longer seeing the starting/stopping parallel and series tasks showing up, the rest seems to work as expected 👍

@phated
Copy link
Member

phated commented Dec 22, 2015

The changes for this have been released in gulp-cli v1.1.0 - you also need to update gulp dependencies on the 4.0 branch because undertaker had a release to support it.

@jaydenseric
Copy link

@glen-84 My man, that worked a treat!

Before:

gulp.task('watch', function () {
  gulp.watch(globs.js, gulp.series('js'))
  gulp.watch(globs.css, gulp.series('css'))
})
[21:54:34] Starting 'watch'...
[21:54:48] Starting '<series>'...
[21:54:48] Starting 'css'...
[21:54:48] Finished 'css' after 142 ms
[21:54:48] Finished '<series>' after 143 ms

After:

gulp.task('watch', function () {
  gulp.watch(globs.js, gulp.registry().get('js'))
  gulp.watch(globs.css, gulp.registry().get('css'))
})
[21:56:29] Starting 'watch'...
[21:56:42] Starting 'css'...
[21:56:42] Finished 'css' after 147 ms

@phated
Copy link
Member

phated commented Jan 20, 2016

That's not the correct way to use registries. gulp.task(taskName) is a getter that returns your task. You should be using it like so:

gulp.task('watch', function () {
  gulp.watch(globs.js, gulp.task('js'))
  gulp.watch(globs.css, gulp.task('css'))
})

@jaydenseric
Copy link

@phated tried that, and it would be an intuitive solution but for some reason it reports their execution as <anonymous>:

gulp.task('watch', function () {
  gulp.watch(globs.js, gulp.task('js'))
  gulp.watch(globs.css, gulp.task('css'))
})
[09:30:36] Starting 'watch'...
[09:30:45] Starting '<anonymous>'...
[09:30:45] Finished '<anonymous>' after 38 ms

A bug?

@phated
Copy link
Member

phated commented Jan 20, 2016

@jaydenseric possibly. Please open a new issue and give reproduction steps (gulpfile, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants