Files
toolkit/packages/glob/src/glob.ts
T

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-01-09 15:05:31 -05:00
import {Globber, DefaultGlobber} from './internal-globber'
import {GlobOptions} from './internal-glob-options'
2021-06-07 14:26:00 -04:00
import {HashFileOptions} from './internal-hash-file-options'
import {hashFiles as _hashFiles} from './internal-hash-files'
2019-12-31 10:16:18 -05:00
2020-01-09 15:05:31 -05:00
export {Globber, GlobOptions}
2019-12-31 10:16:18 -05:00
/**
2020-01-09 15:05:31 -05:00
* Constructs a globber
2019-12-31 10:16:18 -05:00
*
2020-01-09 15:05:31 -05:00
* @param patterns Patterns separated by newlines
* @param options Glob options
2019-12-31 10:16:18 -05:00
*/
2020-01-09 15:05:31 -05:00
export async function create(
patterns: string,
options?: GlobOptions
): Promise<Globber> {
return await DefaultGlobber.create(patterns, options)
2019-12-31 10:16:18 -05:00
}
2021-06-07 14:26:00 -04:00
/**
* Computes the sha256 hash of a glob
*
* @param patterns Patterns separated by newlines
2023-01-24 14:12:47 -05:00
* @param currentWorkspace Workspace used when matching files
2021-06-07 14:26:00 -04:00
* @param options Glob options
2023-01-24 14:12:47 -05:00
* @param verbose Enables verbose logging
2021-06-07 14:26:00 -04:00
*/
export async function hashFiles(
patterns: string,
2023-01-24 14:12:47 -05:00
currentWorkspace = '',
2022-04-18 20:29:24 +02:00
options?: HashFileOptions,
verbose: Boolean = false
2021-06-07 14:26:00 -04:00
): Promise<string> {
let followSymbolicLinks = true
if (options && typeof options.followSymbolicLinks === 'boolean') {
followSymbolicLinks = options.followSymbolicLinks
}
const globber = await create(patterns, {followSymbolicLinks})
2023-01-24 14:12:47 -05:00
return _hashFiles(globber, currentWorkspace, verbose)
2021-06-07 14:26:00 -04:00
}