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