0

I want to pass a saved file which does not need to be compiled or does not need to be saved to a new location to gulp-tap so I can run an external script on it.

Right now I watch a complete directory and on each save I upload the whole directory:

gulp.task('shopify_theme',function(){
gulp.src( './theme/**/*.liquid' )
    .pipe(tap(function(file){
          upload(file);
    }));
})

And this is the upload part (theme is an application that uploads assets to shopify)

var upload = function( file ){
var splitPath = file.path.split('theme/').pop();
run('theme upload ' + splitPath, { cwd: 'theme' }).exec();
};

Every time I save a liquid file in the /theme directory all files (theme/**/*.liquid) are uploaded. gulp-changed doesn't work as at the time the task runs the destination and the source are the same.

What's the best way to only upload the changed file?

4

1 回答 1

0

您可以使用gulp.watch来监视单个文件的更改:

var upload = function(filePath){
  var splitPath = filePath.split('theme/').pop();
  run('theme upload ' + splitPath, { cwd: 'theme' }).exec();
};

gulp.watch('./theme/**/*.liquid', function(evnt) {
  upload(evnt.path);
});
于 2014-09-05T16:15:39.500 回答