D
D
Dima Shishkin2018-04-02 11:01:52
Node.js
Dima Shishkin, 2018-04-02 11:01:52

Why doesn't gulp see the newly created folder?

I'm using Gulp 4 and I have a task that deploys the code locally:

gulp.task('deploy', gulp.series('clean', 'handlers:all', 'deployment'));

The task consists of three subtasks:
1. Task "clean": removes the 'build' folder.
2. Task “handlers:all”: re-creates this folder and spits out files (html, css, js, ...) there
3. Task “deployment”: takes the contents of the build folder and transfers it to where I ask it to be done.
The problem is deployment. It looks something like this:
gulp.task('deployment', done => {
  gulp.src('./build/')
            .pipe(gulp.dest('../other-project/'));
});

In my project, everything is somewhat more complicated, but the essence is the same. The point is that gulp.src simply does not find the 'build' folder because the 'clean' task removed it. If you set a small timeout, then the files are considered:
gulp.task('deployment', done => {
  setTimeout(() => {
    gulp.src('./build/')
              .pipe(gulp.dest('../other-project/'));
  }, 2000);
});

But the problem is that it's not very reliable because you can't guess the timeout over time.
How to catch this right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Lebedinsky, 2018-04-02
@Shugich

Before starting a task that works with a newly created folder, wait until the task that creates this folder is finished. For example, as I recommended here - How to make sequential execution of tasks in GULP?

V
Vitaly, 2018-04-02
@vitstr

And you do not delete the folder, but clean it ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question