bobgodwin 14 Newbie Poster

I need to check the extention of user uploaded files when running a gulp-sass task. I have a file exists function that seems to work, but can't get thereturn value into the task. Here's my gulp file:

var fileexists = require('file-exists');
var gulp = require('gulp');
var sassVars = require('gulp-sass-vars');
var sass = require('gulp-sass');

var style_in = './scss/**/*.scss';
var style_out = './css';
var himg;
var fimg;

fileexists('img/header.jpg').then(exists => {
    if(exists){
        himg = 'header.jpg'
        console.log(himg)
    }
})

fileexists('img/header.png').then(exists => {
    if(exists){
        himg = 'header.png'
        console.log(himg)
    }
})

fileexists('img/footer.jpg').then(exists => {
    if(exists){
        fimg = 'footer.jpg'
        console.log(fimg)
    }
})

fileexists('img/footer.png').then(exists => {
    if(exists){
        fimg = 'footer.png'
        console.log(fimg)
    }
})

gulp.task('sass', function() {
    var variables = {
        header_image : fileexists.himg
    };
    return gulp
    .src(style_in)
    .pipe(sassVars(variables, { verbose: true }))
    .pipe(sass().on('error', sass.logError))
    .pipe(cssImageDimensions('../img'))
    .pipe(gulp.dest(style_out))
});

gulp.task('sass:watch', function() {
    gulp.watch(style_in, ['sass'])
});

I've tried passing values like this " gulp.task('sass', function(fileexists)" but can't get it to work. What am I doing wrong?