D
D
Dmitry2016-07-06 17:53:13
JavaScript
Dmitry, 2016-07-06 17:53:13

Change value of global variable from gulp task?

What you need:
Determine if a certain file exists in a certain directory.
If yes, then change the value of the variable, which will be used for another task with the gulp-if condition.
What happens:
There is a variable AND there is a task that checks for the existence of a file
var bar = false;

gulp.task('default', function(cb) {
  fs.stat('foo/bar.js', function(err, stat) {
    return err == null ? bar = true : err.code;
  });
  console.log(bar); // false (почему не true? условие ведь проходит)
  cb();
});

Thanks in advance for your replies

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2016-07-06
@dmitry-l

False because fs.stat is executed asynchronously, so synchronously here is fs.statSync(path)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question