UNPKG

2.6 kBTypeScriptView Raw
1import { File } from "../File";
2import { FileStream, ProjectAsync } from "../Project";
3/**
4 * Promise of an array of files. Usually sourced from Project.streamFiles
5 */
6export declare function toPromise(stream: FileStream): Promise<File[]>;
7/**
8 * Allows conveniently passing one or many glob patterns to utility functions
9 */
10export declare type GlobOptions = string | string[];
11/**
12 * Does at least one file matching the given predicate exist in this project?
13 * If no predicate is supplied, does at least one file match the glob pattern?
14 * No guarantees about ordering
15 * @param p
16 * @param globPatterns positive and negative globs to match
17 * @param test return a boolean or promise. Defaults to true
18 * @return {Promise<boolean>}
19 */
20export declare function fileExists<T>(p: ProjectAsync, globPatterns: GlobOptions, test?: (f: File) => (boolean | Promise<boolean>)): Promise<boolean>;
21/**
22 * Count files matching the given predicate in this project
23 * If no predicate is supplied, does at least one file match the glob pattern?
24 * No guarantees about ordering
25 * @param p
26 * @param globPatterns positive and negative globs to match
27 * @param test return a boolean or promise. Defaults to true
28 * @return {Promise<boolean>}
29 */
30export declare function countFiles<T>(p: ProjectAsync, globPatterns: GlobOptions, test?: (f: File) => (boolean | Promise<boolean>)): Promise<number>;
31/**
32 * Gather values from files
33 * @param {ProjectAsync} project to act on
34 * @param {string} globPatterns glob pattern for files to match
35 * @param {(f: File) => Promise<T>} gather function returning a promise (of the value you're gathering) from each file.
36 * Undefined returns will be filtered out
37 * @return {Promise<T[]>}
38 */
39export declare function gatherFromFiles<T>(project: ProjectAsync, globPatterns: GlobOptions, gather: (f: File) => Promise<T> | undefined): Promise<T[]>;
40/**
41 * Perform the same operation on all the files.
42 * @param project project to act on
43 * @param globPatterns glob patterns to match
44 * @param op operation to perform on files. Can return void or a promise.
45 */
46export declare function doWithFiles<P extends ProjectAsync>(project: P, globPatterns: GlobOptions, op: (f: File) => void | Promise<any>): Promise<P>;
47/**
48 * Delete files matching the glob pattern and extra test (if supplied)
49 * @param project project to act on
50 * @param globPatterns glob patterns for files to delete
51 * @param test additional, optional test for files to be deleted
52 */
53export declare function deleteFiles<T>(project: ProjectAsync, globPatterns: GlobOptions, test?: (f: File) => boolean): Promise<number>;