gulpTasks-watch.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. gulp.task("watch", function startWatch() {
  26. var tasks = [];
  27. config.modules.map(function(module) {
  28. var settings = config[module].build;
  29. if (settings && settings.webpack) {
  30. for (var index = 0; index < config[module].libraries.length; index++) {
  31. var library = config[module].libraries[index];
  32. if (library.preventLoadLibrary) {
  33. continue;
  34. }
  35. let wpconfig = require(settings.webpack);
  36. // watch on.
  37. wpconfig.watch = true;
  38. // dev mode and absolute path sourcemaps for debugging
  39. wpconfig.mode = "development";
  40. wpconfig.output.devtoolModuleFilenameTemplate = "[absolute-resource-path]";
  41. //config.stats = "minimal";
  42. var outputDirectory = config.build.tempDirectory + settings.distOutputDirectory;
  43. tasks.push(webpackStream(wpconfig, webpack).pipe(gulp.dest(outputDirectory)))
  44. tasks.push(gulp.src(settings.srcDirectory + "**/*.fx")
  45. .pipe(uncommentShaders())
  46. .pipe(processShaders())
  47. );
  48. tasks.push(
  49. gulp.watch(settings.srcDirectory + "**/*.fx", { interval: 1000 }, function() {
  50. console.log(library.output + ": Shaders.");
  51. gulp.src(settings.srcDirectory + "**/*.fx")
  52. .pipe(uncommentShaders())
  53. .pipe(processShaders());
  54. })
  55. );
  56. }
  57. }
  58. });
  59. return Promise.resolve();
  60. });
  61. //}));