2

我有一个执行结帐的 gulp git 任务,因此更改了当前的工作目录。

我也有重新编译更改文件的 gulp watch 任务。

如果任何监视任务正在运行,我不想运行 git 任务。它会重新编译新分支中的文件。

有没有办法检测 gulp watch 任务是否正在运行?如果是这样,我可以简单地退出 git 任务并显示警告消息。

4

2 回答 2

1

您可以为此使用gulp-if 插件

isWatching例如,创建一个变量,并在运行watch任务时将其设置为true Then,在运行 git 的任务中,您可以执行以下操作:if(!isWatching, runGit),其中 runGit 将是执行 git 任务或其他任何内容的函数


PasteBin 示例(用于颜色编码)

于 2014-08-01T13:48:00.013 回答
0

使用环境变量解决

gulp.task("build-typescript", () => {
     if (process.env.IS_GULP_WATCH !== 'true') {
         // this is gulp watch
     }        
     else
     {
         // this is not gulp watch
     }
});

gulp.task('watch-typescript', () => {
    process.env.IS_GULP_WATCH = 'true';
    // watch files
});
于 2018-10-30T03:51:18.027 回答