gpt4 book ai didi

javascript - 吞下目的地 : warn if 2 tasks try to write to the same destination

转载 作者:行者123 更新时间:2023-12-03 08:21:08 24 4
gpt4 key购买 nike

我想知道是否有一种简单的方法来检测两个任务是否写入同一个文件。

在此示例中,有一个 /js 目录和一个 /ts 目录。 /ts 将被转译到与 /js 相同的目录。不应该有任何冲突。要求是,如果发生冲突,ts 将获胜;但是,我想警告一下,存在碰撞。

gulp.task('js', function() {
return es.concat(
gulp.src(config.src.path('js', '**', '*.js'))
.pipe(gulp.dest(config.build.path(app, 'js')))
//, ....
);
});

gulp.task('ts', ['js'], function() {

var tsResult = gulp.src(config.src.path('ts', '**', '*.ts'))
.pipe(ts({
declaration: true,
noExternalResolve: true
}));

return es.concat([
tsResult.dts.pipe(gulp.dest(
config.build.path(app, 'definitions'))),

tsResult.js.pipe(gulp.dest(
config.build.path(app, 'js'))) // <--- same dest as js task
]);

})

我能否检测到 ts 任务正在覆盖 js 任务刚刚放置的文件?

最佳答案

只是一个想法。您可以pass a callbackgulp.dest 像这样:

gulp.src('lib/*.js')
.pipe(uglify())
.pipe(gulp.src('styles/*.css'))
.pipe(gulp.dest(function(file) {
if (fs.existsSync('something here')) { // it's a deprecated call, use a newer one
console.warn("File exists", file);
}
// I don't know, you can do something cool here
return 'build/whatever';
}));

该功能自 Gulp 3.8 起可用:https://github.com/gulpjs/gulp/blob/master/CHANGELOG.md#380

其他资源:

关于javascript - 吞下目的地 : warn if 2 tasks try to write to the same destination,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33742880/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com