瀏覽代碼

Fix watch shaders

sebavan 6 年之前
父節點
當前提交
b5a9690fa4
共有 2 個文件被更改,包括 44 次插入14 次删除
  1. 21 6
      Tools/Gulp/tasks/gulpTasks-watchCore.js
  2. 23 8
      Tools/Gulp/tasks/gulpTasks-watchLibraries.js

+ 21 - 6
Tools/Gulp/tasks/gulpTasks-watchCore.js

@@ -17,12 +17,12 @@ var module = "core";
 /**
  * Process shader ts files.
  */
-gulp.task("watchCore-cleanShaders", async function startWatch() {
+gulp.task("watchCore-cleanShaders", function startWatch(cb) {
     var settings = config[module].computed;
 
     // Clean shaders.
-    await del(settings.shaderTSGlob, { force: true });
-
+    del(settings.shaderTSGlob, { force: true });
+    
     // Generate shaders.
     return gulp.src(settings.shaderGlob)
         .pipe(uncommentShaders())
@@ -32,7 +32,7 @@ gulp.task("watchCore-cleanShaders", async function startWatch() {
 /**
  * Watch ts files and fire repective tasks.
  */
-gulp.task("watchCore", gulp.series("watchCore-cleanShaders", async function() {
+gulp.task("watchCore", gulp.series("watchCore-cleanShaders", function() {
     var settings = config[module].computed;
     var library = config[module].libraries[0];
 
@@ -58,9 +58,24 @@ gulp.task("watchCore", gulp.series("watchCore-cleanShaders", async function() {
     });
 
     // Launch shader watch.
-    gulp.watch(settings.shaderGlob, { interval: 1000 }, function() {
+    var watch = gulp.watch(settings.shaderGlob, { interval: 1000 }, function() {
         console.log(library.output + ": Shaders.");
-        return gulp.src(settings.shaderGlob)
+    })
+    watch.on("add", (event) => {
+        console.log(event);
+        return gulp.src(event)
+            .pipe(uncommentShaders())
+            .pipe(processShaders(true));
+    });
+    watch.on("change", (event) => {
+        console.log(event);
+        return gulp.src(event)
+            .pipe(uncommentShaders())
+            .pipe(processShaders(true));
+    });
+    watch.on("unlink", (event) => {
+        console.log(event);
+        return gulp.src(event)
             .pipe(uncommentShaders())
             .pipe(processShaders(true));
     });

+ 23 - 8
Tools/Gulp/tasks/gulpTasks-watchLibraries.js

@@ -55,14 +55,29 @@ gulp.task("watchLibraries", function startWatch() {
                         .pipe(gulp.dest(outputDirectory))
                 );
 
-                tasks.push(
-                    gulp.watch(settings.shaderGlob, { interval: 1000 }, function() {
-                        console.log(library.output + ": Shaders.");
-                        return gulp.src(settings.shaderGlob)
-                            .pipe(uncommentShaders())
-                            .pipe(processShaders(false));
-                    })
-                );
+                var watch = gulp.watch(settings.shaderGlob, { interval: 1000 }, function() {
+                    console.log(library.output + ": Shaders.");
+                })
+                watch.on("add", (event) => {
+                    console.log(event);
+                    return gulp.src(event)
+                    .pipe(uncommentShaders())
+                    .pipe(processShaders(false));
+                });
+                watch.on("change", (event) => {
+                    console.log(event);
+                    return gulp.src(event)
+                    .pipe(uncommentShaders())
+                    .pipe(processShaders(false));
+                });
+                watch.on("unlink", (event) => {
+                    console.log(event);
+                    return gulp.src(event)
+                    .pipe(uncommentShaders())
+                    .pipe(processShaders(false));
+                });
+
+                tasks.push(watch);
             }
         }
     });