multiple glob patterns (#287)

This commit is contained in:
eric sciple
2020-01-09 15:05:31 -05:00
committed by GitHub
parent 683245ad5e
commit 1a2c592903
7 changed files with 547 additions and 380 deletions

View File

@@ -1,41 +1,9 @@
import * as core from '@actions/core'
import * as pathHelper from './internal-path-helper'
import {IGlobOptions} from './internal-glob-options'
import {MatchKind} from './internal-match-kind'
import {Pattern} from './internal-pattern'
const IS_WINDOWS = process.platform === 'win32'
/**
* Returns a copy with defaults filled in
*/
export function getOptions(copy?: IGlobOptions): IGlobOptions {
const result: IGlobOptions = {
followSymbolicLinks: true,
implicitDescendants: true,
omitBrokenSymbolicLinks: true
}
if (copy) {
if (typeof copy.followSymbolicLinks === 'boolean') {
result.followSymbolicLinks = copy.followSymbolicLinks
core.debug(`followSymbolicLinks '${result.followSymbolicLinks}'`)
}
if (typeof copy.implicitDescendants === 'boolean') {
result.implicitDescendants = copy.implicitDescendants
core.debug(`implicitDescendants '${result.implicitDescendants}'`)
}
if (typeof copy.omitBrokenSymbolicLinks === 'boolean') {
result.omitBrokenSymbolicLinks = copy.omitBrokenSymbolicLinks
core.debug(`omitBrokenSymbolicLinks '${result.omitBrokenSymbolicLinks}'`)
}
}
return result
}
/**
* Given an array of patterns, returns an array of paths to search.
* Duplicates and paths under other included paths are filtered out.
@@ -105,36 +73,6 @@ export function match(patterns: Pattern[], itemPath: string): MatchKind {
return result
}
/**
* Parses the pattern strings into Pattern objects
*/
export function parse(patterns: string[], options: IGlobOptions): Pattern[] {
const result: Pattern[] = []
for (const patternString of patterns.map(x => x.trim())) {
// Skip empty or comment
if (!patternString || patternString.startsWith('#')) {
continue
}
// Push
const pattern = new Pattern(patternString)
result.push(pattern)
// Implicit descendants?
if (
options.implicitDescendants &&
(pattern.trailingSeparator ||
pattern.segments[pattern.segments.length - 1] !== '**')
) {
// Push
result.push(new Pattern(pattern.negate, pattern.segments.concat('**')))
}
}
return result
}
/**
* Checks whether to descend further into the directory
*/