gulpTasks-watchCore.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Import Dependencies.
  2. var gulp = require("gulp");
  3. let shelljs = require('shelljs');
  4. var del = require("del");
  5. // Import Helpers.
  6. var processShaders = require("../helpers/gulp-processShaders");
  7. var uncommentShaders = require('../helpers/gulp-removeShaderComments');
  8. var rmDir = require("../../NodeHelpers/rmDir");
  9. // Read the full config.
  10. var config = require("../../Config/config.js");
  11. // Constants
  12. var module = "core";
  13. /**
  14. * Process shader ts files.
  15. */
  16. gulp.task("watchCore-cleanShaders", async function startWatch() {
  17. var settings = config[module].computed;
  18. // Clean shaders.
  19. await del(settings.shaderTSGlob, { force: true });
  20. // Generate shaders.
  21. return gulp.src(settings.shaderGlob)
  22. .pipe(uncommentShaders())
  23. .pipe(processShaders(true));
  24. });
  25. /**
  26. * Watch ts files and fire repective tasks.
  27. */
  28. gulp.task("watchCore", gulp.series("watchCore-cleanShaders", async function() {
  29. var settings = config[module].computed;
  30. var library = config[module].libraries[0];
  31. // Generate output path.
  32. var outputDirectory = settings.localDevES6Directory;
  33. // Clean Folder.
  34. rmDir(outputDirectory);
  35. // Launch TSC.
  36. const options = {
  37. cwd: settings.srcDirectory,
  38. async: true,
  39. verbose: true
  40. };
  41. shelljs.exec(`tsc --importHelpers false --isolatedModules true --declaration false --target es5 --module es2015 --outDir "${outputDirectory}" -w`, options, function(code, stdout, stderr) {
  42. if (stderr) {
  43. console.log(stderr);
  44. }
  45. if (stdout) {
  46. console.log(stdout);
  47. }
  48. });
  49. // Launch shader watch.
  50. gulp.watch(settings.shaderGlob, { interval: 1000 }, function() {
  51. console.log(library.output + ": Shaders.");
  52. return gulp.src(settings.shaderGlob)
  53. .pipe(uncommentShaders())
  54. .pipe(processShaders(true));
  55. });
  56. }));