I'm probably trying to make gulp something that is not idiomatic, but that goes here. I want my build task to be performed only if the source files are newer than the output file.
In gulp, the standard practice is to create a build task that always runs, and then set up a view task only to complete this build task when certain files change. This is good, but it means that you are always building your first launch.
So, is it possible to do what I want? Here is what I have so far (newer than gulp -newer):
gulp.task('build_lib', function() { return gulp.src(["app/**/*.ts"]) .pipe(newer("out/outputLib.js")) //are any of these files newer than the output? ** NEED SOMETHING HERE ** how do I say, "If I got _any_ files from the step before, replace all of them with a single hardcoded file "app/scripts/LibSource.ts" "? .pipe(typescript({ declaration: true, sourcemap: true, emitError: false, safe: true, target: "ES5", out: "outputLib.js" })) .pipe(gulp.dest('out/'))
});
I tried using gulpif, but it does not work if there are no files in it.
.pipe(gulpif(are_there_any_files_at_all, gulp.src(["app/scripts/LibSource.ts"])))
However, my state function is not even called because there are no files for which it can be called. gulpif calls the true thread in this case, so LibSource is added to my thread, which I don't want.
Perhaps all this in one thread is really not the right call, because the only reason I transfer these files through the gulp -newer filter is to see if any of them are newer. Then I drop them and replace them with another file. My question is still standing.