[英]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.