首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在终端中使用Gulp-Notify显示项目文件夹路径,而不是硬盘上项目的整个路径

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

Stack Overflow用户
提问于 2020-07-05 23:34:44
回答 1查看 59关注 0票数 2

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

代码语言:javascript
复制
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();
}

终端视图

我希望终端简单地说*将快速范围-for-6.mp4复制到\dist\assets\video*

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-13 17:34:08

通过notify(Function) (文档中的here)的形式,您可以使用内置的path.relative方法来获取相对于项目文件夹的目标路径。

代码语言:javascript
复制
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();
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62742789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档