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 | /**
|
---|
16 | * Returns tasks grouped by basic pattern directories.
|
---|
17 | *
|
---|
18 | * Patterns that can be found inside (`./`) and outside (`../`) the current directory are handled separately.
|
---|
19 | * This is necessary because directory traversal starts at the base directory and goes deeper.
|
---|
20 | */
|
---|
21 | function convertPatternsToTasks(positive, negative, dynamic) {
|
---|
22 | const tasks = [];
|
---|
23 | const patternsOutsideCurrentDirectory = utils.pattern.getPatternsOutsideCurrentDirectory(positive);
|
---|
24 | const patternsInsideCurrentDirectory = utils.pattern.getPatternsInsideCurrentDirectory(positive);
|
---|
25 | const outsideCurrentDirectoryGroup = groupPatternsByBaseDirectory(patternsOutsideCurrentDirectory);
|
---|
26 | const insideCurrentDirectoryGroup = groupPatternsByBaseDirectory(patternsInsideCurrentDirectory);
|
---|
27 | tasks.push(...convertPatternGroupsToTasks(outsideCurrentDirectoryGroup, negative, dynamic));
|
---|
28 | /*
|
---|
29 | * For the sake of reducing future accesses to the file system, we merge all tasks within the current directory
|
---|
30 | * into a global task, if at least one pattern refers to the root (`.`). In this case, the global task covers the rest.
|
---|
31 | */
|
---|
32 | if ('.' in insideCurrentDirectoryGroup) {
|
---|
33 | tasks.push(convertPatternGroupToTask('.', patternsInsideCurrentDirectory, negative, dynamic));
|
---|
34 | }
|
---|
35 | else {
|
---|
36 | tasks.push(...convertPatternGroupsToTasks(insideCurrentDirectoryGroup, negative, dynamic));
|
---|
37 | }
|
---|
38 | return tasks;
|
---|
39 | }
|
---|
40 | exports.convertPatternsToTasks = convertPatternsToTasks;
|
---|
41 | function getPositivePatterns(patterns) {
|
---|
42 | return utils.pattern.getPositivePatterns(patterns);
|
---|
43 | }
|
---|
44 | exports.getPositivePatterns = getPositivePatterns;
|
---|
45 | function getNegativePatternsAsPositive(patterns, ignore) {
|
---|
46 | const negative = utils.pattern.getNegativePatterns(patterns).concat(ignore);
|
---|
47 | const positive = negative.map(utils.pattern.convertToPositivePattern);
|
---|
48 | return positive;
|
---|
49 | }
|
---|
50 | exports.getNegativePatternsAsPositive = getNegativePatternsAsPositive;
|
---|
51 | function groupPatternsByBaseDirectory(patterns) {
|
---|
52 | const group = {};
|
---|
53 | return patterns.reduce((collection, pattern) => {
|
---|
54 | const base = utils.pattern.getBaseDirectory(pattern);
|
---|
55 | if (base in collection) {
|
---|
56 | collection[base].push(pattern);
|
---|
57 | }
|
---|
58 | else {
|
---|
59 | collection[base] = [pattern];
|
---|
60 | }
|
---|
61 | return collection;
|
---|
62 | }, group);
|
---|
63 | }
|
---|
64 | exports.groupPatternsByBaseDirectory = groupPatternsByBaseDirectory;
|
---|
65 | function convertPatternGroupsToTasks(positive, negative, dynamic) {
|
---|
66 | return Object.keys(positive).map((base) => {
|
---|
67 | return convertPatternGroupToTask(base, positive[base], negative, dynamic);
|
---|
68 | });
|
---|
69 | }
|
---|
70 | exports.convertPatternGroupsToTasks = convertPatternGroupsToTasks;
|
---|
71 | function convertPatternGroupToTask(base, positive, negative, dynamic) {
|
---|
72 | return {
|
---|
73 | dynamic,
|
---|
74 | positive,
|
---|
75 | negative,
|
---|
76 | base,
|
---|
77 | patterns: [].concat(positive, negative.map(utils.pattern.convertToNegativePattern))
|
---|
78 | };
|
---|
79 | }
|
---|
80 | exports.convertPatternGroupToTask = convertPatternGroupToTask;
|
---|