Guest User

Untitled

a guest
Jul 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. const exec = require("child_process").exec;
  2. const gulp = require("gulp");
  3. const {
  4. bundles, modules
  5. } = require("./gulpfile.json");
  6. for (const bundle in bundles) {
  7. const tasks = bundles[bundle];
  8. for (const task_name in tasks) {
  9. try {
  10. const task = tasks[task_name];
  11. gulp.task(task_name, () => {
  12. const gulp_watch = require("gulp-watch");
  13. let pipe_part;
  14. if (task.watch) {
  15. pipe_part = gulp_watch(task.src, modules["gulp-watch"]);
  16. } else {
  17. pipe_part = gulp.src(task.src);
  18. }
  19. for (const part of task.chain) {
  20. const module_name = typeof part == "string" ? part : part.module;
  21. let pipe_function = require(module_name);
  22. if (typeof pipe_function != "function") {
  23. pipe_function = pipe_function.default;
  24. }
  25. const settings = Object.assign({}, part.settings, modules[module_name]);
  26. pipe_part = pipe_part.pipe(pipe_function(settings));
  27. pipe_part.on("error", error => console.error(error.toString()));
  28. }
  29. if (task.dest !== undefined) {
  30. pipe_part = pipe_part.pipe(gulp.dest(task.dest));
  31. }
  32. return pipe_part;
  33. });
  34. } catch (e) {
  35. console.error(e);
  36. }
  37. }
  38. gulp.task(bundle, gulp.parallel(Object.getOwnPropertyNames(tasks)));
  39. gulp.task("init-" + bundle, () => new Promise((resolve, reject) => {
  40. exec("npm install --save-dev gulp-watch " + Object.getOwnPropertyNames(modules).join(" "), error => {
  41. (error ? reject : resolve)();
  42. });
  43. }));
  44. }
  45. {
  46. const bundle_array = Object.getOwnPropertyNames(bundles);
  47. gulp.task("default", gulp.parallel(bundle_array));
  48. gulp.task("init", gulp.series(bundle_array.map(bundle => "init-" + bundle)));
  49. }
Add Comment
Please, Sign In to add comment