1 | import { Microgrammar } from "@atomist/microgrammar";
|
2 | import { PatternMatch } from "@atomist/microgrammar/lib/PatternMatch";
|
3 | import { File } from "../File";
|
4 | import { ProjectAsync } from "../Project";
|
5 | import { GlobOptions } from "./projectUtils";
|
6 | export declare type Match<M> = M & PatternMatch;
|
7 | /**
|
8 | * Matches within a particular file
|
9 | */
|
10 | export interface FileWithMatches<M> {
|
11 | file: File;
|
12 | content: string;
|
13 | matches: Array<Match<M>>;
|
14 | /**
|
15 | * Make matches updatable
|
16 | */
|
17 | makeUpdatable(): void;
|
18 | }
|
19 | /**
|
20 | * Options for microgrammar matching
|
21 | */
|
22 | export interface Opts {
|
23 | /**
|
24 | * Should we make the results updatable?
|
25 | */
|
26 | makeUpdatable?: boolean;
|
27 | /**
|
28 | * If specified, transforms content of each file matched
|
29 | * by the glob before running the microgrammar.
|
30 | * Used to remove comments etc.
|
31 | * @param {string} content
|
32 | * @return {string}
|
33 | */
|
34 | contentTransformer?: (content: string) => string;
|
35 | }
|
36 | export declare const DefaultOpts: Opts;
|
37 | /**
|
38 | * Integrate microgrammars with project operations to find all matches
|
39 | * @param p project
|
40 | * @param globPatterns file glob patterns
|
41 | * @param microgrammar microgrammar to run against each eligible file
|
42 | * @param opts options
|
43 | */
|
44 | export declare function findMatches<M>(p: ProjectAsync, globPatterns: GlobOptions, microgrammar: Microgrammar<M>, opts?: Opts): Promise<Array<Match<M>>>;
|
45 | /**
|
46 | * Integrate microgrammars with project operations to find all matches
|
47 | * @param p project
|
48 | * @param globPatterns file glob patterns
|
49 | * @param microgrammar microgrammar to run against each eligible file
|
50 | * @param opts options
|
51 | */
|
52 | export declare function findFileMatches<M>(p: ProjectAsync, globPatterns: GlobOptions, microgrammar: Microgrammar<M>, opts?: Opts): Promise<Array<FileWithMatches<M>>>;
|
53 | /**
|
54 | * Manipulate each file match containing an actual match. Will automatically match if necessary.
|
55 | * @param p project
|
56 | * @param {string} globPatterns
|
57 | * @param {Microgrammar<M>} microgrammar
|
58 | * @param {(fh: FileWithMatches<M>) => void} action
|
59 | * @param opts options
|
60 | */
|
61 | export declare function doWithFileMatches<M, P extends ProjectAsync = ProjectAsync>(p: P, globPatterns: GlobOptions, microgrammar: Microgrammar<M>, action: (fh: FileWithMatches<M>) => void, opts?: Opts): Promise<P>;
|
62 | /**
|
63 | * Convenience function to operate on matches in the project.
|
64 | * Works regardless of the number of matches
|
65 | * @param p project
|
66 | * @param {string} globPatterns
|
67 | * @param {Microgrammar<M>} microgrammar
|
68 | * @param {(m: M) => void} action
|
69 | * @param {{makeUpdatable: boolean}} opts
|
70 | */
|
71 | export declare function doWithMatches<M, P extends ProjectAsync = ProjectAsync>(p: P, globPatterns: GlobOptions, microgrammar: Microgrammar<M>, action: (m: M) => void, opts?: Opts): Promise<P>;
|
72 | /**
|
73 | * Convenience function to operate on the sole match in the project.
|
74 | * Fail if zero or more than one.
|
75 | * @param p project
|
76 | * @param {string} globPatterns
|
77 | * @param {Microgrammar<M>} microgrammar
|
78 | * @param {(m: M) => void} action
|
79 | * @param {{makeUpdatable: boolean}} opts
|
80 | */
|
81 | export declare function doWithUniqueMatch<M, P extends ProjectAsync = ProjectAsync>(p: P, globPatterns: GlobOptions, microgrammar: Microgrammar<M>, action: (m: M) => void, opts?: Opts): Promise<P>;
|
82 | /**
|
83 | * Similar to doWithUniqueMatch, but accepts zero matches without error
|
84 | * @param p project
|
85 | * @param {string} globPatterns
|
86 | * @param {Microgrammar<M>} microgrammar
|
87 | * @param {(m: M) => void} action
|
88 | * @param {{makeUpdatable: boolean}} opts
|
89 | */
|
90 | export declare function doWithAtMostOneMatch<M, P extends ProjectAsync = ProjectAsync>(p: P, globPatterns: GlobOptions, microgrammar: Microgrammar<M>, action: (m: M) => void, opts?: Opts): Promise<P>;
|