2

I am using gulp-notify to display extra information in the terminal when a task is run. Currently I can only get the full path on my HD and file name. I would prefer to only display the project folders as it is cleaner.

function copyVideo (done) {
   // Locate files
   return gulp.src('./src/assets/video/*')
   // Copy the files to the dist folder
   .pipe(gulp.dest('./dist/assets/video'))
   // Notify the files copied in the terminal
   .pipe(notify('Copied <%= file.relative %> to <%= file.path %>')),
 done();
}

Terminal view

enter image description here

I would like the terminal to simply say *Copied quick-scope-for-6.mp4 to \dist\assets\video*

I have tried <%= folder.path %> and <%= directory.path %>

MrThunder
  • 725
  • 12
  • 21

1 Answers1

2

With the form of notify(Function) (as documented here), you can use the built-in path.relative method to get the destination path relative to your project folder.

var path = require('path');
// ...

function copyVideo (done) {
  // Locate files
  return gulp.src('./src/assets/video/*')
  // Copy the files to the dist folder
  .pipe(gulp.dest('./dist/assets/video'))
  // Notify the files copied in the terminal
  .pipe(notify(file => {
    var destFolder = path.dirname(file.path);
    var projectFolder = path.dirname(module.id); // Also available as `module.path`
    return `Copied ${file.relative} to ${path.relative(projectFolder, destFolder)}`;
  })),
  done();
}
Avraham
  • 928
  • 4
  • 12
  • Hi Avraham, I can confirm that the gulp-notify output was "gulp-notify: [Gulp notification] Copied quick-scope-for-6.mp4 to dist\assets\video". This solution worked perfectly and is exactly the result i required. Thanks!! – MrThunder Jul 13 '20 at 15:09