gulpTasks-watch.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Import Dependencies.
  2. var gulp = require("gulp");
  3. var webpack = require('webpack');
  4. var webpackStream = require("webpack-stream");
  5. var processShaders = require("../helpers/gulp-processShaders");
  6. var uncommentShaders = require('../helpers/gulp-removeShaderComments');
  7. // Read the full config.
  8. var config = require("../config.json");
  9. /**
  10. * Watch ts files from typescript .
  11. * Hack into the cli :-)
  12. */
  13. gulp.task("srcTscWatch", function() {
  14. // Reuse The TSC CLI from gulp to enable -w.
  15. process.argv[2] = "-w";
  16. process.argv[3] = "-p";
  17. process.argv[4] = "../../src/tsconfig.json";
  18. require("../../../node_modules/typescript/lib/tsc.js");
  19. return Promise.resolve();
  20. });
  21. /**
  22. * Watch ts files and fire repective tasks.
  23. */
  24. gulp.task("watch", gulp.series("srcTscWatch", function startWatch() {
  25. var tasks = [];
  26. config.modules.map(function(module) {
  27. var settings = config[module].build;
  28. if (settings && settings.webpack) {
  29. for (var index = 0; index < config[module].libraries.length; index++) {
  30. var library = config[module].libraries[index];
  31. if (library.preventLoadLibrary) {
  32. continue;
  33. }
  34. let wpconfig = require(settings.webpack);
  35. // watch on.
  36. wpconfig.watch = true;
  37. // dev mode and absolute path sourcemaps for debugging
  38. wpconfig.mode = "development";
  39. wpconfig.output.devtoolModuleFilenameTemplate = "[absolute-resource-path]";
  40. //config.stats = "minimal";
  41. var outputDirectory = config.build.tempDirectory + settings.distOutputDirectory;
  42. tasks.push(webpackStream(wpconfig, webpack).pipe(gulp.dest(outputDirectory)))
  43. tasks.push(gulp.src(settings.srcDirectory + "**/*.fx")
  44. .pipe(uncommentShaders())
  45. .pipe(processShaders())
  46. );
  47. tasks.push(
  48. gulp.watch(settings.srcDirectory + "**/*.fx", { interval: 1000 }, function() {
  49. console.log(library.output + ": Shaders.");
  50. gulp.src(settings.srcDirectory + "**/*.fx")
  51. .pipe(uncommentShaders())
  52. .pipe(processShaders());
  53. })
  54. );
  55. }
  56. }
  57. });
  58. return Promise.resolve();
  59. }));