Compile SASS files in a directory via Gulp.js tasks, one of which produces logging output
Interesting question;

some review remarks before addressing your actual question:


You never seem to pass filePath to src but use path["sass"] instead
I always suggest to pipe your console.log calls through a log function that accepts a severity parameter so that you can customize the level of logging, but that's probably overkill for Gulp


I would add a new function that does nothing, called doNothing() and then up front point an output function to either doNothing() or console.log().

function doNothing(){
  //Do nothing
}

function CompileSass(filePath) {
    const time = process.hrtime();
    const out = (filePath === "string") ? console.log : doNothing;
    out("compiling now");

    return src(path["sass"])
        .pipe(sass({outputStyle: "expanded"}))
        .on("end", () =&gt; {
            out(`Compiled '${filePath}' now`);
        })
        .pipe(dest("css"))
        .on("end", () =&gt; {
            out(`Finished compiling ${prettyTime(process.hrtime(time))}`);
        });
}

exports.default = () =&gt; {
    watch(dir).on("all", (directory) =&gt; {
        CompileSass(directory);
    });
};

exports.sass = series(CompileSass); // in fact, there is other tasks in series function's argument