Copy files with gulp, saving modification time

Situation:

I currently have a small gulp task that prepares my project files for deployment via FTP. This is nothing unusual, but this simple project no longer needs to be done now.

The entire deployment task has a β€œsubtask” that simply grabs the list of paths and copies all the files to the __deploy directory:

 /* Path: Folder path for a prepared deploy */ var deployBasePath = '__deploy/'; /* Paths: Include all paths into deploy and excluded unneeded files. */ var deployIncludePaths = [ '**/*', '.htaccess', '!{__deploy,__deploy/**}', '!{.git,.git/**}', '!assets/{js-sources,js-sources/**}', '!assets/{scss,scss/**}', '!assets/{vendor,vendor/**}', '!{node_modules,node_modules/**}', '!{panel,panel/**}', '!thumbs/**', '!.bowerrc', '!.gitignore', '!.gitmodules', '!bower.json', '!composer.{json,lock}', '!gulpfile.js', '!package.json', '!readme.md' ]; gulp.task('deploy-copy', ['deploy-cleanup', 'css', 'js'], function() { return gulp.src(deployIncludePaths) .pipe(gulp.dest(deployBasePath)); }); 

This will copy the project files to the __deploy directory and exclude all gulp, bower, composer configuration files, as well as SCSS and JS sources. The deploy-cleanup task that it invokes simply cleans up the deployment directory.


Problem:

There is a piece of project code that uses file modification dates to create sitemaps, etc. Unfortunately, this behavior cannot be changed.

Therefore, it would be useful if there was a way to copy files in the same way as it was done above, however, if all file modification dates (or at least files from the specified directory) are saved.

Is there any way to do this?

+7
gulp
source share
2 answers

Since I needed this too, but I could not find anything suitable, I wrote the gulp-preservetime plugin to do this.

Example:

 var gulp = require('gulp'); var preservetime = require('gulp-preservetime'); gulp.task('default', function() { gulp.src('./src/**/*') .pipe(gulp.dest('./dest')) .pipe(preservetime()); }); 
+9
source share

You can use gulp-newer for this.

Here is an example from it:

 var gulp = require('gulp'); var newer = require('gulp-newer'); var imagemin = require('gulp-imagemin'); var imgSrc = 'src/img/**'; var imgDest = 'build/img'; // Minify any new images gulp.task('images', function() { // Add the newer pipe to pass through newer images only return gulp.src(imgSrc) .pipe(newer(imgDest)) .pipe(imagemin()) .pipe(gulp.dest(imgDest)); }); gulp.task('default', function() { gulp.watch(imgSrc, ['images']); }); 
+1
source share

All Articles