source: trip-planner-front/node_modules/fast-glob/out/managers/tasks.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.9 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.convertPatternGroupToTask = exports.convertPatternGroupsToTasks = exports.groupPatternsByBaseDirectory = exports.getNegativePatternsAsPositive = exports.getPositivePatterns = exports.convertPatternsToTasks = exports.generate = void 0;
4const utils = require("../utils");
5function 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}
14exports.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 */
21function 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}
40exports.convertPatternsToTasks = convertPatternsToTasks;
41function getPositivePatterns(patterns) {
42 return utils.pattern.getPositivePatterns(patterns);
43}
44exports.getPositivePatterns = getPositivePatterns;
45function getNegativePatternsAsPositive(patterns, ignore) {
46 const negative = utils.pattern.getNegativePatterns(patterns).concat(ignore);
47 const positive = negative.map(utils.pattern.convertToPositivePattern);
48 return positive;
49}
50exports.getNegativePatternsAsPositive = getNegativePatternsAsPositive;
51function 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}
64exports.groupPatternsByBaseDirectory = groupPatternsByBaseDirectory;
65function convertPatternGroupsToTasks(positive, negative, dynamic) {
66 return Object.keys(positive).map((base) => {
67 return convertPatternGroupToTask(base, positive[base], negative, dynamic);
68 });
69}
70exports.convertPatternGroupsToTasks = convertPatternGroupsToTasks;
71function 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}
80exports.convertPatternGroupToTask = convertPatternGroupToTask;
Note: See TracBrowser for help on using the repository browser.