Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.convertPatternGroupToTask = exports.convertPatternGroupsToTasks = exports.groupPatternsByBaseDirectory = exports.getNegativePatternsAsPositive = exports.getPositivePatterns = exports.convertPatternsToTasks = exports.generate = void 0;
  4. const utils = require("../utils");
  5. function generate(patterns, settings) {
  6. const positivePatterns = getPositivePatterns(patterns);
  7. const negativePatterns = getNegativePatternsAsPositive(patterns, settings.ignore);
  8. const staticPatterns = positivePatterns.filter((pattern) => utils.pattern.isStaticPattern(pattern, settings));
  9. const dynamicPatterns = positivePatterns.filter((pattern) => utils.pattern.isDynamicPattern(pattern, settings));
  10. const staticTasks = convertPatternsToTasks(staticPatterns, negativePatterns, /* dynamic */ false);
  11. const dynamicTasks = convertPatternsToTasks(dynamicPatterns, negativePatterns, /* dynamic */ true);
  12. return staticTasks.concat(dynamicTasks);
  13. }
  14. exports.generate = generate;
  15. function convertPatternsToTasks(positive, negative, dynamic) {
  16. const positivePatternsGroup = groupPatternsByBaseDirectory(positive);
  17. // When we have a global group – there is no reason to divide the patterns into independent tasks.
  18. // In this case, the global task covers the rest.
  19. if ('.' in positivePatternsGroup) {
  20. const task = convertPatternGroupToTask('.', positive, negative, dynamic);
  21. return [task];
  22. }
  23. return convertPatternGroupsToTasks(positivePatternsGroup, negative, dynamic);
  24. }
  25. exports.convertPatternsToTasks = convertPatternsToTasks;
  26. function getPositivePatterns(patterns) {
  27. return utils.pattern.getPositivePatterns(patterns);
  28. }
  29. exports.getPositivePatterns = getPositivePatterns;
  30. function getNegativePatternsAsPositive(patterns, ignore) {
  31. const negative = utils.pattern.getNegativePatterns(patterns).concat(ignore);
  32. const positive = negative.map(utils.pattern.convertToPositivePattern);
  33. return positive;
  34. }
  35. exports.getNegativePatternsAsPositive = getNegativePatternsAsPositive;
  36. function groupPatternsByBaseDirectory(patterns) {
  37. const group = {};
  38. return patterns.reduce((collection, pattern) => {
  39. const base = utils.pattern.getBaseDirectory(pattern);
  40. if (base in collection) {
  41. collection[base].push(pattern);
  42. }
  43. else {
  44. collection[base] = [pattern];
  45. }
  46. return collection;
  47. }, group);
  48. }
  49. exports.groupPatternsByBaseDirectory = groupPatternsByBaseDirectory;
  50. function convertPatternGroupsToTasks(positive, negative, dynamic) {
  51. return Object.keys(positive).map((base) => {
  52. return convertPatternGroupToTask(base, positive[base], negative, dynamic);
  53. });
  54. }
  55. exports.convertPatternGroupsToTasks = convertPatternGroupsToTasks;
  56. function convertPatternGroupToTask(base, positive, negative, dynamic) {
  57. return {
  58. dynamic,
  59. positive,
  60. negative,
  61. base,
  62. patterns: [].concat(positive, negative.map(utils.pattern.convertToNegativePattern))
  63. };
  64. }
  65. exports.convertPatternGroupToTask = convertPatternGroupToTask;