Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp: How to change modification time of file

Tags:

node.js

gulp

I have gulp task below and with every run of this task (before browsersync) I want to change last modification time of one file (nothing changes in that file, I just need to change time of last modification - alternative to shell "touch" command). Can somebody tell me what's the easiest way to do that please? Thanks!

gulp.task('sass', function() {

    return sass(pkg.sass.dir, {sourcemap: true, precision: 10}) 
        .on('error', function (err) { 
            onError(err);
        })
        .pipe(autoprefixer({
            browsers: ['last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'],
            cascade: true
        }))
        .pipe(gulp.dest(pkg.css.dir))
        .pipe(browsersync.reload({stream:true}));
});
like image 241
user2595304 Avatar asked Feb 04 '15 16:02

user2595304


1 Answers

Use the core fs module's fs.utimes function, which is the node analog to the Unix touch command. You pass the path and if you pass a new Date() as the mtime parameter, that should do the trick.

like image 173
Peter Lyons Avatar answered Sep 24 '22 01:09

Peter Lyons