繁体   English   中英

使用 Gulp-Notify 在终端中显示项目文件夹路径,而不是硬盘上项目的整个路径

[英]Display project folder path in the terminal with Gulp-Notify instead of entire path of project on hard drive

我正在使用gulp-notify在运行任务时在终端中显示额外信息。 目前我只能获得我的高清和文件名的完整路径。 我宁愿只显示项目文件夹,因为它更干净。

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();
}

终端视图

在此处输入图像描述

我希望终端简单地说 *Copied quick-scope-for-6.mp4 to \dist\assets\video*

我试过 <%= folder.path %> 和 <%= directory.path %>

使用notify(Function)的形式(如此所述),您可以使用内置的path.relative方法来获取相对于您的项目文件夹的目标路径。

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();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM