Node.js 以编程方式将目录名作为字符串传递给gulp rename

Node.js 以编程方式将目录名作为字符串传递给gulp rename,node.js,gulp,gulp-rename,Node.js,Gulp,Gulp Rename,是否可以将父目录的名称传递给gulp rename或任何其他重命名插件?我试图以编程方式连接“src”文件夹中的所有文件,并用它们的父目录名重命名它们。下面的代码是我到目前为止的代码 gulp.task('js-test', function() { return gulp.src('dev/scripts/**/src/*.min.js') .pipe(concat('interim-name.js')) .pipe(rename('How do I g

是否可以将父目录的名称传递给gulp rename或任何其他重命名插件?我试图以编程方式连接“src”文件夹中的所有文件,并用它们的父目录名重命名它们。下面的代码是我到目前为止的代码

gulp.task('js-test', function() {
    return gulp.src('dev/scripts/**/src/*.min.js')
        .pipe(concat('interim-name.js'))
        .pipe(rename('How do I give it the name of the parent directory of src'))
        .pipe(gulp.dest('dev/scripts'))
});
最终结果如下所示:

发展 剧本 独自创立 Src alert.js文件 alert.js.map文件 alert.min.js文件 tooltip.js文件 tooltip.js.map文件 tooltip.min.js文件 bootstrap.js bootstrap.min.js 真棒 Src 文件-1.js file-1.js.map文件 file-1.min.js文件 文件-2.js file-2.js.map文件 file-2.min.js文件 文件-3.js file-3.js.map文件 file-3.min.js文件 Fontsome.js font.min.js 具有使用函数的选项,例如来自文档:

// rename via function 
gulp.src("./src/**/hello.txt")
 .pipe(rename(function (path) {
     path.dirname += "/ciao";
     path.basename += "-goodbye";
     path.extname = ".md"
 }))
 .pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md 
因此,我将注销path.dirname,然后对其进行字符串操作:

.pipe(rename(function (path) {

   // I use nodePath.sep here but you may have to require path for it to work
   // var nodePath = require('path');
   // but maybe just path.sep without the require will work just fine

   var temp = path.dirname.split(nodePath.sep);
   path.basename = temp[some index here];
}))