How to run Gulp tasks sequentially one after the other
It's not an official release yet, but the coming up Gulp 4.0 lets you easily do synchronous tasks with gulp.series. You can simply do it like this:
gulp.task('develop', gulp.series('clean', 'coffee'))
I found a good blog post introducing how to upgrade and make a use of those neat features:
migrating to gulp 4 by example
Running Gulp task one after another in specific order
You should have the 'unzip-wp' task wait for the 'download' task to finish. To make sure the 'download' task is really finished also add a return statement to that task, i.e. this would do what you're looking for:
var gulp = require('gulp'),
decompress = require('gulp-decompress'),
download = require("gulp-download"),
ftp = require('gulp-ftp'),
gutil = require('gulp-util');
gulp.task('default', function () {
console.log("Hello gulp");
});
var src_download = [
"https://wordpress.org/latest.zip"
];
gulp.task('download', function () {
return download(src_download)
.pipe(gulp.dest("./"));
});
gulp.task('unzip-wp', ['download'], function () {
return gulp.src('latest.zip')
.pipe(decompress({strip: 1}))
.pipe(gulp.dest('./'));
});
gulp.task('install', ['unzip-wp']);
How to run gulp.watch multiple tasks synchronized?
Gulp 4.0 (3.9.1 as of right now) has the ability to run tasks in sequence/series.
https://github.com/gulpjs/gulp/blob/4.0/docs/API.md#gulpseriestasks
For now, you could use the run-sequence
package.
https://www.npmjs.com/package/run-sequence
How can I automatically run all gulp tasks?
This has three arguments:
gulp.task('browser-sync', gulp.series('nodemon'), () => {
in gulp v4+ you can only have two arguments, so change that to
gulp.task('browser-sync', gulp.series('nodemon', () => {
and same with
gulp.task('default', gulp.series('browser-sync', () => {
- there will be a close paren
)
to add to the ends of those functions too, like}));
Run gulp task after completion of other task
I know you don't want to use a plugin, but gulp doesn't have a way to run a sequence of tasks in order without a plugin. Gulp 4 will, but in the meantime the stopgap solution is the run-sequence plugin.
gulp.task('all', function() {
runSequence('base', 'mods');
});
This ensures that the tasks run in order as opposed to unordered dependencies.
Now setup a watch:
gulp.task('watch', function() {
gulp.watch('base-glob', ['all']);
gulp.watch('mods-glob', ['mods']);
});
Whenever base-glob
changes, gulp will run all
task, which will run the sequence base
then mods
.
Whenever mods-glob
changes, gulp will run only mods
task.
That sound about right?
Related Topics
How to Capture an Arbitrary Number of Groups in JavaScript Regexp
Why Does JavaScript Handle the Plus and Minus Operators Between Strings and Numbers Differently
Concrete JavaScript Regular Expression for Accented Characters (Diacritics)
How to Parse JSON Using Node.Js
Differencebetween Parseint() and Number()
How to Get the Scrollbar Position with JavaScript
JavaScript % (Modulo) Gives a Negative Result for Negative Numbers
Jquery How to Bind Onclick Event to Dynamically Added HTML Element
Get the Element with the Highest Occurrence in an Array
How to Perform a Dns Lookup (Hostname to Ip Address) Using Client-Side JavaScript
Defining a JavaScript Prototype
How to Set the Value Property in Angularjs' Ng-Options
How to Check a Radio Button with Jquery
JavaScript Regex: How to Put a Variable Inside a Regular Expression
Are Eval() and New Function() the Same Thing