UNPKG

1.41 kBTypeScriptView Raw
1import IUrlFetcher from './IUrlFetcher';
2/**
3 * A utility base class for the `Parser` and `Generator` classes
4 * providing a convenient interface to a filesystem folder and HTTP requests
5 */
6export default abstract class Doer {
7 /**
8 * The directory to scan for relevant files
9 */
10 folder: string;
11 /**
12 * The instance of IUrlFetcher to fetch URLs
13 */
14 protected readonly urlFetcher: IUrlFetcher;
15 constructor(urlFetcher: IUrlFetcher, folder: string | undefined);
16 /**
17 * Does a path exist within the project folder?
18 *
19 * @param subpath The path within the folder
20 */
21 exists(subpath: string): boolean;
22 /**
23 * Get a list of paths that match a pattern in the project folder.
24 *
25 * @param pattern The glob pattern
26 */
27 glob(pattern: string | Array<string>): Array<string>;
28 /**
29 * Read a file within the project folder
30 *
31 * @param subpath The path within the folder
32 */
33 read(subpath: string): string;
34 /**
35 * Write to a file within the project folder
36 *
37 * @param subpath The path within the folder
38 * @param content The content to write to the file
39 */
40 write(subpath: string, content: string): void;
41 /**
42 * Fetch content from a URL
43 *
44 * @param url The URL to fetch
45 * @param options Request options
46 */
47 fetch(url: string, options?: any): Promise<any>;
48}