Variable Not Updated in Gulp - Out of order console logging?

gulp.task('sass', function() {
  var districtSchool = 'src/sass/districts/';
  if(config.districts.length) {
    console.log("schools found");
    config.districts.forEach(function(school) {
      console.log(school+": school");
      fs.stat('src/sass/districts/_'+school+'.scss', function(err, stat) {
        if(err == null) {
          districtSchool = districtSchool + school+".scss";
          gulp.src('').pipe(gulp.dest('src/'+school+'/img'));
          gulp.src('').pipe(gulp.dest('src/'+school+'/js'));
          gulp.src('').pipe(gulp.dest('src/'+school+'/sass'));
          console.log(districtSchool + ": districtschool varkk");
        }
        else {
          console.log(err.code);
        }
      });
    });
  }
  else {
    console.log("noschools");
    districtSchool = null;
  }
  console.log("district var : "+districtSchool);
  return gulp.src([
      'src/sass/main.scss',
      districtSchool
    ])
    .pipe(sass({ style : config.sass_style}))
    .on("error", handleError)
    .pipe(autoprefixer({
      browsers: ['> 1%', 'last 4 versions', 'Firefox ESR', 'Opera 12.1'],
      cascade: false
    }))
    // .pipe(header(banner, { pkg : pkg, config: config } ))
    .pipe(gulp.dest('src/dist/css'))
    .pipe(gulp.dest(themepath+'css'))
    .pipe(browserSync.stream());
});

This is my console.

Seems it’s not in order? The variable is updated when I console log it but it’s out of order…why is this? It’s within the same gulp task.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.