Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.3 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var patternUtils = require("../utils/pattern");
  4. /**
  5. * Generate tasks based on parent directory of each pattern.
  6. */
  7. function generate(patterns, options) {
  8. var unixPatterns = patterns.map(patternUtils.unixifyPattern);
  9. var unixIgnore = options.ignore.map(patternUtils.unixifyPattern);
  10. var positivePatterns = getPositivePatterns(unixPatterns);
  11. var negativePatterns = getNegativePatternsAsPositive(unixPatterns, unixIgnore);
  12. var staticPatterns = positivePatterns.filter(patternUtils.isStaticPattern);
  13. var dynamicPatterns = positivePatterns.filter(patternUtils.isDynamicPattern);
  14. var staticTasks = convertPatternsToTasks(staticPatterns, negativePatterns, /* dynamic */ false);
  15. var dynamicTasks = convertPatternsToTasks(dynamicPatterns, negativePatterns, /* dynamic */ true);
  16. return staticTasks.concat(dynamicTasks);
  17. }
  18. exports.generate = generate;
  19. /**
  20. * Convert patterns to tasks based on parent directory of each pattern.
  21. */
  22. function convertPatternsToTasks(positive, negative, dynamic) {
  23. var positivePatternsGroup = groupPatternsByBaseDirectory(positive);
  24. // When we have a global group – there is no reason to divide the patterns into independent tasks.
  25. // In this case, the global task covers the rest.
  26. if ('.' in positivePatternsGroup) {
  27. var task = convertPatternGroupToTask('.', positive, negative, dynamic);
  28. return [task];
  29. }
  30. return convertPatternGroupsToTasks(positivePatternsGroup, negative, dynamic);
  31. }
  32. exports.convertPatternsToTasks = convertPatternsToTasks;
  33. /**
  34. * Return only positive patterns.
  35. */
  36. function getPositivePatterns(patterns) {
  37. return patternUtils.getPositivePatterns(patterns);
  38. }
  39. exports.getPositivePatterns = getPositivePatterns;
  40. /**
  41. * Return only negative patterns.
  42. */
  43. function getNegativePatternsAsPositive(patterns, ignore) {
  44. var negative = patternUtils.getNegativePatterns(patterns).concat(ignore);
  45. var positive = negative.map(patternUtils.convertToPositivePattern);
  46. return positive;
  47. }
  48. exports.getNegativePatternsAsPositive = getNegativePatternsAsPositive;
  49. /**
  50. * Group patterns by base directory of each pattern.
  51. */
  52. function groupPatternsByBaseDirectory(patterns) {
  53. return patterns.reduce(function (collection, pattern) {
  54. var base = patternUtils.getBaseDirectory(pattern);
  55. if (base in collection) {
  56. collection[base].push(pattern);
  57. }
  58. else {
  59. collection[base] = [pattern];
  60. }
  61. return collection;
  62. }, {});
  63. }
  64. exports.groupPatternsByBaseDirectory = groupPatternsByBaseDirectory;
  65. /**
  66. * Convert group of patterns to tasks.
  67. */
  68. function convertPatternGroupsToTasks(positive, negative, dynamic) {
  69. return Object.keys(positive).map(function (base) {
  70. return convertPatternGroupToTask(base, positive[base], negative, dynamic);
  71. });
  72. }
  73. exports.convertPatternGroupsToTasks = convertPatternGroupsToTasks;
  74. /**
  75. * Create a task for positive and negative patterns.
  76. */
  77. function convertPatternGroupToTask(base, positive, negative, dynamic) {
  78. return {
  79. base: base,
  80. dynamic: dynamic,
  81. patterns: [].concat(positive, negative.map(patternUtils.convertToNegativePattern)),
  82. positive: positive,
  83. negative: negative
  84. };
  85. }
  86. exports.convertPatternGroupToTask = convertPatternGroupToTask;