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 file with the given path. Return undefined if not found.
|
19 | *
|
20 | * @param path {string} Path of the file we want
|
21 | * @returns {File}
|
22 | */
|
23 | findFileSync(path: string): File;
|
24 | /**
|
25 | * Add the given file to the project. Path can contain /s. Content is a literal string
|
26 | *
|
27 | * @param path {string} The path to use
|
28 | * @param content {string} The content to be placed in the new file
|
29 | */
|
30 | addFileSync(path: string, content: string): void;
|
31 | /**
|
32 | * Deletes a directory with the given path
|
33 | *
|
34 | * @param path {string} The path to use
|
35 | */
|
36 | deleteDirectorySync(path: string): void;
|
37 | /**
|
38 | * Delete the given file from the project. Path can contain /s.
|
39 | *
|
40 | * @param path {string} The path to use
|
41 | */
|
42 | deleteFileSync(path: string): void;
|
43 | /**
|
44 | * Makes a file executable
|
45 | *
|
46 | * @param path {string} The path to use
|
47 | */
|
48 | makeExecutableSync(path: string): void;
|
49 | /**
|
50 | * Does a directory with the given path exist?
|
51 | *
|
52 | * @param path {string} The path to use
|
53 | * @returns {boolean}
|
54 | */
|
55 | directoryExistsSync(path: string): boolean;
|
56 | /**
|
57 | * Does a file with the given path exist?
|
58 | *
|
59 | * @param path {string} The path to use
|
60 | * @returns {boolean}
|
61 | */
|
62 | fileExistsSync(path: string): boolean;
|
63 | }
|
64 | /**
|
65 | * Asynchronous Project operations, returning promises or node streams.
|
66 | */
|
67 | export interface ProjectAsync extends ProjectCore {
|
68 | /**
|
69 | * Return a node stream of the files in the project meeting
|
70 | * the given path criteria. Uses default exclusions in the glob path.
|
71 | * @param globPatterns glob patterns. If none is provided,
|
72 | * include all files. If at least one positive pattern is provided,
|
73 | * one or more negative glob patterns can be provided.
|
74 | */
|
75 | streamFiles(...globPatterns: string[]): FileStream;
|
76 | /**
|
77 | * Stream file with full control over globs.
|
78 | * At least one glob must be provided. No default exclusions will be used.
|
79 | * @param {string[]} globPatterns
|
80 | * @param opts for glob handling
|
81 | * @return {FileStream}
|
82 | */
|
83 | streamFilesRaw(globPatterns: string[], opts: {}): FileStream;
|
84 | /**
|
85 | * The total number of files in this project or directory
|
86 | *
|
87 | * @property {number} totalFileCount
|
88 | */
|
89 | totalFileCount(): Promise<number>;
|
90 | /**
|
91 | * Attempt to find a file.
|
92 | * Use then or catch, depending on whether the file exists.
|
93 | * You may well want getFile, which returns a Promise of the file or undefined.
|
94 | * @param {string} path
|
95 | * @return {Promise<File>}
|
96 | */
|
97 | findFile(path: string): Promise<File>;
|
98 | /**
|
99 | * Attempt to find a file.
|
100 | * Never throws an exception, returns undefined
|
101 | * @param {string} path
|
102 | * @return {Promise<File>}
|
103 | */
|
104 | getFile(path: string): Promise<File | undefined>;
|
105 | /**
|
106 | * Add a file preserving permissions
|
107 | * @param {File} f
|
108 | * @return {Promise<this>}
|
109 | */
|
110 | add(f: File): Promise<this>;
|
111 | addFile(path: string, content: string): Promise<this>;
|
112 | deleteFile(path: string): Promise<this>;
|
113 | /**
|
114 | * Move the file. Do not error if it's not found.
|
115 | * @param {string} oldPath
|
116 | * @param {string} newPath
|
117 | * @return {Promise<this>}
|
118 | */
|
119 | moveFile(oldPath: string, newPath: string): Promise<this>;
|
120 | /**
|
121 | * Add an empty directory to the project.
|
122 | * Should be preserved through all transformations, although
|
123 | * may not be accessible in some implementations
|
124 | * @param {string} path
|
125 | * @return {Promise<this>}
|
126 | */
|
127 | addDirectory(path: string): Promise<this>;
|
128 | /**
|
129 | * Delete a directory. Do not throw an error if it doesn't exist
|
130 | * @param {string} path
|
131 | * @return {Promise<this>}
|
132 | */
|
133 | deleteDirectory(path: string): Promise<this>;
|
134 | /**
|
135 | * Make a file executable by its owner.
|
136 | * Other permissions are unchanged.
|
137 | * @param {string} path
|
138 | * @return {Promise<this>}
|
139 | */
|
140 | makeExecutable(path: string): Promise<this>;
|
141 | }
|
142 | /**
|
143 | * Interface representing a project, allowing transparent operations
|
144 | * whether it is sourced from a GitHub or other repository, from local disk
|
145 | * or in memory. Allows both read and write operations. The three
|
146 | * interfaces it extends allow different styles of operation: scripting (deferred),
|
147 | * asynchronous (with promises) or synchronous.
|
148 | */
|
149 | export interface Project extends ProjectAsync, ProjectSync {
|
150 | /**
|
151 | * For debugging: how was this project created?
|
152 | */
|
153 | provenance?: string;
|
154 | }
|
155 | export declare function isProject(a: any): a is Project;
|
156 | /**
|
157 | * Extension of node Stream to handle files within a Project
|
158 | */
|
159 | export interface FileStream extends Stream {
|
160 | on(event: "data" | "end" | "error", listener: (f: File) => void): this;
|
161 | }
|
162 | //# sourceMappingURL=Project.d.ts.map |
\ | No newline at end of file |