1 | /// <reference types="node" />
|
2 | import { Stream } from "stream";
|
3 | import { RepoRef } from "../operations/common/RepoId";
|
4 | import { File } from "./File";
|
5 | /**
|
6 | * Project operations common to all projects
|
7 | */
|
8 | export interface ProjectCore {
|
9 | readonly name: string;
|
10 | id: RepoRef;
|
11 | }
|
12 | /**
|
13 | * Synchronous project operations. Should generally be avoided except for testing
|
14 | * or in other special cases.
|
15 | */
|
16 | export interface ProjectSync extends ProjectCore {
|
17 | /**
|
18 | * Find a regular file with the given path. Return undefined if
|
19 | * file does not exist or is not a regular file.
|
20 | *
|
21 | * @param path {string} path to file relative to root of project
|
22 | * @returns {File}
|
23 | */
|
24 | findFileSync(path: string): File;
|
25 | /**
|
26 | * Add the given file to the project. Path can be nested. Content
|
27 | * is a literal string. This method will throw an error if it is
|
28 | * not successful.
|
29 | *
|
30 | * @param path {string} path to file relative to root of project
|
31 | * @param content {string} The content to be placed in the new file
|
32 | */
|
33 | addFileSync(path: string, content: string): void;
|
34 | /**
|
35 | * Recursively deletes a directory and all its contents with the
|
36 | * given path. Errors when deleting the directory are caught.
|
37 | *
|
38 | * @param path {string} path to directory relative to root of project
|
39 | */
|
40 | deleteDirectorySync(path: string): void;
|
41 | /**
|
42 | * Delete the given file from the project. Path can be nested.
|
43 | * Errors when deleting the file are caught.
|
44 | *
|
45 | * @param path {string} path to file relative to root of project
|
46 | */
|
47 | deleteFileSync(path: string): void;
|
48 | /**
|
49 | * Makes a file executable. Other permissions are unchanged.
|
50 | *
|
51 | * @param path {string} path to file relative to root of project
|
52 | */
|
53 | makeExecutableSync(path: string): void;
|
54 | /**
|
55 | * Does a directory with the given path exist?
|
56 | *
|
57 | * @param path {string} path to directory relative to root of project
|
58 | * @returns {boolean}
|
59 | */
|
60 | directoryExistsSync(path: string): boolean;
|
61 | /**
|
62 | * Does a regular file with the given path exist? It will return
|
63 | * false if the file does not exist or is not a regular file.
|
64 | *
|
65 | * @param path {string} path to file relative to root of project
|
66 | * @returns {boolean}
|
67 | */
|
68 | fileExistsSync(path: string): boolean;
|
69 | }
|
70 | /**
|
71 | * Asynchronous Project operations, returning promises or node streams.
|
72 | */
|
73 | export interface ProjectAsync extends ProjectCore {
|
74 | /**
|
75 | * Return a node stream of the files in the project meeting
|
76 | * the given path criteria. Uses default exclusions in the glob path.
|
77 | * @param globPatterns glob patterns. If none is provided,
|
78 | * include all files. If at least one positive pattern is provided,
|
79 | * one or more negative glob patterns can be provided.
|
80 | *
|
81 | * @param {string[]} globPatterns glob patterns per minimatch
|
82 | * @return {FileStream}
|
83 | */
|
84 | streamFiles(...globPatterns: string[]): FileStream;
|
85 | /**
|
86 | * Stream file with full control over globs. At least one glob
|
87 | * must be provided. No default exclusions will be used.
|
88 | *
|
89 | * @param {string[]} globPatterns glob patterns per minimatch
|
90 | * @param opts for glob handling
|
91 | * @return {FileStream}
|
92 | */
|
93 | streamFilesRaw(globPatterns: string[], opts: {}): FileStream;
|
94 | /**
|
95 | * The total number of files in this project or directory
|
96 | *
|
97 | * @return {number} totalFileCount
|
98 | */
|
99 | totalFileCount(): Promise<number>;
|
100 | /**
|
101 | * Attempt to find a regular file at path. This method will
|
102 | * return a rejected Promise if the file does not exist or is not
|
103 | * a regular file. You may well want getFile, which returns a
|
104 | * Promise of the file or undefined.
|
105 | *
|
106 | * @param {string} path path to file relative to root of project
|
107 | * @return {Promise<File>}
|
108 | */
|
109 | findFile(path: string): Promise<File>;
|
110 | /**
|
111 | * Attempt to find a regular file at path. Never throws an
|
112 | * exception, returns undefined if file does not exist or is not a
|
113 | * regular file.
|
114 | *
|
115 | * @param {string} path path to file relative to root of project
|
116 | * @return {Promise<File>}
|
117 | */
|
118 | getFile(path: string): Promise<File | undefined>;
|
119 | /**
|
120 | * Does a regular file exist at this path? It will return false
|
121 | * for non-existent files, directories, block devices, FIFOs,
|
122 | * sockets, etc.
|
123 | *
|
124 | * @param {string} path path to file relative to root of project
|
125 | * @return {Promise<boolean>}
|
126 | */
|
127 | hasFile(path: string): Promise<boolean>;
|
128 | /**
|
129 | * Does a directory exist at this path? It will return false if
|
130 | * directory does not exist or if file at path is not a directory.
|
131 | *
|
132 | * @param {string} path path to directory relative to root of project
|
133 | * @return {Promise<boolean>}
|
134 | */
|
135 | hasDirectory(path: string): Promise<boolean>;
|
136 | /**
|
137 | * Add a file preserving permissions
|
138 | * @param {File} f
|
139 | * @return {Promise<this>}
|
140 | */
|
141 | add(f: File): Promise<this>;
|
142 | /**
|
143 | * Add the given file to the project. Path can be nested. Content
|
144 | * is a literal string.
|
145 | *
|
146 | * @param path {string} path to file relative to root of project
|
147 | * @param content {string} The content to be placed in the new file
|
148 | */
|
149 | addFile(path: string, content: string): Promise<this>;
|
150 | /**
|
151 | * Delete the given file from the project. Path can be nested.
|
152 | * Errors when deleting the file do not result in a rejected
|
153 | * Promise being returned.
|
154 | *
|
155 | * @param path {string} path to file relative to root of project
|
156 | */
|
157 | deleteFile(path: string): Promise<this>;
|
158 | /**
|
159 | * Move the file. Do not error if it's not found.
|
160 | * @param {string} oldPath
|
161 | * @param {string} newPath
|
162 | * @return {Promise<this>}
|
163 | */
|
164 | moveFile(oldPath: string, newPath: string): Promise<this>;
|
165 | /**
|
166 | * Add an empty directory to the project. Should be preserved
|
167 | * through all transformations, although may not be accessible in
|
168 | * some implementations.
|
169 | *
|
170 | * @param {string} path path to directory relative to root of project
|
171 | * @return {Promise<this>}
|
172 | */
|
173 | addDirectory(path: string): Promise<this>;
|
174 | /**
|
175 | * Recursively delete a directory and all its contents. Path can
|
176 | * be nested. Errors when deleting the directory do not result in
|
177 | * a rejected Promise being returned.
|
178 | *
|
179 | * @param {string} path path to directory relative to root of project
|
180 | * @return {Promise<this>}
|
181 | */
|
182 | deleteDirectory(path: string): Promise<this>;
|
183 | /**
|
184 | * Make a file executable. Other permissions are unchanged.
|
185 | *
|
186 | * @param {string} path path to file relative to root of project
|
187 | * @return {Promise<this>}
|
188 | */
|
189 | makeExecutable(path: string): Promise<this>;
|
190 | }
|
191 | /**
|
192 | * Interface representing a project, allowing transparent operations
|
193 | * whether it is sourced from a GitHub or other repository, from local disk
|
194 | * or in memory. Allows both read and write operations. The three
|
195 | * interfaces it extends allow different styles of operation: scripting (deferred),
|
196 | * asynchronous (with promises) or synchronous.
|
197 | */
|
198 | export interface Project extends ProjectAsync, ProjectSync {
|
199 | /**
|
200 | * For debugging: how was this project created?
|
201 | */
|
202 | provenance?: string;
|
203 | }
|
204 | export declare function isProject(a: any): a is Project;
|
205 | /**
|
206 | * Extension of node Stream to handle files within a Project
|
207 | */
|
208 | export interface FileStream extends Stream {
|
209 | on(event: "data" | "end" | "error", listener: (f: File) => void): this;
|
210 | }
|
211 | //# sourceMappingURL=Project.d.ts.map |
\ | No newline at end of file |