如何删除与 glob 数组中的基本名称匹配的所有文件?

How do I delete all files that match the basename in an array of globs?

我的 gulpfile 中有一个现有的 build 任务,它将 "source" 文件的集合转换为 "dist" 文件。我有一组众所周知的文件名,告诉我的 build 任务要操作哪些文件:

sourceFiles: [
    "./js/source/hoobly.js",
    "./js/source/hoo.js"
    ]

我的 build 任务由此生成以下文件:

我现在想编写一个相应的 clean 任务来删除在我的 build 任务期间生成的文件。不幸的是,我不能只删除 all ./js/dist/ 目录中的文件,因为它包含其他不是由相关 build 任务生成的文件,所以我需要确保我删除的文件与原始 sourceFiles.

的 "basename" 匹配

我的问题是:如何使用 sourceFiles 数组和 "munging"* 它,以便我最终可以调用类似的东西:

gulp.src(sourceFiles)
    .pipe(munge()) // I don't know what to do here!!
    .pipe(del());  // does a `del ./js/dist/hoobly.*`
                   // and a  `del ./js/dist/hoo.*`

(*技术术语,"munge"...)

你能给我指出正确的方向吗?我查看了各种 NPM 包(vinyl-paths、gulp-map-files、gulp-glob,...),但我越来越迷路了。

我会在将 glob 传递给 gulp.src:

之前更改它们

var sourceFiles = [
    "./js/source/hoobly.js",
    "./js/source/hoo.js"
    ];
    
var filesToDelete = sourceFiles.map(f=>f.replace("/source/", "/dist/").replace(".js", ".*"));

console.log(filesToDelete)

并省略 munge 步骤:

gulp.src(filesToDelete).pipe(del())